String not working in If Function.

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
hardik_228
Newbie
Posts: 12
Joined: Mon Dec 01, 2008 10:46 am

String not working in If Function.

Post by hardik_228 » Mon Dec 01, 2008 10:55 am

Hi guys,

Can anyone help me please. I am using MS 6.0. I am trying to get excel data and analyse it. I did following script but it is not working.
***************************************************
let>One=0

label>New
SetFocus>Microsoft Excel*
Press Ctrl
Press C
Release Ctrl
press down
wait>1
gcb>One
if>One=Y
messagemodal>Hi
elseif One=N then
messagemodal>Hello
endif
goto New
**************************************************
first, i define one variable named One.
second i stored value from excel into variable One.
then if excel cell value is Y then it shows me message "Hi"
and if cell value is N then it shows me message "Hello".
but it it not working.

i am trying this from last 3 days. and my whole script is useless because of this.

thanks in advance

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 Dec 01, 2008 11:05 am

You've set one to zero. Then you've use One in GetClipBoard. Therefore you have now set the contents of the clipboard to a variable called 0 (zero) because you earlier set One to zero. Fix your variable names (or remove the Let>one=0 at least) and use the debugger to see what happens when your script runs.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

hardik_228
Newbie
Posts: 12
Joined: Mon Dec 01, 2008 10:46 am

Post by hardik_228 » Thu Dec 04, 2008 5:52 am

Hi marcus,

i tried that but still not working. please help.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Dec 04, 2008 6:00 am

Your syntax is incorrect. Try this:

Code: Select all

label>New
SetFocus>Microsoft Excel*
Press Ctrl
send>c
Release Ctrl
press down
wait>1
gcb>One
if>One=Y
messagemodal>Hi
EndIf
if>One=N
messagemodal>Hello
endif
goto New

hardik_228
Newbie
Posts: 12
Joined: Mon Dec 01, 2008 10:46 am

Post by hardik_228 » Thu Dec 04, 2008 11:28 pm

Thanks mate,

I tried but problem is once condition fulfill then loop must be stop like if variable found Y character in excel it only shows me message box "Hi" and Message box "Hello" for N. but doesn't matter whatever it found in excel it shows me both the messagebox.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Dec 04, 2008 11:43 pm

whatever it found in excel it shows me both the messagebox.
The only way I could see that happening is if you have used "Y" and "N" as variables previously in your script AND they are both set to the same value as the variable "One".

Try setting the system variable VAREXPLICIT=1. Also, show the values of "One" "N" and "Y" in your message so you can see what their values are.

Code: Select all

label>New
Let>VAREXPLICIT=1
SetFocus>Microsoft Excel*
Press Ctrl
send>c
Release Ctrl
press down
wait>1
gcb>One
if>One=Y
messagemodal>Hi One=%One% Y=%Y% N=%N%
EndIf
if>One=N
messagemodal>Hello One=%One% Y=%Y% N=%N%
endif
Let>VAREXPLICIT=0
goto New

hardik_228
Newbie
Posts: 12
Joined: Mon Dec 01, 2008 10:46 am

Post by hardik_228 » Mon Dec 08, 2008 1:18 am

I tried this as well, but it is also shows two messages. if variable found "Y" then it shows only one message and only one message for "N" as well, but whatever it found always shows 2 messages. i tried with 0 and 1 insted of Y and N but problem is same. the thing is if variable found Y then display message "HI" and found N then display message "HELLO" and anything else then not a single message. but rather than this it is always show both the messages. help please!!!!!!!! now i do not know what i will do to sorted out this problem. i am new for macro programming.

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 Dec 08, 2008 2:53 am

You need to post your full script so that we can see the problem.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Use %% when VAREXPLICIT=1

Post by gdyvig » Mon Dec 08, 2008 4:00 pm

Hi,

I don't see why your code would display both messages, it should have displayed neither message. Because VAREXPLICIT=1 when you do the if statements, you must use if>%One%. Also your clipboard may contain extra characters that need to be stripped off. The following code should work provided the first character in the clipboard is Y or N.

abel>New
Let>VAREXPLICIT=1
SetFocus>Microsoft Excel*
Press Ctrl
send>c
Release Ctrl
press down
wait>1
gcb>One
MidStr>%One%,1,1,One
if>%One%=Y
messagemodal>Hi One=%One% Y=%Y% N=%N%
EndIf
if>%One%=N
messagemodal>Hello One=%One% Y=%Y% N=%N%
endif
Let>VAREXPLICIT=0
goto New

hardik_228
Newbie
Posts: 12
Joined: Mon Dec 01, 2008 10:46 am

Post by hardik_228 » Tue Dec 09, 2008 3:20 am

Actually what i want to do with my script is;

-i have excel sheet with 5 codes in A1 to A5
-i have status of those code in B1 to B5

now, in B1 to B5, if i want to apply that code to particular service then i put Y in front of that code and N for do not apply.

now, the problem is my whole script is running perfect. but it is not going in to loop.

so i set that loop like this,

if in cell B1 i got value Y then i stored that value in one variable. then i check that variable with if condition. if i got value Y then show me message "Hi". Now in cell B2 i got value N then as per if condition it shows me "Hello". (instead of applying code, first i have to see message so i can understand it is going in to loop, but it is not working.)

if this loop is working well then instad of putting Hi and Hello i will able put my codes.

so my all friends if you have any solution for this problem then let me know. you can create your own small script which get cell value from excel and shows the message what i want. Please help me. following is my created script.

**********************************

Let>Vari=0

label>New
SetFocus>Microsoft Excel*
Press Ctrl
Send>c
Release Ctrl
Press Down
Wait>1
gcb>Vari

if>Vari=Y
messagemodal>"Hi"
end if

if>vari=N
messagemodal>"Hello"
end if

goto>New

******************

it is always shows me two messages.

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Each cell value is appended with CRLF

Post by gdyvig » Tue Dec 09, 2008 4:33 pm

//Use endif, not end if
//Provide way to exit loop
//Start script with cell B1 highlighted
//Assume all cell values appended with CRLF.
//This script demonstrates presense of CRLF

Let>Vari=0
Let>Blank=
Let>Counter=0

label>New
Let>Counter=%Counter%+1
SetFocus>Microsoft Excel*
Press Ctrl
Send>c
Release Ctrl
Press Down
Wait>1
gcb>Vari
Messagemodal>vari:(%vari%)
//Vari will have CRLF appended, strip it off
Position>CRLF,%Vari%,1,CRLFPOS
Let>len=%CRLFPOS%-1
if>%len%>-1
midstr>%vari%,1,%len%,vari
else
Let>var=Blank
endif
Messagemodal>vari:(%vari%)

if>Vari=Y
messagemodal>"Hi"
endif

if>vari=N
messagemodal>"Hello"
endif

if>vari=%Blank%
Messagemodal>"BlankDone"
goto>Done
endif

if>Counter=10
Messagemodal>"CounterDone"
goto>Done
endif

goto>New
Label>Done

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