Proper use of "upper"?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

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

Proper use of "upper"?

Post by JRL » Tue Mar 14, 2006 6:56 pm

Ran into this issue this morning. It's probably something I'm missing.

The ERP software I work with has workorder numbers that are in two parts, job number and job number suffix. The job number always has 6 characters and the suffix always has 3 characters. Even though the title is "job number" the input characters are alphanumeric (although alpha characters need to be capitalized.)

I have a program that allows a bar code scanner to "type" the job number and suffix into input boxes, runs the two generated variables through the "upper" function to make sure they are upper case, then pastes the values into the appropriate fields in a form.

If suffix = inv, the line Let>suffix={upper(%suffix%)} will change the value of suffix to INV as expected. My problem is that if variable suffix = 001, the line Let>suffix={upper(%suffix%)} will strip off the leading zeros and the value of suffix will become 1. So, I added quotes around %suffix% altering the script line to read Let>suffix={upper("%suffix%")}. Now a suffix value of 001 remains 001 but a suffix value inv throws a Macro Scheduler error "Incorrectly formed parameters", followed by a second error "i not appropriate".

Next I tried the same thing setting VAREXPLICIT=1 and got the same results.

In other complex expressions quotes are required around text items. Why do I get an error when surrounding text with quotes using the "upper" function?

Examples and results:


Let>suffix=inv
Let>suffix={upper(%suffix%)}

suffix will equal INV


Let>suffix=001
Let>suffix={upper(%suffix%)}

suffix will equal 1


Let>suffix=001
Let>suffix={upper("%suffix%")}

suffix will equal 001


Let>suffix=inv
Let>suffix={upper("%suffix%")}

Macro Scheduler will error

Thanks for listening,
Dick

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

Post by Me_again » Wed Mar 15, 2006 3:26 am

This issue has been raised before. Help does say that upper only works with a-z but it does seem reasonable that there should be a way to have it handle numerics more gracefully.

If you need it then this is a workaround:

Let>suffix=001
Concat>suffix,x
Let>suffix={upper(%suffix%)}
MidStr>suffix,1,3,suffix
MessageModal>%suffix%

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

Post by pgriffin » Wed Mar 15, 2006 2:32 pm

While it might not be the easiest route, my work-around would be to test the %suffix% string for numeric characters, then optionally use Upper.

I'm sure there is some slick way to use VBScript for this but I literally examine each character.

AlphaChar=ABCDEFGHIJK.....abcdefg......
NumChar=0123456789

then something like Pos>SuffixCharOne,AlphaChar,AlphaFound
Pos>SuffixCharOne,NumChar,NumFound

you get the picture....

if you would like I can send plenty of example code...

painful, but effective

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

Post by JRL » Wed Mar 15, 2006 2:48 pm

Thanks Me_again that works.

Using the concept you supplied I've added a line and made the problem resolution more generic. The following does the same thing without any need to know the length of the string.

Let>prefix=x
Let>suffix=inventory
Concat>prefix,suffix
Let>prefix={upper(%prefix%)}
MidStr>prefix,2,
2147483647,suffix
MessageModal>%suffix%


Incidently, 2147483647 is the largest number that I've been able to use with Midstr.

Later,
Dick

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

Post by Me_again » Wed Mar 15, 2006 7:45 pm

You made it too easy with that fixed format :lol: I think it would be a bit more elegant to just get the length of the string and use that in the MidStr>

Let>prefix=x
Let>suffix=inventory
Concat>prefix,suffix
Let>prefix={upper(%prefix%)}
Len>suffix,lenny
MidStr>prefix,2,%lenny%,suffix
MessageModal>%suffix%

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

Post by Me_again » Wed Mar 15, 2006 7:56 pm

SkunkWorks wrote:While it might not be the easiest route, my work-around would be to test the %suffix% string for numeric characters, then optionally use Upper.

I'm sure there is some slick way to use VBScript for this but I literally examine each character.

AlphaChar=ABCDEFGHIJK.....abcdefg......
NumChar=0123456789

then something like Pos>SuffixCharOne,AlphaChar,AlphaFound
Pos>SuffixCharOne,NumChar,NumFound

you get the picture....

if you would like I can send plenty of example code...

painful, but effective
So far as I can tell upper only gives the wrong result if the string is 100% numeric AND starts with a zero.

So:

001 results in 1
100 results in 100
001x results in 001X

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

Post by pgriffin » Mon Mar 20, 2006 3:32 pm

In either case, my method works.

If the char is any number, then it simply includes that char in the "result" string...

concat>Result,ThisChar

if it is alpha, then it uses UPPER, then also includes it in the result.

Let>ThisChar={upper(%ThisChar%)}
concat>Result,ThisChar

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