Converting a string to a number
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2011-04-09 07:44 PM
‎2011-04-09
07:44 PM
TIA
Jeffrey
6 REPLIES 6

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2011-04-10 11:31 AM
‎2011-04-10
11:31 AM
You must use SPLIT to split parts of strings into numbers.
http://www.selfgdl.com/7_function/str_funktion/SPLIT/kompendium.php
e.g. n = SPLIT ("15.25", "%n", num_val)
num_val returns the number value of "15.25"
e.g. n = SPLIT ("15.25", "%n", num_val)
num_val returns the number value of "15.25"
Jochen Suehlo . AC12-28 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de
GDL object creation: b-prisma.de
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2011-04-10 04:13 PM
‎2011-04-10
04:13 PM
Thanks Joachim,
I have been trying that but then I no longer have a string. Instead of just reading the appropriate parts it destroys the original string therefore destroying the value list it comes from and I get an "Error in expression..".
myparameterstring is a value list that represents part of an alphanumeric ID, it only contains 4 numbers i.e. "1224" that represent two dimensions (length and width) STRSUB was the easiest way I found to separate the first two numbers from the last. There are a few hundred variations. "1224", "1226", "1424", "1426"...
myparameterstring is in the parameter list as text (ABC) and needs to be used elsewhere.
nmbrvl = STRSUB(myparameterstring, 1, 2)
wdth = SPLIT ("nmbrvl", %n, num)
oawdth = wdth * 12"
The ultimate goal is to change it to a dimension.
Is there any way to prevent split from destroying the string?
Thanks
AC 9
I have been trying that but then I no longer have a string. Instead of just reading the appropriate parts it destroys the original string therefore destroying the value list it comes from and I get an "Error in expression..".
myparameterstring is a value list that represents part of an alphanumeric ID, it only contains 4 numbers i.e. "1224" that represent two dimensions (length and width) STRSUB was the easiest way I found to separate the first two numbers from the last. There are a few hundred variations. "1224", "1226", "1424", "1426"...
myparameterstring is in the parameter list as text (ABC) and needs to be used elsewhere.
nmbrvl = STRSUB(myparameterstring, 1, 2)
wdth = SPLIT ("nmbrvl", %n, num)
oawdth = wdth * 12"
The ultimate goal is to change it to a dimension.
Is there any way to prevent split from destroying the string?
Thanks
AC 9
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2011-04-10 04:33 PM
‎2011-04-10
04:33 PM
Jeffrey wrote:The whole point of SPLIT is to convert from string to number so the string aspect of the value will be lost. As long as the string is preserved in the original variable what is the problem?
Is there any way to prevent split from destroying the string?
The ultimate goal is to change it to a dimension.For this you will need to convert the extracted number (which I assume is in inches) to meters since this is what GDL uses internally. Something like:
wdth = SPLIT ("nmbrvl", %n, num) * 0.0254To later display this as a dimension would require STR with the appropriate format string.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2011-04-10 04:40 PM
‎2011-04-10
04:40 PM
Jeffrey,
if you want to convert a string into a number, you must destroy the string.
But: you can use a new variable, so you do not have to destroy the original string.
The syntax of your script was not complete correct.
The variable before SPLIT is a dummy, not the returned value (it is 0 or 1),
that shows if SPLIT returns a value or not.
Try this script:
VALUES "myparameterstring" "1224", "1226", "1424", "1426"
nmbrvl = STRSUB(myparameterstring, 1, 2)
TEXT2 0,0,nmbrvl
x = SPLIT (nmbrvl, "%n", num)
oawdth = num * 12"
TEXT2 0,-0.1,oawdth
TEXT2 0,-0.2,x
I hope, I understood you right. But you cannot use the same variable/parameter both as string and as number.
if you want to convert a string into a number, you must destroy the string.
But: you can use a new variable, so you do not have to destroy the original string.
The syntax of your script was not complete correct.
The variable before SPLIT is a dummy, not the returned value (it is 0 or 1),
that shows if SPLIT returns a value or not.
Try this script:
VALUES "myparameterstring" "1224", "1226", "1424", "1426"
nmbrvl = STRSUB(myparameterstring, 1, 2)
TEXT2 0,0,nmbrvl
x = SPLIT (nmbrvl, "%n", num)
oawdth = num * 12"
TEXT2 0,-0.1,oawdth
TEXT2 0,-0.2,x
I hope, I understood you right. But you cannot use the same variable/parameter both as string and as number.
Jochen Suehlo . AC12-28 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de
GDL object creation: b-prisma.de

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2011-04-10 04:51 PM
‎2011-04-10
04:51 PM
Matthew,
if I try this:
Please try instead:
GDL is able to interpret the Inch sign.
if I try this:
wdth = SPLIT (nmbrvl, "%n", num) * 0.0254 (the quotes must be around %n) TEXT2 0,-0.4,wdthit returns 0.0254.
Please try instead:
x = SPLIT (nmbrvl, "%n", num) oawdth = num * 12" TEXT2 0,-0.1,oawdthIf I calculate manually, the TEXT2 shows the correct result (in meters).
GDL is able to interpret the Inch sign.
Jochen Suehlo . AC12-28 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de
GDL object creation: b-prisma.de
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2011-04-10 07:59 PM
‎2011-04-10
07:59 PM
Thanks Matthew, Joachim,
I need the string to remain intact because it is part of a value list of predetermined sizes and is also used elsewhere in the script. The objects properties and other dimensions change depending on the size.
Joachim, It worked like a charm. I was thinking the new number was ???=SPLIT. Once I added the quotations to the %n and replaced num with wdth it all worked perfectly and the string stays intact.
The end result is.
nmbrvl = STRSUB (myparameterstring, 1, 2)
SPLIT (nmbrvl, "%n", wdth)
oawdth = wdth * 12"
The UI did show as meters but all I had to do was change "aowdth" to a formatted string.
Thanks again.
I need the string to remain intact because it is part of a value list of predetermined sizes and is also used elsewhere in the script. The objects properties and other dimensions change depending on the size.
Joachim, It worked like a charm. I was thinking the new number was ???=SPLIT. Once I added the quotations to the %n and replaced num with wdth it all worked perfectly and the string stays intact.
The end result is.
nmbrvl = STRSUB (myparameterstring, 1, 2)
SPLIT (nmbrvl, "%n", wdth)
oawdth = wdth * 12"
The UI did show as meters but all I had to do was change "aowdth" to a formatted string.
Thanks again.