Syntax Error with Complex Expression

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
sailor dude
Pro Scripter
Posts: 50
Joined: Fri Jan 20, 2006 10:43 pm

Syntax Error with Complex Expression

Post by sailor dude » Wed Jan 10, 2007 8:01 pm

If I end the input text with a period I see the message modal showing it is a period. However, I never get to the message modal "did i get here". I have tried many permutations of If>{((%CHARACTER%=" ")OR(%CHARACTER%="."))}

Please help
Thanks

Code: Select all

CapsOff
Let>RP_WINDOWMODE=3
Let>CHARACTER=
Let>MODEL=

Input>MODEL,ENTER MODEL


//  remove a trailing space or period in the string.  

//  Don't try and remove a character if the length is 0 or MODEL=

Length>MODEL,LENGTH

If>LENGTH=0
	Goto>DONT_PARSE
EndIf

//  Get the last character
MidStr>MODEL,LENGTH,1,CHARACTER
MessageModal>%CHARACTER%

//  If the last character is a space or period, remove it.
If>{((%CHARACTER%=" ")OR(%CHARACTER%="."))}
	 MessageModal>DID I GET HERE
	 Let>LENGTH=LENGTH-1
	 MidStr>MODEL,1,LENGTH,MOD_MODEL
Else>
	 Let>MOD_MODEL=MODEL
EndIf>

PutClipboard>MOD_MODEL

Label>DONT_PARSE

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Thu Jan 11, 2007 3:47 am

No idea if your choice of vars matters, but I would not use the word LENGTH to store the value for Length or the Word CHARACTER to store a value. Again, might not make any difference at all..... I also took a few liberties with the var names and logic, but my code produces the same result...

Label>GetInput
let>t Char=
let>MODEL=
Input>MODEL,Enter Model
Len>MODEL,lenMod
if>lenMod=0
goto>NoParse
endif>

Midstring>%MODEL%,%lenMod%,1,tChar

if>{(%tChar%=" ") or (%tChar%=".")}
let>lenMod=lenMod-1
midstring>%MODEL%,1,lenMod,MODEL
endif>

PutClipboard>MODEL
Label>NoParse

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Jan 11, 2007 4:29 am

I agree about the variable names, makes me nervous to do that.

Does your code work for you if the last character is a "." ? The compound if always chokes for me in that case. I can only make it work if I split the condition into two regular if's:

Label>GetInput
let>t Char=
let>MODEL=
Input>MODEL,Enter Model
Len>MODEL,lenMod
if>lenMod=0
goto>NoParse
endif>

Midstring>%MODEL%,%lenMod%,1,tChar
MDL>%tChar%
if>tChar=space,parse_it
if>tChar=.,parse_it,NoParse
Label>parse_it
MDL>parse_it
let>lenMod=lenMod-1
midstring>%MODEL%,1,lenMod,MODEL
endif>

MDL>MODEL
Goto>theend
Label>NoParse
MDL>NoParse
Label>theend

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Thu Jan 11, 2007 2:49 pm

Strange. I did not test the code bit I posted earlier, but when I clean it up enough to test, the complex expression, which I cut directly from a working program, will not work when the tChar value is a "."

Works fine if I also break the expression into two regular expressions.

Here is my modified code...

HEY! Sailordude, please tell us what you are trying to accomplish with this. Maybe we could suggest other ways to solve your problem.

Label>GetInput
let>tChar=
let>MODEL=
Input>MODEL,Enter Model
Len>MODEL,lenMod
if>lenMod=0
goto>NoParse
endif>

Midstr>%MODEL%,%lenMod%,1,tChar

if>%tChar%=" "
let>lenMod=lenMod-1
midstr>%MODEL%,1,lenMod,MODEL
endif>
if>%tChar%=.
let>lenMod=lenMod-1
midstr>%MODEL%,1,lenMod,MODEL
endif>
PutClipboard>MODEL
Label>NoParse

sailor dude
Pro Scripter
Posts: 50
Joined: Fri Jan 20, 2006 10:43 pm

Thanks

Post by sailor dude » Thu Jan 11, 2007 3:42 pm

I am getting information out of a database. The database chokes if there is a trailing space or period in the entry. I often double click and copy text out of documents. There is a trailing space or a period when I copy and paste text into the MS input box.

I will use 2 simple expressions to remove the trailing characters.

I am glad complex expressions are now available but, I wish using them was easier.

I wish MJNet would provide better complex expression examples in the help, improve the error messages, or suggest how to fix the expression before running the script to improve the useability of complex expressions. I have run into syntax issues too many times when using complex expressions.

I am not a programmer. I use MS to hack some simple programs to save keystrokes and mouse moves. I have written ~50 scripts I use daily.

I love MS and have been using it for 5 years. The support is terrific. I am now demoing the WebRecorder program to try and improve some of my scripts that access commonly used webpages.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Jan 11, 2007 4:04 pm

SkunkWorks wrote:Strange. I did not test the code bit I posted earlier, but when I clean it up enough to test, the complex expression, which I cut directly from a working program, will not work when the tChar value is a "."
Exactly! I'm going to post this as a bug since you have confirmed my result.

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Thu Jan 11, 2007 4:28 pm

ok, not to overwork this issue, but if I were writing this for you (and writing MacroScript is my living), I would probably do something like this...

If you aren't using VBScript at all, you are really missing out on some powerful capabilities....in this case, all you have to do is include the words vbstart and vbend....the functions are then available....and if you are copying to paste to a database, why not skip the input box and just get the clipboard contents into a var, clean up the var, and write it to the db? Also could use some VBScript to write it directly to the DB...btw, I added the CleanUp label for the case of finding a space AND a period at the end of a string....

vbstart
vbend
Label>GetInput
let>tChar=
let>MODEL=
Input>MODEL,Enter Model
Len>MODEL,lenMod
if>lenMod=0
goto>NoParse
endif>
Label>CleanUp
vbe>InstrRev("%MODEL%","."),LChar
if>LChar=lenMod
let>LChar=LChar-1
midstr>%MODEL%,1,%LChar%,MODEL
goto>CleanUp
endif>
vbe>InstrRev("%MODEL%"," "),LChar
if>LChar=lenMod
let>LChar=LChar-1
midstr>%MODEL%,1,%LChar%,MODEL
goto>CleanUp
endif>
mdl>%MODEL%
PutClipboard>MODEL
Label>NoParse

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

Post by Marcus Tettmar » Thu Jan 11, 2007 4:40 pm

And if *I* were writing this for you, I'd just do this:

Code: Select all

VBSTART
VBEND
Let>sModel=endswith.
VBEval>Replace("%sModel%",".","",1,Len("%sModel%")-1),sModel
VBEval>Replace("%sModel%"," ","",1,Len("%sModel%")-1),sModel

Issue with "." string and complex expression noted. Will be investigated.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Thu Jan 11, 2007 4:59 pm

very nice.....now I have that code in my toolbox as well.

:wink:

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