Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:50 18 Sep 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Array create and erase

Author Message
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1116
Posted: 04:57pm 16 Nov 2016
Copy link to clipboard 
Print this post

Hi Folks,

Can anyone offer some advise re the following. I want to create an array, erase it then re-create it with the same name. I can't see any restrictions on this in the manual (but am happy to be told 'not possible').

The test code is

' Test program to create an a string array, erase it and
' then reuse it using the same name

Dim a_array_ptr% 'integer for pointer to array
Dim a_array$(1,1) length 1 ' 2 by 2 one char string array
a_array$(0,0)="A" 'set value into array
Print a_array$(0,0) ' print it out
a_array_ptr% = Peek(VARADDR a_array$()) 'get pointer to array
Print a_array_ptr% 'print it out
Erase a_array$ ' erase the array to free memory
on error skip
a_array_ptr%=Peek(VARADDR b_array$()) ' get pointer to array
if MM.ERRORNO <> 0 then goto exitdoor
' ** the peek should fail as array does not exist
on error skip
a_array_ptr%=Peek(VARADDR a_array$()) ' get pointer to array
if MM.ERRORNO <> 0 then goto exitdoor

' ** the peek should fail also as array was erased ???

Print a_array_ptr% 'print out pointer
Dim a_array$(2,2) length 1 ' re dim array should work ???
' ** this should work as a_array$ was erased and should now
' be available for re-use ??

a_array$(0,0) = "Z" 'assign new value
Print a_array$(0,0) ' and print
error "Not really an error - correct end of program"

exitdoor:
error "Really - an error happend up above!"



The error I get running this code under MMBasic 5.2 on a 64 pin 470 is

>run
A
2684479224
1700012071
[22] Dim a_array$(2,2) length 1 ' re dim array should work ???
Error: Array dimensions
>

Should PEEK to a non-existing variable throw some sort of error?

Should re-DIMing an array variable work after an ERASE if using the same array name?

Thanks,
Doug.

PS. I had hoped to include this functionality into some string/character manipulation routines I am working on.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1116
Posted: 09:16pm 27 Nov 2016
Copy link to clipboard 
Print this post

Read the manual and can not see what I am doing wrong?

Updated the code to be a little more descriptive - don't want to call this a bug but if I do something wrong program wise, shouldn't an error be created?


' Test program to create an a string array, erase it and
' then reuse it using the same name

Dim a_array_ptr% = 0 'integer for pointer to array
Dim b_array_ptr% = 0 'integer for pointer to array which doesn't exist
Dim a_array$(1,1) length 1 ' 2 by 2 one char string array
a_array$(0,0)="A" 'set value into array
Print "This is what we put in the first position of the array ",a_array$(0,0)
a_array_ptr% = Peek(VARADDR a_array$()) 'get pointer to array
Print "Address of array is ",hex$(a_array_ptr%)
Erase a_array$ ' erase the array to free memory
on error skip 'if error in next line, jump over IF ... GOTO
a_array_ptr%=Peek(VARADDR a_array$()) ' get pointer to array
if MM.ERRORNO <> 0 then goto exitdoor
' ** the peek above should fail as array was erased ???
' so we should have jumped to the exitdoor
Print "Address of erased array is ",hex$(a_array_ptr%)

' Now test a non existant array
on error skip 'if error in next line, jump over IF ... GOTO
b_array_ptr%=Peek(VARADDR b_array$()) ' get pointer to array
if MM.ERRORNO <> 0 then goto exitdoor
' ** the peek should fail as array does not exist
' so we should have jumped to the exitdoor
Print "Address of non-existant array !!! ",hex$(b_array_ptr%)
' We should not get here as both Peeks above should have failed
Print "Why am I here?"
Dim a_array$(2,2) length 1 ' re dim array should work ???
' ** this should work as a_array$ was erased and should now
' be available for re-use ??

a_array$(0,0) = "Z" 'assign new value
Print a_array$(0,0) ' and print
error "Not really an error - correct end of program"

exitdoor:
error "Really - an error happend up above!"

... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025