Variable Scope

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
cabramson
Newbie
Posts: 6
Joined: Wed Jul 04, 2007 5:56 pm
Location: Cypress, CA

Variable Scope

Post by cabramson » Sun Jul 08, 2007 9:37 pm

I want to assign a variable within a subroutine and make it available to the main scrip.

I've not found variable scope rules so far.

Am I missing something simple?

Thanks,

Carl

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Jul 08, 2007 9:56 pm

All variables have global scope. Variables created in subroutines will be available in the rest of the script and vice versa.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

cabramson
Newbie
Posts: 6
Joined: Wed Jul 04, 2007 5:56 pm
Location: Cypress, CA

Post by cabramson » Mon Jul 09, 2007 1:39 am

Is there anything special required within the Subroutine to expose the variable? In the code below, the PW variable is correctly populated; but, I'm not seeing it in the script where I was calling the subroutine. I saw a mention of variable format under the SRT documentation; but, haven't found an example.

//Enter Showcase PW
SRT>GetPW
Label>ReEnterPW
Let>Input_Browse=0
Let>INPUT_PASSWORD=1
Input>PW1,Enter Your Showcase Password,
Input>PW2,Re-enter Your Showcase Password,
//Verify Credentials
If>%PW1%=%PW2%,,
Let>PW=%PW1%
Else
MessageModal>The passwords entered are NOT the same.%CRLF%%CRLF%Please try again.
GoTo>ReEnterPW
EndIf
End>GetPW

Thanks,

Carl

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Jul 09, 2007 5:36 am

Nothing special. Your code works fine:

Code: Select all

GoSub>GetPW
MessageModal>PW

//Enter Showcase PW
SRT>GetPW
Label>ReEnterPW
Let>Input_Browse=0
Let>INPUT_PASSWORD=1
Input>PW1,Enter Your Showcase Password,
Input>PW2,Re-enter Your Showcase Password,
//Verify Credentials
If>%PW1%=%PW2%,,
Let>PW=%PW1%
Else
MessageModal>The passwords entered are NOT the same.%CRLF%%CRLF%Please try again.
GoTo>ReEnterPW
EndIf
End>GetPW
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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