Main Menu

Strange redim behaviour

Started by monkeybot, July 05, 2014, 08:09:03 AM

Previous topic - Next topic

monkeybot

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!

PlayBASIC Code: [Select]
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




kevin


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


monkeybot

but what if i want to allocate some more space to my array and fill it up later?

kevin

#3
 what's stopping you from doing that ?



PlayBASIC Code: [Select]
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



monkeybot

#4
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