Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF Statement Problem 1

Status
Not open for further replies.

foleyml

Technical User
Jan 13, 2009
3
US
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":

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("==>") 
        [COLOR=red]If MyArea Then[/color]
	  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
 
foleyml,

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.
 
buckeye7,

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:
Sub Main()
	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
It works when the 1st condition is true - it puts "FOUND IT" and stops. But when the 1st condition is false, and the second condition is true, it types the text for both the 2nd and 3rd condition, when it should only type the 2nd condition text and stop.

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.
 
You're welcome. I am not sure if the code below is what you are looking to do.



Code:
Sub Main

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top