Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Convert numeric string into a variable


Recommended Posts

Hi guys,

     Its been a while.  I am stumped right now trying to convert a numeric string variable into a variable so that I may use it in an argument.

 

stoolusedes2 = brksps(16, stoolusedes1) # Break string

*stoolusedes2, e$

 

This posts out the following string: .1875     This is correct.

 

This value is from the end of the string.  I would like to do this:

 

emasbb = value (stoolusedes2)     But how do I do this.

 

I know about no2str, I'm just trying to do this in reverse and convert the string into something I can use.

 

Thanx

Link to comment
Share on other sites

The function you need is 'rpar'.

 

emasbb = rpar(stoolusedes2, 1)

 

The 'rpar' function can be used on a single variable (when the 2nd argument is '1'), or to extract a "space delimited" range of variables.

 

So if your string had five numeric values, separated by spaces, then you could extract all five variables from that string, like so:

 

 

my_real1  : 0

my_real2  : 0

my_real3  : 0

my_real4  : 0

my_real5  : 0

 

smy_string : "1 2.456 2.145 8.12 9.999"

 

my_real1 = rpar (smy_string, 5)

 

That would load the values as follows:

 

my_real1  : 1.0

my_real2  : 2.456

my_real3  : 2.145

my_real4  : 8.12

my_real5  : 9.999

Link to comment
Share on other sites

Also, depending on what you are trying to capture from the original string parameter, it might just be easier to use the 'scan' function.

 

The 'scan' function scans through a String variable, looking for a 'sub-string'. If that string is found, the functions looks to the right of the sub-string location, and looks for a "numeric" string value. If found, the function then converts that numeric string into a Real number, and places it in the return variable.

 

my_real6 : 0

 

smy_string : "tool_dia 0.5 flute_len 1.75 flood_cool 1 thru_cool 0"

 

 

std : "tool_dia"

sfl  : "flute_len"

sfc : "flood_cool"

stc : "thru_cool"

 

tool_dia : 0

flute_len : 0

flood_cool : 0

thru_cool : 0

 

flood_cool = scan (sfc, smy_string) #scan string to get value after string

if flood_cool < 0, result = mprint("flood_cool not found in search string")

Link to comment
Share on other sites

Thanks again Colin,

    I guess I was only thinking that the rpar function is only for reading from the NCI.  I was not thinking that I could use the rpar on an internal variable that I created.  Works as planned, now I can read from the data from the tool name to get extra parameters that I need to pass on.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...