Page 1 of 1
Variables CLEAR
Posted: Sun Jan 14, 2007 6:14 pm
by oryaaaaa
I want to learn which variable to have initialized quickly.
Code: Select all
Global a.l, b.b, c.l, d.s, e.f, g.b=20
Start:
; .....
repeat
; .....
if event=restart
VariablesClear a,b,d,e,g
; a=0 : b=0 : d="" : e=0 : g=20
goto Start
endif
forever
It cannot be understood that the variable increases.
Cannot you do simply?
Thanks
Posted: Sun Jan 14, 2007 6:22 pm
by Kaeru Gaman
it's not possible to check this in runtime,
you have to keep track of the used variables by yourself.
but this should not be that difficult,
because i think you only need a handfull of variables really resettet,
most variables you used anywhere dont need it.
what exactly do you need to do?
Posted: Sun Jan 14, 2007 8:01 pm
by oryaaaaa
Do you have the experience of writing a long source code
spending one year or more?
Your opinion is a young person limitation.
variable input temporary or initialize?
a structure variable, 200 variables, do you clear in Big Applications ?
this restart example is one example.
Posted: Sun Jan 14, 2007 8:37 pm
by Derek
Can you explain exactly what it is you're after.
If you need certain variables reset each time your program starts then have an init procedure that is called at the start of the program that resets them each time it is called. Don't know if this is what you are after?
Posted: Sun Jan 14, 2007 11:03 pm
by Kaeru Gaman
oryaaaaa wrote:Your opinion is a young person limitation.
really unpolite. I'm disappointed. I expected much more from a japanese man.
Posted: Sun Jan 14, 2007 11:27 pm
by Nik
I think the concept of an InitFunction could realy do the trick, if the values are constant you could also use a macro which everytime it is applied to the variables sets them to the values you want them to be then you can use this at the start of the program and everywhere you want to set them to those start values again. I still don't understand what you are asking for.
Posted: Mon Jan 15, 2007 9:35 am
by Kaeru Gaman
> I think the concept of an InitFunction could realy do the trick
indeed.
I don't know any programming language where some Clear_All_Variables is implemented,
you always have to write it on your own.
the easiest solution would be to restart the whole application.
Posted: Wed Jan 17, 2007 8:40 pm
by chris319
Microsoft QuickBasic had CLEAR:
The keyword CLEAR was used in QB to erase all variables, close all files, and optionally change the stack size.
Posted: Wed Jan 17, 2007 9:01 pm
by Rescator
If the variables are global, or you are using a global structure or list,
the easiest would be to make a procedure that re-initialize them back to their defaults.
However a VariableReset that reset specified variables to their compiletime values would be nice,
and I guess that is what you are after oryaaaaa?
Posted: Wed Jan 17, 2007 9:47 pm
by merihevonen
So pseudo-cally he needs this:
Code: Select all
MyVariable=12
; MyVariable at compile time, 12
[..]
For Personal_Computer=0 to 100
OverClock(1500Mhz)
MyVariable+1
Next
; MyVariable is now 113
[..]
ResetVariable MyVariable
; MyVariable back to 12
Posted: Thu Jan 18, 2007 12:23 am
by PB
> Microsoft QuickBasic had CLEAR
And the Commodore 64 has CLR which resets all variables to nothing too.
That is, strings become "" and numeric variables become 0 again. I guess
this is what he's asking for, because it resets all variables without needing
to do many loops like this: For a=1 to 1000 : var$(a)="" : Next
Posted: Thu Jan 18, 2007 12:51 am
by chris319
PB wrote:> Microsoft QuickBasic had CLEAR
And the Commodore 64 has CLR which resets all variables to nothing too.
That is, strings become "" and numeric variables become 0 again. I guess
this is what he's asking for, because it resets all variables without needing
to do many loops like this: For a=1 to 1000 : var$(a)="" : Next
Agreed. The CLEAR/CLR statement is not without precedent.
Posted: Thu Jan 18, 2007 1:05 am
by PB
Personally, I don't clear all my arrays before re-using them, I just use a var
to indicate the highest number. So if I had Dim a$(999) and read 250 items
into it, and then wanted to re-read just 50 items into it, I would NOT go and
clear it all first with For a=1 to 999 : a$(a)="" : Next, but rather I would just
read the new 50 items into a$(1) to a$(50) and leave a$(51-999) as they were.
It's probably a waste of memory doing it that way, but does it matter that much?
I guess I could always just do Dim a$(999) again to clear it all first, but I'm not
sure how that affects performance.
Posted: Thu Jan 18, 2007 10:52 am
by Derek
PB wrote:Personally, I don't clear all my arrays before re-using them, I just use a var
to indicate the highest number. So if I had Dim a$(999) and read 250 items
into it, and then wanted to re-read just 50 items into it, I would NOT go and
clear it all first with For a=1 to 999 : a$(a)="" : Next, but rather I would just
read the new 50 items into a$(1) to a$(50) and leave a$(51-999) as they were.
I'm with PB on this one, that's the same way as I do it. Just got to make sure that if you sort arrays you use the optional start and finish and that way your old data doesn't get used.