Couple questions on the if statements

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Visitor

Couple questions on the if statements

Post by Visitor » Wed Oct 06, 2004 5:26 pm

Hi, I was just wondering if it was possible to do complex if statements such as:

if/else queries

and

if ((i == j) and (x == y)) type of queries.

I can work around the problem by having a second if statement inside the subroutine of the first one.. But that do not apear to be a very optimal solutions.

Another question. Is it possible to call a subroutine without passing through an if statement? I want to avoid goto's as it just wouldn't work well on my script (it'll get messy). Right now I work around the problem by using a "Let>i=0 followed by if>i=0,subroutine". This is a minor problem really, but it'll be nice if it was possible to cut one line off.

Maybe I should start learning how to script in VB.. If only they supported Java (saves me from learning new syntax :lol:)

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Oct 06, 2004 5:52 pm

Yes to both questions.

You can do simple IF>Condition, True Label, False Label.
You can use the operators >, with numbers, strings, variables.
You cannot do "AND" conditions on same line but you can nest or continue to next line. It actually makes it much easier to read, and comment lines can be added if clarification is needed.
You can nest IF statements by leaving off the optional False Label.
=========================================

It looks like you may be already doing these things from the last part of your message, so perhaps I am not understanding the problem?

You can also do simple GoSub> Gosub Label with Return. No IF> is required.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Ax
Newbie
Posts: 9
Joined: Wed Oct 06, 2004 5:28 pm

Post by Ax » Wed Oct 06, 2004 9:37 pm

Ah, so GoSub is what I am looking for. Thanks, that'll allow me to trim a few lines off my script :lol:

And as for the first part, the if statement makes more sense.
I always thought of the syntax to be IF>Condition,DoSomething.

------------------------------------------------------------------

Back to the first part. The AND/Nested Ifs still isn't completely clear to me.

Lets take a very simple example: Say I want to check if a number is greater than 0 and smaller than 10.

I can do that in two similar manners in C/Java:

Nested If:

If (x>0)
If (x0 & xk=5
If>k>0, //Not sure what to put here
If>ks
msg>yes!
END>s

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Wed Oct 06, 2004 10:29 pm

There are lots of ways of doing this. Here are a few:


//Method 1 - basic If statements
//******************************
Let>k=5
If>kk>10,end
MessageModal>k is between 0 and 10
Label>end

//Method 2 - Evaluate a VBScript expression
//*****************************************
//If using VBScript you need a VBSTART/VBEND block, even if no functions in it
//So you can just stick the following two lines at the top of your script.
VBSTART
VBEND

Let>k=5

//VBEval will evaluate ANY VBScript expression and return the result ...
VBEval>0 > k res=True,DoTrueSub,DoFalseSub

SRT>DoTrueSub
MessageModal>k is between 0 and 10
END>DoTrueSub

SRT>DoFalseSub
MessageModal>k is not between 0 and 10
END>DoFalseSub


//Method 3 - Overkill this, but good for more complex expressions:
//Make a VBScript function to contain the expression
VBSTART

Function MyCheck(k)
if 0 > k k=5
VBEval>MyCheck(k),res
MessageModal>res
MJT Net Support
[email protected]

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Oct 07, 2004 3:05 am

Minor changes to the first of the Support solutions:
Changed k10 to k>=10 to exclude 10

These changes correct the math for the sample, but the approach is correct. That is the most important fact, the technique to be used.


Let>k=5

If>kk>=10,end

MessageModal>k is between 0 and 10

Label>end
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Oct 07, 2004 2:10 pm

Yes, sorry I wasn't paying much attention to the range check, just giving some ideas on how to use If statements.

But the breaking news is that Macro Scheduler 7.3 supports IF/ELSE/ENDIF, nested IF statements, and complex expressions in IF statements. All other IF commands work in the same way. To ensure backward compatibility labels/subroutines can still be provided, so no scripts will need modification. Without the label/subroutine on the IF line it works as IF/ELSE/ENDIF.

Macro Scheduler 7.3 should be released in the next couple of weeks. Documentation is being updated now.

To whet your appetite further, 7.3 also supports NON modal dialogs with commands to create action loops which check to see which button has been pressed. This means you can effectively create an interface which triggers events while staying active.

We've also added a variable switch that allows you to set ALL window functions to use the window handle instead of window title text. You can switch between handles and text. GetWindowHandle retrieves the handle of the window specified by window title, and GetActiveWindow will also return the window handle. Using the internal window handle makes it easier to differentiate between windows of the same name or similar names.

We've added a SelectMenu command to activate menu options without having to issue keystrokes or mouse events. GetObjectText and SetObjectText retrieves and sets the text of a specific object on a window by classname.

We've added commands to get and set environment variables. Macros can now return values to the calling macro. Variables have been added to allow you to position Message boxes. And you can change the window title/app name of compiled macros. Improvements to the clipboard functions have been made and we've added WaitClipboard to wait for the clipboard to be ready.

Other improvements include improvements to the playback speed selection of recorded macros and an optional message to warn of trailing spaces if any exist when saving macros ...

So, watch this space ....
MJT Net Support
[email protected]

Lumumba

Post by Lumumba » Thu Oct 07, 2004 4:06 pm

:!: WoW :D

Ax
Newbie
Posts: 9
Joined: Wed Oct 06, 2004 5:28 pm

Post by Ax » Thu Oct 07, 2004 6:55 pm

Wow, thats quite a bit to digest - but looking good :)

What would be the best solution for me (in terms of making the script "clean") if I needed to do quite a lot of "if statements" in pair (and)?

e.g.
Say I need to check the color of two pixels on screen and run a different subroutine for each pair or more.
Like:

GetPixelColor>x,y,c1
GetPixelColor>x,y,c2
//What I want to do
If (c1 == 0 & c2 == 1000)
GoSub>Blah1
If (c1 == 200 & c2 == 500)
GoSub>Blah2
If (c1 == 0 & c2 == 500)
GoSub>Blah3

etc.

Based on the provided information by support, I reckon that I will be able to work up something.. But I have a feeling that it might be a bit messy, and was wondering how you would solve that problem.

Many thanks.

==============================

A lil side question.. Does Macro Scheduler editor provide any facilities to facilitated gathering pixel color at a given coordinate?
The script I am working on requires me to do a fair amount of checking pixels on screen. And though I can use pen and paper to note a color at an exact cordinate, any tools to ease that would save some time [:)]

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Oct 07, 2004 9:23 pm

:D :shock: :D :shock: :D
Sounds great! And that is just a sample, right? Even more to come?

Not to be greedy, but will we be able to have a timeout on Macro Scheduler Dialog boxes? Really hate to have to wait for another round of releases.

But this is good news, happy to see ongoing development. This is one reason that I keep recommending Macro Scheduler to others. Thanks for the great tools. Once again you will get my vote for best utility program.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Oct 07, 2004 9:42 pm

You can't timeout modal dialogs. They're modal. They wait for the user. Once created they have control.

But since you will be able to make non-modal dialogs, you can create timeouts for them easily. Show it, then set an action loop, check the elapsed time in the loop and when it reaches a certain amount, Close it.
MJT Net Support
[email protected]

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Oct 07, 2004 10:07 pm

Sorry I was wrong (!) - both Input and Ask now have timeouts! I had either forgotten or not noticed. INPUT_TIMEOUT and ASK_TIMEOUT can be set before issuing these commands. If the Input box times out the default value given is the result. If Ask times out the default result is YES.
MJT Net Support
[email protected]

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Oct 07, 2004 10:39 pm

Those two timeouts will be well used, thanks. But now you are challenging me re the Dialog timeout that is unavailable.. Gonna force me to get really creative, may even have to work a little.

Will the modal nature of the Dialog also prevent these options?

1. Just before calling the Dialog, call another background macro to wait x mins, then look for an open Dialog box, and go into the dialog box and click on an object, close the box etc.

2. Have a macro triggered to run when Dialog window opens. Same as above, after x mins, close the Dialog and set some default values as needed.

3. MJT could create an object WITHIN the Dialog box that has a timeout?

4. MJT could create a Dialog option to be Modal/Non-modal option. Now the non-modal option could have timeout.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Oct 07, 2004 10:46 pm

Much easier would be just to use a non modal dialog. Show it, then a loop which checks for the response and the timeout. Don't worry it will make sense when you see how non-modal dialogs work.
MJT Net Support
[email protected]

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Oct 07, 2004 11:55 pm

Dummy Me! :oops:

I missed the earlier reference that non-modal dialogs could be made. That was one of my alternatives suggestions, but you were already ahead of me. As they say, "Great minds think alike".

Sounding better each time I come back. Thanks for the advance info, looking forward to new features.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Ax
Newbie
Posts: 9
Joined: Wed Oct 06, 2004 5:28 pm

Post by Ax » Wed Oct 13, 2004 11:30 pm

Me again (I just can't get things right :?)..
I've been toying around with VBScript and if statements, and I am basically getting a bit confused.. Here's a lil test script I've wrote:

VBSTART
Function GetValue(x,y)
If y=small Then
Value = 100+x
ElseIf y=medium Then
Value = 200+x
ElseIf y=large Then
Value = 300+x
else Value=0
End If
End Function
VBEND

//Let>i=5
//Let>j=large
VBEval>GetValue(10,large),i
Msg>blah %i%

Really simple, what I wanted to do is to pass %i%, %j% to GetValue, but I noticed the function doesn't even work properly when I hard cope the values (I am -expecting- a result of 310 here).

What am I doing wrong?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts