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

Just starting out? Need help? Post your questions and find answers here.
heinz.goldbach
User
User
Posts: 25
Joined: Mon Dec 12, 2005 8:35 pm
Location: Neuss - Germany

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

Post 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
Last edited by heinz.goldbach on Thu Feb 03, 2011 2:32 pm, edited 3 times in total.
Intel i3, 8 GB RAM, 2*200 GB HDD, Windows 7 64bit
SUSE LINUX 10.1
Mac G4, OSX 10.4.11, 80 GB HDD, 1,5 GB RAM
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

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

Post 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
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

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

Post 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! :)
Last edited by WilliamL on Thu Feb 03, 2011 12:40 am, edited 2 times in total.
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

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

Post 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 ^^
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
heinz.goldbach
User
User
Posts: 25
Joined: Mon Dec 12, 2005 8:35 pm
Location: Neuss - Germany

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

Post 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
Intel i3, 8 GB RAM, 2*200 GB HDD, Windows 7 64bit
SUSE LINUX 10.1
Mac G4, OSX 10.4.11, 80 GB HDD, 1,5 GB RAM
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
heinz.goldbach
User
User
Posts: 25
Joined: Mon Dec 12, 2005 8:35 pm
Location: Neuss - Germany

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

Post 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
Intel i3, 8 GB RAM, 2*200 GB HDD, Windows 7 64bit
SUSE LINUX 10.1
Mac G4, OSX 10.4.11, 80 GB HDD, 1,5 GB RAM
Post Reply