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
Removing non numeric characters from a string
Moderators: JRL, Dorian (MJT support)
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
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