Using string in if Function
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 10
- Joined: Tue Jun 26, 2007 2:46 pm
Using string in if Function
Hi
I'm trying to use a string variable I have stored in and IF statement and I can't get it to work.
The code I'm using is
The have set the Country variable using the Getclipboard command. I know the variable is storing correctly as I've used messagemodal to pull it up and it is storing Canada
If>%Country%="Canada",Canada,Countryset
Label>Canada
//bunch of code here that I want run if Country=Canada
Label>Countryset
//Code I want if Country is not equal to
The script is only running Canada and not going to the Countryset Label
Please help!
Thanks!
________
Alaska Dispensary
I'm trying to use a string variable I have stored in and IF statement and I can't get it to work.
The code I'm using is
The have set the Country variable using the Getclipboard command. I know the variable is storing correctly as I've used messagemodal to pull it up and it is storing Canada
If>%Country%="Canada",Canada,Countryset
Label>Canada
//bunch of code here that I want run if Country=Canada
Label>Countryset
//Code I want if Country is not equal to
The script is only running Canada and not going to the Countryset Label
Please help!
Thanks!
________
Alaska Dispensary
Last edited by philmcmannis on Sat Feb 12, 2011 4:01 am, edited 1 time in total.
Re: Using string in if Function
Hi philmcmannis,philmcmannis wrote:The script is only running Canada and not going to the Countryset Label
Please help!
Thanks!
That's because in the If> statement, you are testing whether the variable Country is equal to "Canada" (including the double quotes). Just remove the double quotes and it will work as you expect. Try this code... run it once like it is and then uncomment the //Let>Country=France line and comment out the Let>Country=Canada line and run it again:
Code: Select all
Let>Country=Canada
//Let>Country=France
If>%Country%=Canada,Canada,Countryset
Label>Canada
//bunch of code here that I want run if Country=Canada
MDL>We have reached the line: Label>Canada
GoTo>end
Label>Countryset
//Code I want if Country is not equal to
MDL>We have reached the line: Label>Countryset
Label>end
- If>%Country%=Canada,Canada,Countryset
- If>Country=Canada,Canada,Countryset
Last edited by jpuziano on Tue Jun 26, 2007 3:51 pm, edited 1 time in total.
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
It's both a blessing and a curse but you don't "quote" strings in macroscheduler. And you don't need the % in an If> (unless you have set the VAREXPLICIT system variable to require them).
Try:
Let>Country=Canada
If>Country=Canada,Canada,Countryset
Label>Canada
MDL>This is Canada
Goto>theend
Label>Countryset
MDL>This is Countryset
Goto>theend
Label>theend
Try:
Let>Country=Canada
If>Country=Canada,Canada,Countryset
Label>Canada
MDL>This is Canada
Goto>theend
Label>Countryset
MDL>This is Countryset
Goto>theend
Label>theend
Lots of answers here on the forums... 

jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

-
- Newbie
- Posts: 10
- Joined: Tue Jun 26, 2007 2:46 pm
Thanks for the quick response. My IF statement is working correctly which means this is actually related to what I'm trying to copy out of Excel.
What I'm trying to do is Copy a cell in Excel, Store that text as a variable and then evaluate that variable with an if command.
I've used messagemodal to confirm that Data is getting picked up, but I'm assuming there is some extra "excel stuff" being copied as well. What should I do?
Press Ctrl
Wait>0.10
Send>c
Wait>0.10
Release Ctrl
WaitClipboard>2
GetClipboard>Country
MEssageModal>%Country%
The message box returns Canada, but the if statement doesn't detect Canada.
Thoughts?
________
Mxr-01
What I'm trying to do is Copy a cell in Excel, Store that text as a variable and then evaluate that variable with an if command.
I've used messagemodal to confirm that Data is getting picked up, but I'm assuming there is some extra "excel stuff" being copied as well. What should I do?
Press Ctrl
Wait>0.10
Send>c
Wait>0.10
Release Ctrl
WaitClipboard>2
GetClipboard>Country
MEssageModal>%Country%
The message box returns Canada, but the if statement doesn't detect Canada.
Thoughts?
________
Mxr-01
Last edited by philmcmannis on Sat Feb 12, 2011 4:01 am, edited 1 time in total.
Yup, that's what I'd say is happening alright... Try the following to "clean up" your variable...philmcmannis wrote:I'm assuming there is some extra "excel stuff" being copied as well. What should I do?
Code: Select all
VBEval>Replace("%val%",chr(13),""),val
VBEval>Replace("%val%",chr(10),""),val
VBEval>Trim("%val%"),val
First line replaces carriage returns with nothing. Next line replaces linefeeds with nothing. Final line removes trailing and leading spaces.
Also, if you use the above code, you'll need to add the following two lines as well, right at the top of your script would be best...
- VBSTART
VBEND
Take care
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

Yes... its happened to me many times before as well. Sometimes I even open a separate browser window and re-check the original forum posting to check if someone else has already replied... before posting my reply.Me_again wrote:Darn this phpbb that doesn't warn you if another reply has been posted since you opened the page. SMF rules!
I didn't know that SMF had a warning feature... very interesting. Someone should put in an enhancement request for this feature over at phpBB. If it came out in a future release, one day we could be enjoying that feature here too.
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

-
- Newbie
- Posts: 10
- Joined: Tue Jun 26, 2007 2:46 pm
I just tried inserting the code you wrote after grabbing the text from excel.
What I put in is:
VBEval>Replace("%RecordCount%",chr(13),""),RecordCount
VBEval>Replace("%RecordCount%",chr(10),""),RecordCount
VBEval>Trim("%RecordCount%"),RecordCount
I'm getting an error that says
Microsoft VBScript compilation error :1033
Unterminated string constant
Line 23, Column 10
Any idea what's causing that?
________
BUY VOLCANO VAPORIZER
What I put in is:
VBEval>Replace("%RecordCount%",chr(13),""),RecordCount
VBEval>Replace("%RecordCount%",chr(10),""),RecordCount
VBEval>Trim("%RecordCount%"),RecordCount
I'm getting an error that says
Microsoft VBScript compilation error :1033
Unterminated string constant
Line 23, Column 10
Any idea what's causing that?
________
BUY VOLCANO VAPORIZER
Last edited by philmcmannis on Sat Feb 12, 2011 4:01 am, edited 1 time in total.
Not sure but the following works for me without any errors... give this a try:philmcmannis wrote:I'm getting an error that says
Microsoft VBScript compilation error :1033
Unterminated string constant
Line 23, Column 10
Any idea what's causing that?
- VBSTART
VBEND
//Ensure the following line ends with a SPACE character
Let>Country=Canada
//Ensure the following line ends with a SPACE character
//Let>Country=France
Let>RecordCount=Country
//Remove Carriage Returns
VBEval>Replace("%RecordCount%",chr(13),""),RecordCount
//Remove Linefeeds
VBEval>Replace("%RecordCount%",chr(10),""),RecordCount
//Remove leading and trailing spaces
VBEval>Trim("%RecordCount%"),RecordCount
Let>Country=RecordCount
If>Country=Canada,Canada,Countryset
Label>Canada
//bunch of code here that I want run if Country=Canada
MDL>We have reached the line: Label>Canada
GoTo>end
Label>Countryset
//Code I want if Country is not equal to
MDL>We have reached the line: Label>Countryset
Label>end
- //Ensure the following line ends with a SPACE character
Let>Country=Canada_
//Ensure the following line ends with a SPACE character
//Let>Country=France_
Let us know how this works for you...
Last edited by jpuziano on Tue Jun 26, 2007 5:58 pm, edited 1 time in total.
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

Yes, that will work fine for %CR% and %LF% (done separately on two different lines as you might have data that has just one or the other) but if you try to use StringReplace> to trim leading and trailing spaces, it will remove spaces *from within* the string as well. New Zealand would be transformed into NewZealand and that's not what we want... so I prefer to just use the VBScript method for all three.Me_again wrote:Why not just use StringReplace?
StringReplace>Country,%CRLF%,,Country
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

-
- Newbie
- Posts: 10
- Joined: Tue Jun 26, 2007 2:46 pm
I've got it going now. Used to stringreplace as spaces don't have an effect on what I'm trying to do.
Thanks!!
________
Robert lutz
Thanks!!
________
Robert lutz