What is wrong with this code?
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
What is wrong with this code?
Okay, I am rather new to this. I've been converting some VB code to PB and so far its been working fine. Until I introduced the use of structures.
This line of code is generating "[ERROR] Array index out of bounds."
tflights(i)\actype = actypes(typecnt)\actype ;this is the index to the actypes array
When this line of code is called upon, i = 1 and typecnt = say 13. Both of which are well within the bounds of the structure array.
If I enter tflights(1)\actype and click on [Display] with the debugger, it displays exactly what I am expecting.
If I enter actypes(13)\actype and click on [Display] with the debugger, it too displays exactly what I am expecting.
Is there some fundamental thing I am missing in the code?
Thanks.
This line of code is generating "[ERROR] Array index out of bounds."
tflights(i)\actype = actypes(typecnt)\actype ;this is the index to the actypes array
When this line of code is called upon, i = 1 and typecnt = say 13. Both of which are well within the bounds of the structure array.
If I enter tflights(1)\actype and click on [Display] with the debugger, it displays exactly what I am expecting.
If I enter actypes(13)\actype and click on [Display] with the debugger, it too displays exactly what I am expecting.
Is there some fundamental thing I am missing in the code?
Thanks.
Re: What is wrong with this code?
Need to see some code.
Try using ArraySize() to see exactly what the array upper bounds are.
Try using ArraySize() to see exactly what the array upper bounds are.
I may look like a mule, but I'm not a complete ass.
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: What is wrong with this code?
Actually, I've been using the debugger and using Arraysize;
===========================================
Number = Random(32767)
RandomSeed(Number)
newtype = Random(ArraySize(tindex()),1)
typecnt = tindex(newtype)
tmp = actypes(typecnt)\actype
Debug actypes(typecnt)\actype
Debug ArraySize(tindex())
Debug newtype
Debug ArraySize(tflights())
Debug "TFLIGHTS = "+Str(ArraySize(TFLIGHTS()))
===========================================
What will display is this;
tmp = nothing
actypes(typecnt)\actype = (the correct response)
ArraySize(tindex()) = 13 (the correct amount)
newtype = 1 - 58 (within range)
Arraysize(tflights()) = 13 (the correct size of the array)
i = 1 (which is the first element of the tflights() structure
So, I am really baffled. When I attempt to assign directly from one structure to the other, is when the error occurs:
tflights(i)\actype = actypes(typecnt)\actype
both elements in the structures are the same thing; strings.
===========================================
Number = Random(32767)
RandomSeed(Number)
newtype = Random(ArraySize(tindex()),1)
typecnt = tindex(newtype)
tmp = actypes(typecnt)\actype
Debug actypes(typecnt)\actype
Debug ArraySize(tindex())
Debug newtype
Debug ArraySize(tflights())
Debug "TFLIGHTS = "+Str(ArraySize(TFLIGHTS()))
===========================================
What will display is this;
tmp = nothing
actypes(typecnt)\actype = (the correct response)
ArraySize(tindex()) = 13 (the correct amount)
newtype = 1 - 58 (within range)
Arraysize(tflights()) = 13 (the correct size of the array)
i = 1 (which is the first element of the tflights() structure
So, I am really baffled. When I attempt to assign directly from one structure to the other, is when the error occurs:
tflights(i)\actype = actypes(typecnt)\actype
both elements in the structures are the same thing; strings.
Re: What is wrong with this code?
Post some code showing the problem.
All your source OR part of it OR extract structures definitions / arrays / dimensioning code only and put together some equivalent snippet as long it shows the error and it's compilable.
All your source OR part of it OR extract structures definitions / arrays / dimensioning code only and put together some equivalent snippet as long it shows the error and it's compilable.
"Have you tried turning it off and on again ?"
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: What is wrong with this code?
Your code snippet is not complete, we can't see if you have defined the structure or the arrays correctly.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: What is wrong with this code?
Thanks guys. I did narrow the problem down to the variable (i). So I'm looking back through the code to see what is happening with i.
Re: What is wrong with this code?
There is no need to use Debug with so many times.
Add a breakpoint, then go into the debugger menu then take a look at variable viewer. You will be able to view the contents and size of your structure and compare this against any variables.
Add a breakpoint, then go into the debugger menu then take a look at variable viewer. You will be able to view the contents and size of your structure and compare this against any variables.
----
R Tape loading error, 0:1
R Tape loading error, 0:1
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: What is wrong with this code?
Thanks...yes, I've been adding lots of breakpoints and examining variables, arrays, etc.
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: What is wrong with this code?
Thanks for your feedback guys. I fixed the problem.
I needed to Redim tflights by 1 each time I added a new structured record and not use "i", but a unique integer representing the # of items in the array.
I needed to Redim tflights by 1 each time I added a new structured record and not use "i", but a unique integer representing the # of items in the array.
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: What is wrong with this code?
Linked List might serve you better.I needed to Redim tflights by 1 each time I added a new structured record
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.


