Removing non numeric characters from a string

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Rory
Pro Scripter
Posts: 50
Joined: Thu Mar 23, 2006 2:50 pm
Location: Wisconsin

Removing non numeric characters from a string

Post by Rory » Mon Apr 10, 2006 6:40 pm

This Example was posted in the Scripts and tips forum back in 1999.
http://www.mjtnet.com/usergroup/viewtop ... ht=numeric

Let>MyVal=3g5tmar61gg3

Let>k=0
Length>MyVal,lv
Let>NewVal=
Label>Trim
Let>k=k+1
if>k>lv,Done
MidStr>MyVal,k,1,char
If>charchar>9,Trim
ConCat>NewVal,char
Goto>Trim
Label>Done
Let>MyVal=NewVal

I copied this and created a new macro containing only the script above and it work perfectly.

When I inserted this same script into my other existing script, the line "Let>NewVal=" Assigns 0 (zero) to the variable NewVal.
Why is this happening and how can I get around it to so that the zero is not assigned.

Rory

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

Post by JRL » Mon Apr 10, 2006 10:11 pm

Rory,
You haven't provided enough info. All we can tell from this is that you are having a problem. Can you post the code that is not working for you?

Later,
Dick

Rory
Pro Scripter
Posts: 50
Joined: Thu Mar 23, 2006 2:50 pm
Location: Wisconsin

Post by Rory » Tue Apr 11, 2006 7:13 pm

I found a way around the problem. I am writing a script to creating a CNC program for one of our machine tools and the program number for the machine must be formated with an O along with five aditional numbers.
Example: O12345.

Basically I assigned the letter O to variable NewVal.
This is how I handled it:

Let>ProgNo=Dialog1.ProgNo
Let>q=0
Length>ProgNo,lv
Let>NewVal=O

Label>Trim
Let>q=q+1
if>q>lv,Done
MidStr>ProgNo,q,1,char
If>charchar>9,Trim
ConCat>NewVal,char
Goto>Trim
Label>Done
Let>ProgNo=NewVal
Length>%ProgNo%,ProgNoLength
If>%ProgNoLength%You have entered too few of numbers for the program number!%CRLF%The program number must contain five digits.%CRLF%Example: 12345%CRLF%%CRLF%Any letters will be ignored.
ENDIF
If>%ProgNoLength%>6
MessageModal>You have entered too many numbers for the program number!%CRLF%The program number must contain five digits.%CRLF%Example: 12345%CRLF%%CRLF%Any letters will be ignored.
ENDIF



Thanks,
Rory

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