Page 1 of 1

PB 4,51 Read String in 2 Dimensions is impossible (SOLVED)

Posted: Thu Feb 03, 2011 12:24 am
by heinz.goldbach
Hello,
i have little Problem.
It seemed, that the reading of strings in a 2 dimensional variable is impossible.

Code: Select all

Global Dim Block1.s(100,100)         

Gosub ArraysFuellen
End


ArraysFuellen:
Restore AllgemeineFischkunde:
For x= 1 To 3
   For y= 1 To 5
    Read.s Block1.s(x,y)
  Next y
Next x  
Return


DataSection
AllgemeineFischkunde:

Data.s "Was befähigt Fische zum Hen?"
Data.s "a) Die Schleimhaut"
Data.s "b) Ein inneres Hörorgan"
Data.s "c) Die Kiemendeckel"
Data.s "2"


Data.s "Welche Gruppe unserer Fischfauna ?"
Data.s "a) Die Lachsartigen"
Data.s "b) Die Barschartigen"
Data.s "c) Die Karpfenartigen"
Data.s "3"


Data.s "Wieviel heimische Süßwasserfis"
Data.s "a) 10 Arten"
Data.s "b) 30 Arten"
Data.s "c) 70 Arten"
Data.s "3"
EndDataSection
i hope someone can Help.

Heinz

Re: PB 4,51 Read String in 2 Dimensions is impossible

Posted: Thu Feb 03, 2011 12:37 am
by Demivec
Why do you say it is impossible?

Code: Select all

ArraysFuellen:
Restore AllgemeineFischkunde:
For x= 1 To 3
  For y= 1 To 5
    Read.s Block1.s(x,y)
  Next y
  ;messageRequester ("", Block1.s(x,y),0) ; <== what is this supposed to show, 'y' is out of bounds after the loop ... it equals 6
Next x 
Return

Re: PB 4,51 Read String in 2 Dimensions is impossible

Posted: Thu Feb 03, 2011 12:37 am
by WilliamL
In your code, y is one more than 5 after it goes thru the 'Y' For/Next loop so it is beyond the dimensioned array.

Demivec - you beat me to it! :)

Re: PB 4,51 Read String in 2 Dimensions is impossible

Posted: Thu Feb 03, 2011 12:39 am
by STARGÅTE
bug ?

after your y-loop, y is 6, and 6 is over die array-size

Code: Select all

For y = 1 To 5
Next
Debug y
so use

Code: Select all

MessageRequester ("", Block1.s(x,5),0)
or what is "impossible"

EDIT: to slow ^^

Re: PB 4,51 Read String in 2 Dimensions is impossible

Posted: Thu Feb 03, 2011 12:59 am
by heinz.goldbach
Hello,
the problem is, that the data strings wouldnt read in the 2 dimensional strings in Block1.s (x.y).
When i advance the dim to Global Dim Block1.s(100,100) the problem is the same.
I shortened the Program to see it.
The Messanger shows the "empty" string after 5 runs.
The same code runs without problems under Linux and Windows.

Heinz

Re: PB 4,51 Read String in 2 Dimensions is impossible

Posted: Thu Feb 03, 2011 1:18 am
by ts-soft

Code: Select all

Global Dim Block1.s(100,100)         

Gosub ArraysFuellen
For x = 1 To 3
  For y = 1 To 5
    Debug Block1(x, y)
  Next
Next
End


ArraysFuellen:
Restore AllgemeineFischkunde:
For x= 1 To 3
  For y= 1 To 5
    Read.s Block1.s(x,y)
  Next y
Next x 
Return


DataSection
  AllgemeineFischkunde:
  
  Data.s "Was befähigt Fische zum Hen?"
  Data.s "a) Die Schleimhaut"
  Data.s "b) Ein inneres Hörorgan"
  Data.s "c) Die Kiemendeckel"
  Data.s "2"
  
  
  Data.s "Welche Gruppe unserer Fischfauna ?"
  Data.s "a) Die Lachsartigen"
  Data.s "b) Die Barschartigen"
  Data.s "c) Die Karpfenartigen"
  Data.s "3"
  
  
  Data.s "Wieviel heimische Süßwasserfis"
  Data.s "a) 10 Arten"
  Data.s "b) 30 Arten"
  Data.s "c) 70 Arten"
  Data.s "3"
EndDataSection

Re: PB 4,51 Read String in 2 Dimensions is impossible

Posted: Thu Feb 03, 2011 2:32 pm
by heinz.goldbach
Hello,
the Problem is solved.
I have declared two variables in my Program one normal (x,y) und one (nummer.b,y)

After readig the strings in the two dimensional Array with (x,y) everything is ok.
Later in the Program i work with the string.s (nummer.b,y).
When the Program enter string.s (nummer.b,y) the program crash.
After changing nummer.b to nummer, the Program runs without Problems.
Under Windows and Linux there was no Problem.
But it is nota a PureBasic MAC Problem
The Problem was between my ears.
Thanks
Heinz