Discussion:
Coding problem
Daniel Drijard
2018-08-05 17:42:17 UTC
Permalink
Hello,

I have a problem. I use macOS SIERRA (10.12.6) on an iMac Retina bought 9/2015.
The following shows my code. The program blows up in this routine, pointing to Adr(i).

Cordially,
Daniel

•••••••••••••••
Read4 Byref NbWords as integer, Byref Adr() as integer
dim i as integer
for i=1 to NbWords
Adr(i)=MyBin.readint32
next

MyBin was declared as BinaryStream
•••••••••••••••

Daniel Drijard
Thoiry téléphone :
04 50 41 22 75
international
+33/4 50 41 22 75
Courriel :
***@cern.ch
Thoiry F-01710
Jon Ogden
2018-08-05 17:44:47 UTC
Permalink
What is blowing up? Is MyBin not Nil? Has it been opened?

What is the error message?

Sent from my iPhone
Post by Daniel Drijard
Hello,
I have a problem. I use macOS SIERRA (10.12.6) on an iMac Retina bought 9/2015.
The following shows my code. The program blows up in this routine, pointing to Adr(i).
Cordially,
Daniel
•••••••••••••••
Read4 Byref NbWords as integer, Byref Adr() as integer
dim i as integer
for i=1 to NbWords
Adr(i)=MyBin.readint32
next
MyBin was declared as BinaryStream
•••••••••••••••
Daniel Drijard
04 50 41 22 75
international
+33/4 50 41 22 75
Thoiry F-01710
48, rue des Savoies
Jean-Pierre DOUCET
2018-08-05 20:05:36 UTC
Permalink
Hi Daniel,
From the doco :
If you try to access an element of an array that does not exist, you will get an OutOfBoundsException <http://developer.xojo.com/outofboundsexception>. Here are some examples that would raise the exception:
aNames(5) = "Tom" ' this exceeds the upper bound of aNames
aFirstName(1) = "Bill" ' aFirstName is still empty
Use the methods Append <http://developer.xojo.com/arrays$Append> and Insert <http://developer.xojo.com/arrays$Insert> to add additional elements to arrays. These methods are the only ways to add elements to empty arrays, but they can also be used to extend the size of any single-dimension array.
Hence : Adr.Append (MyBin.readint32)
Post by Daniel Drijard
Hello,
I have a problem. I use macOS SIERRA (10.12.6) on an iMac Retina bought 9/2015.
The following shows my code. The program blows up in this routine, pointing to Adr(i).
Cordially,
Daniel
•••••••••••••••
Read4 Byref NbWords as integer, Byref Adr() as integer
dim i as integer
for i=1 to NbWords
Adr(i)=MyBin.readint32
next
MyBin was declared as BinaryStream
•••••••••••••••
Daniel Drijard
04 50 41 22 75
international
+33/4 50 41 22 75
Thoiry F-01710
48, rue des Savoies
Cordially,
JPD
Markus Winter
2018-08-05 21:14:52 UTC
Permalink
Post by Daniel Drijard
Read4 Byref NbWords as integer, Byref Adr() as integer
dim i as integer
for i=1 to NbWords
Adr(i)=MyBin.readint32
next
Are you sure Adr() doesn‘t start at zero and goes to NbWords - 1 ?

Test by checking ubound of Adr()

Markus

Continue reading on narkive:
Loading...