×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

IF Statement Problem

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":

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

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

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.

RE: IF Statement Problem

(OP)
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.

RE: IF Statement Problem

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close