UnderwareDESIGN

PlayBASIC => Beginners => Topic started by: monkeybot on July 05, 2014, 08:09:03 AM

Title: Strange redim behaviour
Post by: monkeybot on July 05, 2014, 08:09:03 AM
After populating the array we loop through it then we Redim to 200 and loop through it again and the for next loop only goes upto 100?

weird!

[pbcode]explicit on

dim test$(100)
local q,q2,q3

for q=0 to GetArrayElements(test$())
   test$(q)="test  "+str$(q)   
next



for q2=0 to GetArrayElements(test$())
   cls
   print "displaying  array"
   print test$(q2)
   sync
   wait 50
next

redim test$(200)
;local f=GetArrayElements(test$())


for q3=0 to GetArrayElements(test$())
   cls
   print "running array after redim to "+str$(GetArrayElements(test$()))
   print test$(q3)
   sync
   wait 50
next

waitkey
[/pbcode]

Title: Re: Strange redim behaviour
Post by: kevin on July 05, 2014, 08:19:39 AM

it might help if you put something in cells 101 to 200...  :)

Title: Re: Strange redim behaviour
Post by: monkeybot on July 05, 2014, 09:43:24 AM
but what if i want to allocate some more space to my array and fill it up later?
Title: Re: Strange redim behaviour
Post by: kevin on July 05, 2014, 06:13:43 PM
 what's stopping you from doing that ?



[pbcode]

explicit on

dim test$(10)
local q

// ---------------------------------------------------------
// Fill Test with some junk
// ---------------------------------------------------------
for q=0 to GetArrayElements(test$())
   test$(q)="test  "+str$(q)   
next


// ---------------------------------------------------------
// show contents of original array
// ---------------------------------------------------------
print "Original Array--------------------------------------"
for q=0 to GetArrayElements(test$())
   print "String"+digits$(q,2)+"="+test$(q)
next
sync


// ---------------------------------------------------------
// expand test array
// ---------------------------------------------------------
redim test$(20)

// ---------------------------------------------------------
// show contents of array after redim
// ---------------------------------------------------------
print "After REDIM------------------------------------------"
for q=0 to GetArrayElements(test$())
   print "String"+digits$(q,2)+"="+test$(q)
next
sync
waitkey

[/pbcode]
Title: Re: Strange redim behaviour
Post by: monkeybot on July 06, 2014, 09:49:00 AM
sorry being stupid as usual.Thanks for the help.

I have worked out what was wrong in my original code i was using arrays of UDT but when i was re-dimming the array i wasn't declaring it as a type so it wasn't allocating the array and i was getting "array access beyond dimension  sized" error but couldn't expand the array


I had that

redim recorder(recindex+100)

when i should have had

redim recorder(recindex+100) as trecord