You can declare another variable as an 'alias' to an existing variable. Like this:
MyTemp VAR BYTE
MyOtherTemp VAR MyTemp
Why would you want to "undeclare" a variable? Just don't declare it in the first place. You've only got 26 bytes, and 2000 bytes of program storage. Doing something you intend to undo later -- well, there's not a lot of resources available to devote to that sort of thing.
In PBasic this is known as sharing or the use of an "alias". You can't "undeclare" them, but you can declare a new name that's identical functionally to the old name. Since there are only 13 words (also usable as 26 bytes, 52 "nibbles" or 208 individual bits), the alias idea works reasonably well. If you want to reuse a word as two bytes, you can use an alias to the predefined names like B5 or B6 as in "newByte var B5".
Couldn't you just reuse one that you have already declared and no longer need, assuming it was the correct type?
A good example is the variable you must declare as the loop index variable for a FOR/NEXT loop. When the loop is finished, you can set that variable to zero (or any other value up to the maximum type size) and use it for anything you want.
I find that when a variable is only to be used temporarily it’s good to give it such a name…temp, work or something that doesn’t lock it to a specific use. I re-use variables all the time and try to give those variables useful but more general names such as ioByte or ioData. As has been said previously you can always re-use the variable space for something else. Just remember that it won’t be un-initialized (0) at that point so remember that before you use it. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Chris Savage Parallax Tech Support
Comments
MyTemp VAR BYTE
MyOtherTemp VAR MyTemp
Why would you want to "undeclare" a variable? Just don't declare it in the first place. You've only got 26 bytes, and 2000 bytes of program storage. Doing something you intend to undo later -- well, there's not a lot of resources available to devote to that sort of thing.
Couldn't you just reuse one that you have already declared and no longer need, assuming it was the correct type?
A good example is the variable you must declare as the loop index variable for a FOR/NEXT loop. When the loop is finished, you can set that variable to zero (or any other value up to the maximum type size) and use it for anything you want.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
I find that when a variable is only to be used temporarily it’s good to give it such a name…temp, work or something that doesn’t lock it to a specific use. I re-use variables all the time and try to give those variables useful but more general names such as ioByte or ioData. As has been said previously you can always re-use the variable space for something else. Just remember that it won’t be un-initialized (0) at that point so remember that before you use it. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
that should do the job
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
/jon