Oxygen Basic

Programming => Problems & Solutions => Topic started by: chrisc on April 25, 2018, 10:56:09 AM

Title: Equivalent of PB Reset statement
Post by: chrisc on April 25, 2018, 10:56:09 AM
In PB  the RESET statement is to clear off the memory of strings, numeric variables and arrays

http://www.manmrk.net/tutorials/basic/PowerBASIC/pbcc6/reset_statement.html (http://www.manmrk.net/tutorials/basic/PowerBASIC/pbcc6/reset_statement.html)

what is the equivalent in O2 ?   

But O2  del  command only clear off strings and bstrings  but not for
numeric variables and arrays

so del may not be equivalent to PB's  RESET  ?    is this right?
Title: Re: Equivalent of PB Reset statement
Post by: Charles Pegge on April 26, 2018, 07:48:39 AM
Hi Chris,

del destroys strings and objects.

The most direct solution is to iterate over the array, and set each element to its reset value.

You can use scope to confine the iterator
This will work for non-dynamic variables and arrays

Code: [Select]
macro ResetString(s)
scope
  indexbase 1
  int i
  for i=1 to countof s : s[i]="" : next
end scope
end macro

macro ResetNumber(s)
scope
  indexbase 1
  int i
  for i=1 to countof s : s[i]=0 : next
end scope
end macro