Trouble with variable expressions

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
ari
Junior Coder
Posts: 23
Joined: Tue Jul 15, 2014 4:12 pm

Trouble with variable expressions

Post by ari » Fri Nov 04, 2016 9:09 pm

I am trying to write a script that copies a string of text from a program (electronic medical record), then a certain string of text is written to a text file depending on what was copied.

Code: Select all

//Copy text
Press LShift
Press End
Press Left
Wait>0.2
Release LShift


//copy spiro statement to clipboard
Press LCtrl
Send>c
Release LCtrl

Wait>1
GetClipBoard>var_spiro

Wait>1

//translate EMR text into custom text
If>%var_spiro%=Normal spirometry.
Let>spiroresults=The spirometry is normal.
Endif

Wait>0.5

If>%var_spiro%=Obstruction may be a physiological variant.
Let>spiroresults=The spirometry is normal.
Endif

Wait>0.5

If>%var_spiro%=Normal spirometry. Post bronchodilator test not improved.
Let>spiroresults=The spirometry is normal and non-reversible with a bronchodilator.
Endif

Wait>0.5

If>%var_spiro%=Mild airway obstruction.
Let>spiroresults=The spirometry demonstrates mild airway obstruction.
Endif

Wait>0.5

If>%var_spiro%=Mild airway obstruction. Post bronchodilator test improved.
Let>spiroresults=The spirometry demonstrates mild airway obstruction, significantly reversible with a bronchodilator.

Wait>0.5

Else
Let>spiroresults=var_spiro
Endif

This fails every time and just writes the value of var_spiro to the text file rather than switching it to my preferred text. I added a lot of wait times without any improvement. Any help appreciated!!

ari
Junior Coder
Posts: 23
Joined: Tue Jul 15, 2014 4:12 pm

Re: Trouble with variable expressions

Post by ari » Fri Nov 04, 2016 9:19 pm

Very very oddly, the 5th case worked

Code: Select all

If>%var_spiro%=Mild airway obstruction. Post bronchodilator test improved.
Let>spiroresults=The spirometry demonstrates mild airway obstruction, significantly reversible with a bronchodilator.
Whereas the other scenarios do not...

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

Re: Trouble with variable expressions

Post by Marcus Tettmar » Mon Nov 07, 2016 10:09 am

Hi,

Maybe there are spaces or control characters at the start/end of the text you have copied from the clipboard, causing your comparisons to fail. Therefore try trimming the value returned from the clipboard.

The waits between your comparisons are utterly pointless by the way ;-) I would also remove the percents from the variable on the left of the If condition. Here's my version of your code, with some indentations for readability:

Code: Select all

//Copy text
Press LShift
Press End
Press Left
Wait>0.2
Release LShift

//copy spiro statement to clipboard
Press LCtrl
Send>c
Release LCtrl

Wait>1
GetClipBoard>var_spiro

//Trim it to remove any leading/trailing spaces etc
Trim>var_spiro,var_spiro

//default
Let>spiroresults=var_spiro

//translate EMR text into custom text
If>var_spiro=Normal spirometry.
  Let>spiroresults=The spirometry is normal.
Endif

If>var_spiro=Obstruction may be a physiological variant.
  Let>spiroresults=The spirometry is normal.
Endif

If>var_spiro=Normal spirometry. Post bronchodilator test not improved.
  Let>spiroresults=The spirometry is normal and non-reversible with a bronchodilator.
Endif

If>var_spiro=Mild airway obstruction.
  Let>spiroresults=The spirometry demonstrates mild airway obstruction.
Endif

If>var_spiro=Mild airway obstruction. Post bronchodilator test improved.
  Let>spiroresults=The spirometry demonstrates mild airway obstruction, significantly reversible with a bronchodilator.
Endif
If still not getting what you expect USE THE DEBUGGER! :-) Set a breakpoint after the GetClipboard and then look in the watch list to see what the value actually is. Copy it from the watch list and paste into an editor which shows unprintable characters. Paste in the value you are comparing with. Look closely. If the Ifs are failing THEY ARE NOT THE SAME :-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Trouble with variable expressions

Post by hagchr » Mon Nov 07, 2016 10:25 am

Hi, I think your ELSE statement only refers to your final IF statement. This means that if one of your first IF statements triggers then the final IF will not, BUT the ELSE will, and thus will "kill" any previous matches.

You can eg define a flag=FALSE in the beginning and set it to TRUE in each IF statement. Then finally, you have an IF statement checking if the flag is still FALSE (in which case there was no match up above).

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

Re: Trouble with variable expressions

Post by Marcus Tettmar » Mon Nov 07, 2016 10:28 am

Yes, good point. If any of the first few If conditions match then the last one will trigger the Else condition. I was focusing on the Trim and had already altered your code to set the default (else) at the top, removing that final else, so that this wouldn't happen.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

ari
Junior Coder
Posts: 23
Joined: Tue Jul 15, 2014 4:12 pm

Re: Trouble with variable expressions

Post by ari » Mon Nov 07, 2016 4:28 pm

Thanks for your replies, learned a lot, trim worked like a charm.

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