Advanced Conditional Expressions
Sub main
'create a report,write to it 'and make it visible Dim r As New Report r.Visible = True r.SelectionText = "Report text." 'if it is visible and it contains 12 characters 'then display a messagebox. If either of these 'expressions are false then the messagebox will 'not appear If r.Visible And r.CharacterCount = 12 Then
MsgBox "The report is visible and" & _ vbCrLf & "has twelve characters."
Else
r.Visible = True
End If
End Sub
Sub main
'create a report and write to it ',but it will be left invisible Dim r As New Report r.Visible = False r.SelectionText = "Report text." 'if it is visible or it contains 12 characters 'then display a messagebox. If both of these 'expressions are false then an 'error messagebox will appear If r.Visible Or r.CharacterCount = 12 Then MsgBox "The report either visible or" & _ vbCrLf & "has twelve characters." Else MsgBox "The report is neither visible nor" & _ vbCrLf & "does it have twelve characters." End If
End Sub
Sub main
Dim WS As WindowState WS = Application.WindowState If WS = scNormal Xor WS = scMaximized _
Xor WS = scMinimized Then
MsgBox _ "Statistica is either minimized," _ & vbCrLf &"Normal, or maximized"
Else
MsgBox "Statistica is in an invalid window state"
End If
End Sub
The reason that Xor should be used in a situation such as this is because is verifies that only one of the window states is currently valid. It wouldn't be logical for Statistica to be two different window states at the same time, and Xor is able to validate that.
Sub main
'create a new spreadsheet and make it invisible Dim s As New Spreadsheet s.Visible = False 'if it's visible then... If s.Visible Then
'because it's invisible, then the following 'will not be evaluated (whether or not it 'is true) If s.Cases.Count = 10 Then
MsgBox "The spreadsheet has 10 cases"
'This End If will close the closest If statement, 'which happens to be the one verifying whether 'the case count is ten or not End If
'Because the previous (nested) If statement has 'been closed, then this else will refer to the 'next closest If statement which is still open, 'which happens to be one verifying whether or 'not the spreadsheet is visible or not Else
MsgBox "The spreadsheet is invisible"
'This End If will close the next closest If 'statement that is still open, which happens 'to be the one verifying whether or 'not the spreadsheet is visible or not End If
End Sub