String not working in If Function.
Moderators: Dorian (MJT support), JRL
-
- Newbie
- Posts: 12
- Joined: Mon Dec 01, 2008 10:46 am
String not working in If Function.
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
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 12
- Joined: Mon Dec 01, 2008 10:46 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
-
- Newbie
- Posts: 12
- Joined: Mon Dec 01, 2008 10:46 am
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".whatever it found in excel it shows me both the messagebox.
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
-
- Newbie
- Posts: 12
- Joined: Mon Dec 01, 2008 10:46 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.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Use %% when VAREXPLICIT=1
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
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
-
- Newbie
- Posts: 12
- Joined: Mon Dec 01, 2008 10:46 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.
-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.
Each cell value is appended with CRLF
//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
//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