IF Statement Problem
IF Statement Problem
(OP)
Hi, I'm trying to get the hang of "if...then...else" statements in an EXTRA! AS400 emulator macros. The simple code below is supposed to find the command line and type "FOUND IT"; but if it can't find the command line then it'll go to the given coordinates and type "NO GO":
When the IF condition is FALSE and goes to the ELSE statement, the macro works just fine.
The problem is: When the IF condition is TRUE, an error message pops up in the macro saying:
"Type Mismatch -- Line Number 12 -- Stopping Macro Playback" (The red line is the culprit), then pauses the macro. If I hit GO to continue, then the macro will pick up where it left off and finish normally.
I'm trying to figure out what the error is on that line that stops the macro.
Thanks a million,
Mark
CODE
Sub Main()
Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object
Set Sys = CreateObject("EXTRA.System")
' Assumes an open session
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen
MyScreen.MoveTo 1, 1
Set MyArea = MyScreen.Search("==>")
If MyArea Then
MyScreen.MoveTo MyArea.Bottom, MyArea.Right + 2 'found the command line
Sess.Screen.Sendkeys "FOUND IT"
Else
MyScreen.MoveTo 6, 53 'could not find the commmand line
Sess.Screen.Sendkeys "NO GO"
End If
End Sub
Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object
Set Sys = CreateObject("EXTRA.System")
' Assumes an open session
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen
MyScreen.MoveTo 1, 1
Set MyArea = MyScreen.Search("==>")
If MyArea Then
MyScreen.MoveTo MyArea.Bottom, MyArea.Right + 2 'found the command line
Sess.Screen.Sendkeys "FOUND IT"
Else
MyScreen.MoveTo 6, 53 'could not find the commmand line
Sess.Screen.Sendkeys "NO GO"
End If
End Sub
When the IF condition is FALSE and goes to the ELSE statement, the macro works just fine.
The problem is: When the IF condition is TRUE, an error message pops up in the macro saying:
"Type Mismatch -- Line Number 12 -- Stopping Macro Playback" (The red line is the culprit), then pauses the macro. If I hit GO to continue, then the macro will pick up where it left off and finish normally.
I'm trying to figure out what the error is on that line that stops the macro.
Thanks a million,
Mark
RE: IF Statement Problem
There are several ways to accomplish what you are looking to do. I typically would use If MyArea.top <> -1 Then ....
When the string is found the top coordinates of the area object will be a positive number, and when it isn't found the top value is -1.
RE: IF Statement Problem
Thanks for that tip buckeye7, it worked. But I tried to take it a step further and hit another snag I was hoping you could help with.
Basically, I wanted to extend the if...then...else scenario to include and execute a 3rd condition when the 1st and 2nd are false. I know the code must look screwy, but it was the only way I could get it to compile without errors.
CODE
Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object, OurArea As Object, iMailArea As Object
Set Sys = CreateObject("EXTRA.System")
' Assumes an open session
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen
MyScreen.MoveTo 1, 1
Set MyArea = MyScreen.Search("==>")
If MyArea.Top <> -1 Then
MyScreen.MoveTo MyArea.Bottom, MyArea.Right + 2
Sess.Screen.Sendkeys "FOUND IT"
Else
Set OurArea = MyScreen.Search("User")
MyScreen.MoveTo OurArea.Bottom, OurArea.Right + 33
Sess.Screen.Sendkeys "NO GO"
If OurArea.Top <> -1 Then
Set iMailArea = MyScreen.Search("Subject")
MyScreen.MoveTo iMailArea.Bottom, iMailArea.Right + 12
Sess.Screen.Sendkeys "TAKING IT FURTHER"
End If
End If
End Sub
How can I make it just do the 2nd step and stop when the the 2nd condition is true, without executing the 3rd - and make it execute the 3rd condition when the first 2 are false? I played around with "ElseIf" but couldn't get it to work. Thank you again.
RE: IF Statement Problem
CODE
Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object, OurArea As Object, iMailArea As Object
Set Sys = CreateObject("EXTRA.System")
' Assumes an open session
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen
MyScreen.MoveTo 1, 1
Set MyArea = MyScreen.Search("==>")
Set OurArea = MyScreen.Search("User")
If MyArea.Top <> -1 Then
MyScreen.MoveTo MyArea.Bottom, MyArea.Right + 2
Sess.Screen.Sendkeys "FOUND IT"
ElseIf OurArea.Top <> -1 Then
Set iMailArea = MyScreen.Search("Subject")
MyScreen.MoveTo iMailArea.Bottom, iMailArea.Right + 12
Sess.Screen.Sendkeys "TAKING IT FURTHER"
Else
MyScreen.MoveTo OurArea.Bottom, OurArea.Right + 33
Sess.Screen.Sendkeys "NO GO"
End If
End Sub