Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible String issue? (*solved*)
#1
I don't know whether this is expected behaviour or not because of the way Strings are stored, but my high score routine just presented this issue so I thought I'd check before I changed how it works. :-)

If I declare a string outside of a sub I can use it within any sub. If I change the value within the sub then that's fine, unless I make it equal to another String which was declared within that sub. If I do that, the value of the first string becomes blank as soon as the sub ends.

This is kind of hard to explain, so see this example:
Code:
dim testglobal as string

cls
testglobal = "global"
print testglobal
setlocal()
print testglobal
print "done"

sub setlocal
    dim testlocal as string
    testlocal = "local"
    testglobal = testlocal
    print testlocal
    print testglobal
end sub
The output from this is:
Code:
global
local
local

done
During the sub the value of testglobal is "local". Once the sub ends, it becomes blank.

I think I would be better off using a function for this kind of thing rather than a sub, but I just thought it was worth checking whether that behaviour was expected or not.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)