<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error when writing/reading an array in Libraries &amp; objects</title>
    <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93913#M38520</link>
    <description>Funny.... I had that exact statement a few lines before the DO loop, and it didn't work.&lt;BR /&gt;
&lt;BR /&gt;
That's OK. I've realized I don't really need an array to do what I want anyway.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
    <pubDate>Wed, 12 Jan 2005 15:02:07 GMT</pubDate>
    <dc:creator>TomWaltz</dc:creator>
    <dc:date>2005-01-12T15:02:07Z</dc:date>
    <item>
      <title>Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93908#M38515</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;&lt;R&gt;This is kind of a strange problem.&lt;BR /&gt;
&lt;BR /&gt;
I am reading a Text file into an Array:&lt;BR /&gt;

&lt;PRE&gt;	DO 
		n = INPUT (ch1, i, 1, keynote) 
		IF n &amp;gt; 0 AND VARTYPE (keynote) = 2 THEN 
			sarray&lt;J&gt; = keynote 
			j = j + 1 
		ENDIF 
		i = i + 1 
	WHILE n &amp;gt; 0 
&lt;/J&gt;&lt;/PRE&gt;

 ...which I am later in the script trying to retrieve:
&lt;PRE&gt;	i = 1
FOR i = 1 to arrayLength
		split_char = ",," ! Two commas, field delimeter
		keynote = sarray&lt;I&gt;
		test_text = keynote
		txlen = STRLEN (keynote)
		tx_split = STRSTR (keynote, split_char) 
	
		IF tx_split &amp;gt; 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
&lt;/I&gt;&lt;/PRE&gt;

Subroutines 110 and 120 actualy try to process the text to place it on the drawing.&lt;BR /&gt;
&lt;BR /&gt;
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&lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt;"&lt;BR /&gt;
&lt;BR /&gt;
What is really odd is that if I replace the &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt; with a number, like [4], the whole thing works.&lt;BR /&gt;
&lt;BR /&gt;
Is there something obvious I am missing here?&lt;/R&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 11 Jan 2005 18:16:58 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93908#M38515</guid>
      <dc:creator>TomWaltz</dc:creator>
      <dc:date>2005-01-11T18:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93909#M38516</link>
      <description>Tom,&lt;BR /&gt;
I have had the same problem a week ago or so. &lt;BR /&gt;
Try this:&lt;BR /&gt;
&lt;BR /&gt;
   DO &lt;BR /&gt;
      n = INPUT (ch1, i, 1, keynote) &lt;BR /&gt;
      IF n &amp;gt; 0 AND VARTYPE (keynote) = 2 THEN &lt;BR /&gt;
         sarray&lt;J&gt; = ""&lt;BR /&gt;
         sarray&lt;J&gt; = keynote &lt;BR /&gt;
         j = j + 1 &lt;BR /&gt;
      ENDIF &lt;BR /&gt;
      i = i + 1 &lt;BR /&gt;
   WHILE n &amp;gt; 0&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;/J&gt;&lt;/J&gt;</description>
      <pubDate>Wed, 12 Jan 2005 00:18:40 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93909#M38516</guid>
      <dc:creator>Rob</dc:creator>
      <dc:date>2005-01-12T00:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93910#M38517</link>
      <description>&lt;BLOCKQUOTE&gt;Rob wrote:&lt;BR /&gt; sarray&lt;J&gt; = ""
&lt;/J&gt;&lt;/BLOCKQUOTE&gt;

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.&lt;BR /&gt;
&lt;BR /&gt;
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:&lt;BR /&gt;
&lt;BR /&gt;
str1=""&lt;BR /&gt;
str2=""&lt;BR /&gt;
etc.&lt;BR /&gt;
&lt;BR /&gt;
at the top of my script and then all was fine.&lt;BR /&gt;
&lt;BR /&gt;
Karl</description>
      <pubDate>Wed, 12 Jan 2005 01:58:32 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93910#M38517</guid>
      <dc:creator>Karl Ottenstein</dc:creator>
      <dc:date>2005-01-12T01:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93911#M38518</link>
      <description>Rob and Karl,&lt;BR /&gt;
I thank you both very much!&lt;BR /&gt;
&lt;BR /&gt;
I think this tip is very valuable and I can imagine&lt;BR /&gt;
several situations where it could be applied.&lt;BR /&gt;
"Pre-formating" as Rob calls it or as Karl&lt;BR /&gt;
might say "Pre-declaring type" without initializing&lt;BR /&gt;
I did not think was allowed but a statement like str1="" &lt;BR /&gt;
apparently is allowed and understood by the processor.&lt;BR /&gt;
Thank you,&lt;BR /&gt;
Peter Devlin</description>
      <pubDate>Wed, 12 Jan 2005 02:24:15 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93911#M38518</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-01-12T02:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93912#M38519</link>
      <description>I think the way it works in ArchiCAD is this:&lt;BR /&gt;
 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.&lt;BR /&gt;
If you want it otherwise, you have to specifically define its variable type (by the methods given by the above gentlemen).</description>
      <pubDate>Wed, 12 Jan 2005 11:57:00 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93912#M38519</guid>
      <dc:creator>Laszlo Nagy</dc:creator>
      <dc:date>2005-01-12T11:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93913#M38520</link>
      <description>Funny.... I had that exact statement a few lines before the DO loop, and it didn't work.&lt;BR /&gt;
&lt;BR /&gt;
That's OK. I've realized I don't really need an array to do what I want anyway.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Wed, 12 Jan 2005 15:02:07 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93913#M38520</guid>
      <dc:creator>TomWaltz</dc:creator>
      <dc:date>2005-01-12T15:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93914#M38521</link>
      <description>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."&lt;BR /&gt;
&lt;BR /&gt;
ARGGHH!!!!!&lt;BR /&gt;
&lt;BR /&gt;
I was playing with OPEN, INPUT and VARTYPE, without any success.&lt;BR /&gt;
&lt;BR /&gt;
It seems like the statement:
&lt;PRE&gt;ch1 = OPEN("text", filename, "Mode = RO", Library)&lt;/PRE&gt;

SHOULD be telling Archicad to read the file as text, but it is not.&lt;BR /&gt;
&lt;BR /&gt;
Is there another way?</description>
      <pubDate>Wed, 12 Jan 2005 18:27:17 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93914#M38521</guid>
      <dc:creator>TomWaltz</dc:creator>
      <dc:date>2005-01-12T18:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93915#M38522</link>
      <description>&amp;lt;SLAP FOREHEAD&amp;gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
It all makes sense now. &lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
Once again, how can I specify to read the file LITERALLY AS STRINGS, not as numbers???</description>
      <pubDate>Wed, 12 Jan 2005 19:00:09 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93915#M38522</guid>
      <dc:creator>TomWaltz</dc:creator>
      <dc:date>2005-01-12T19:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93916#M38523</link>
      <description>Tom,&lt;BR /&gt;
&lt;BR /&gt;
the first of all this statement has a syntax error (I am not sure if you have realised that):&lt;BR /&gt;

&lt;BLOCKQUOTE&gt;It seems like the statement: &lt;BR /&gt;
Code: &lt;BR /&gt;
ch1 = OPEN("text", filename, "Mode = RO", Library) &lt;/BLOCKQUOTE&gt;

it should go like this:&lt;BR /&gt;
&lt;BR /&gt;
ch1 = OPEN("text", filename, "Mode = RO, Library")</description>
      <pubDate>Wed, 12 Jan 2005 21:35:40 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93916#M38523</guid>
      <dc:creator>Rob</dc:creator>
      <dc:date>2005-01-12T21:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93917#M38524</link>
      <description>sorry, I was going for concept, not compilabilty.</description>
      <pubDate>Wed, 12 Jan 2005 21:50:50 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93917#M38524</guid>
      <dc:creator>TomWaltz</dc:creator>
      <dc:date>2005-01-12T21:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Error when writing/reading an array</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93918#M38525</link>
      <description>ok then, I was just checking...&lt;BR /&gt;
&lt;BR /&gt;
back to your previous question.&lt;BR /&gt;
when you are reading the values to the array it does not matter wether the value is a string or a number&lt;BR /&gt;
&lt;BR /&gt;
so:&lt;BR /&gt;
&lt;BR /&gt;
sarray=""&lt;BR /&gt;
&lt;BR /&gt;
for rowNum=1 to 10&lt;BR /&gt;
n=input(ch1,rowNum,1,sarray[1])&lt;BR /&gt;
n=input(ch1,rowNum,2,sarray[2])&lt;BR /&gt;
n=input(ch1,rowNum,3,sarray[3])&lt;BR /&gt;
next rowNum&lt;BR /&gt;
&lt;BR /&gt;
****&lt;BR /&gt;
&lt;BR /&gt;
text file: blabla,1,0&lt;BR /&gt;
&lt;BR /&gt;
sarray[1]=blabla&lt;BR /&gt;
sarray[2]=1&lt;BR /&gt;
sarray[3]=0</description>
      <pubDate>Wed, 12 Jan 2005 22:32:01 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Error-when-writing-reading-an-array/m-p/93918#M38525</guid>
      <dc:creator>Rob</dc:creator>
      <dc:date>2005-01-12T22:32:01Z</dc:date>
    </item>
  </channel>
</rss>

