License Delivery maintenance is expected to occur on Saturday, November 30, between 8 AM and 11 AM CET. This may cause a short 3-hours outage in which license-related tasks: license key upload, download, update, SSA validation, access to the license pool and Graphisoft ID authentication may not function properly. We apologize for any inconvenience.
Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Error when writing/reading an array

TomWaltz
Participant
This is kind of a strange problem.

I am reading a Text file into an Array:
	DO 
		n = INPUT (ch1, i, 1, keynote) 
		IF n > 0 AND VARTYPE (keynote) = 2 THEN 
			sarray = keynote 
			j = j + 1 
		ENDIF 
		i = i + 1 
	WHILE n > 0 
...which I am later in the script trying to retrieve:
	i = 1
FOR i = 1 to arrayLength
		split_char = ",," ! Two commas, field delimeter
		keynote = sarray
		test_text = keynote
		txlen = STRLEN (keynote)
		tx_split = STRSTR (keynote, split_char) 
	
		IF tx_split > 0 THEN	! If there is a Split Character found
			keynote_num = STRSUB(keynote, 1, tx_split-1)
			keynote_text = STRSUB(keynote, tx_split+2, txlen)
		ELSE
			keynote_num = keynote
			keynote_text = " "
		ENDIF
		GOSUB 110
		GOSUB 120
	NEXT i
Subroutines 110 and 120 actualy try to process the text to place it on the drawing.

This script does not have any errors when I run "Check Script", but I get an error when I try to save the object. The debugger tells me I have a "String type expression required" error on the line that reads "keynote = sarray"

What is really odd is that if I replace the with a number, like [4], the whole thing works.

Is there something obvious I am missing here?
Tom Waltz
10 REPLIES 10
Rob
Graphisoft
Graphisoft
Tom,
I have had the same problem a week ago or so.
Try this:

DO
n = INPUT (ch1, i, 1, keynote)
IF n > 0 AND VARTYPE (keynote) = 2 THEN
sarray = ""
sarray = keynote
j = j + 1
ENDIF
i = i + 1
WHILE n > 0

It has worked for me. It looks like you need to 'pre-format' the array and variable which are not declared as parametres to string. Same with the 'keynote' variable.
::rk
Karl Ottenstein
Moderator
Rob wrote:
sarray = ""
I don't think you need to put that statement in the loop, Rob, and execute it for every element. One statement above the loop may be enough to trick the GDL compiler.

I ran into something like this last week ... had nothing to do with arrays ... but with the 9.0 GDL compiler's confusion over the type of a variable. Similar error message to Tom. I found that I had to "declare" my string variables with a sequence of statements such as:

str1=""
str2=""
etc.

at the top of my script and then all was fine.

Karl
One of the forum moderators
AC 28 USA and earlier   •   macOS Sonoma 14.7.1, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB
Anonymous
Not applicable
Rob and Karl,
I thank you both very much!

I think this tip is very valuable and I can imagine
several situations where it could be applied.
"Pre-formating" as Rob calls it or as Karl
might say "Pre-declaring type" without initializing
I did not think was allowed but a statement like str1=""
apparently is allowed and understood by the processor.
Thank you,
Peter Devlin
Laszlo Nagy
Community Admin
Community Admin
I think the way it works in ArchiCAD is this:
if you have a new variable in a script, and it is not among the additional parameters (in which case AC knows its variable type as you have set it) and it has not been given a value earlier in the script (in which case again AC will know its type), THEN it will assume that its variable type is number.
If you want it otherwise, you have to specifically define its variable type (by the methods given by the above gentlemen).
Loving Archicad since 1995 - Find Archicad Tips at x.com/laszlonagy
AMD Ryzen9 5900X CPU, 64 GB RAM 3600 MHz, Nvidia GTX 1060 6GB, 500 GB NVMe SSD
2x28" (2560x1440), Windows 10 PRO ENG, Ac20-Ac27
TomWaltz
Participant
Funny.... I had that exact statement a few lines before the DO loop, and it didn't work.

That's OK. I've realized I don't really need an array to do what I want anyway.

Thanks!
Tom Waltz
TomWaltz
Participant
The problem I am finding now is that the text files I am reading have mixed string and numerical data in it. I am also finding that the word "Not" imports at a number "zero."

ARGGHH!!!!!

I was playing with OPEN, INPUT and VARTYPE, without any success.

It seems like the statement:
ch1 = OPEN("text", filename, "Mode = RO", Library)
SHOULD be telling Archicad to read the file as text, but it is not.

Is there another way?
Tom Waltz
TomWaltz
Participant
<SLAP FOREHEAD>


It all makes sense now.

Since my array was supposed to be a STRING array, whenever there was a number in the text file being read, it caused an error.

Once again, how can I specify to read the file LITERALLY AS STRINGS, not as numbers???
Tom Waltz
Rob
Graphisoft
Graphisoft
Tom,

the first of all this statement has a syntax error (I am not sure if you have realised that):
It seems like the statement:
Code:
ch1 = OPEN("text", filename, "Mode = RO", Library)
it should go like this:

ch1 = OPEN("text", filename, "Mode = RO, Library")
::rk
TomWaltz
Participant
sorry, I was going for concept, not compilabilty.
Tom Waltz