We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2024-05-15 10:47 AM
Hello everyone,
I've been studying arrays, and I'd like to know if an idea I had in mind was possible:
I'd like to give the user the possibility of manually entering numbers in an ui_infield by separating them with a space (or a /) and have these numbers automatically transferred into an array, one entry per number.
For example:
0 1 12 15 16 30
or
0/1/12/15/16/30
I've looked at STRSUB, but you need to know the length of the elements. The problem with numbers is that they can be 1, 2 or 3+ long.
Any ideas on how to extract the data from the text?
(And how to enter them in an array?)
Thanks a lot!
2024-05-15 02:52 PM - last edited on 2024-05-16 01:41 PM by Laszlo Nagy
STRSTR will return the location of a character in a string. So can be used in conjunction with STRSUB to split strings at certain characters.
I’m thinking you’d want a while loop to process the input string, split it at the slash and grab the first part and drop it into the first index of an array.
Then grab the remainder of the string and do the same thing again. And keep doing that until you can’t find any more slashes in your string.
I’m not at a computer at the moment so this probably has syntax errors galore but maybe something like this:
Input_str = “0/1/12/15/16/30”
slash_present = true
dim inputs_array[]
i = 1
WHILE slash_present DO
slash_pos = STRSTR(input_str, “/“)
IF slash_pos <> 0 THEN
inputs_ary[i] = SUBSTR(input_str,1,slash_pos)
Input_str = SUBSTR(input_str,slash_pos+1,STRLEN(input_str))
i = i + 1
ELSE
slash_present = false
ENDIF
ENDWHILE
2024-05-17 09:23 AM - edited 2024-05-17 09:31 AM
Hi,
SPLIT is the command that converts strings to numbers. You can make an assumption about the maximum number of numbers present in the infield, or pre-split the whole string with scottjm's code.