Use the following guidelines when using asynchronous methods or subroutines (Close method, ClosePicture subroutine, ReplaceDocument method, ReplacePicture subroutine, or SwitchMode method) in your scripts:
If possible, make the asynchronous call the last line in your script.
If using the Close or Replace calls, and the document that is being closed or replaced is the document that contains the script, the call must be the last line in the script. Otherwise, you may experience unexpected behavior when executing the script.
If using the SwitchMode method from anywhere other than a toolbar, the call must be the last line in the script. Otherwise, you may experience unexpected behavior when executing the script.
If the call is not in the picture being closed or replaced, and it is not the last line in your script, be certain that the operation is complete before the rest of the script continues to execute. Immediately after making the call, you must relinquish the CPU by calling DoEvents. For example, the following sample script closes a picture called TANK1 and opens a picture called TANK2:
Private Sub Rect1_Click()
ClosePicture "Tank1"
DoEvents
OpenPicture "Tank2"
End Sub
When performing a string comparison using the A_SCAN or A_ENAB field, you must include a trailing space in the comparison string. For example, in the following sample script, the trailing space is required in the comparison strings for the test to work correctly.
Private Sub CommandButton4_Click()
If (Fix 32.DVSYS.A_SCAN = "OFF ") Then
Fix 32.DVSYS.AI1.A_SCAN = "ON "
Else
Fix 32.DVSYS.AI1.A_SCAN = "OFF "
End If
End Sub