resetting variables
-
Saturday, September 22, 2012 2:16 PM
The title says it all really.
how woulod you reset ALL variables and arrays in a programme ?
thanks ikn advance :)
All Replies
-
Saturday, September 22, 2012 3:05 PMAnswerer
Sorry, there is no automatic way to do this =(
However, for arrays, you can use a for loop and go through each array element and set them to "".
- Marked As Answer by samualsock Saturday, September 22, 2012 3:18 PM
-
Saturday, September 22, 2012 3:19 PM
awwww that sucks :(
however the the arrays is exactly what i was looking for :) thanks
-
Saturday, September 22, 2012 5:32 PMAnswerer
Arrays in SB are nothing more than a big primitive string!
For example:
array[100] = 30 array[-.5] = .25 array["a"] = "txt"
would be equivalent to:
array = "100=30;-.5=.25;a=txt;"
So, if you just wanna erase a variable, be it "normal" or "array", just assign "" to it!
array = ""
P.S.: If an array has more than 1 dimension, like in array[user]["pass"], you can choose to clear just one (or more) of its dimensions:
user = "samualsock" TextWindow.WriteLine(user + ", type in your password:") array[user]["pass"] = TextWindow.Read() array[user] = "" TextWindow.WriteLine("Here's your password:") TextWindow.WriteLine(array[user]["pass"]) If array[user]["pass"] = "" Then TextWindow.WriteLine("Oops! I guess we've lost your password!!!") EndIfIn the example above, the array would scale down from being 2D to become 1D only, and thus, erasing the ["pass"] field, and any others belonging to the 2nd dimension (and beyond)!
Well, at least for that particular user index. If there are other "users" in that array, they would be unaffected! ;-P
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
- Edited by GoToLoopEditor Saturday, September 22, 2012 6:13 PM
-
Sunday, September 23, 2012 2:51 AM
Sorry, there is no automatic way to do this =(
However, for arrays, you can use a for loop and go through each array element and set them to "".
This is actually incorrect. Take for example, an array of numbers:
For i = 1 To 10 num[i] = i EndFor
You can clear all indexes by doing the following:
num = ""
If you was to print num[1] to the screen you would get an empty string.- Edited by Mainchip Sunday, September 23, 2012 10:02 AM
-
Sunday, September 23, 2012 3:14 AMAnswerer
Sorry, I didn't know that! Both methods work though.
Great point!
-
Sunday, September 23, 2012 7:25 AMAnswerer
You can clear all indexes by doing the following:
num = 0
If you was to print num[1] to the screen you would get an empty string.Just a little bit of clarifying...
Assigning 0 is not the same as erasing a variable, since the 0 value needs to be stored in memory!
Even though printing num[1] would result in nothing showing up, since that dimension has been deleted; if you just print num, you'd see result 0 displayed!
However, a num = "" would make sure nothing is stored! ;-P
For i = 1 To 10 num[i] = i EndFor TextWindow.WriteLine(num) num = 0 TextWindow.WriteLine("w/ num = 0 -> " + num) num = "" TextWindow.WriteLine("w/ num = '' -> " + num)
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
- Edited by GoToLoopEditor Sunday, September 23, 2012 7:32 AM
-
Sunday, September 23, 2012 10:02 AM
Hi GoToLoop,
You are correct, I did not test this, it was late, I shall edit my post for future reference to save and confusion.
Thank you for pointing this out.
- Edited by Mainchip Sunday, September 23, 2012 10:02 AM

