06-18-2010, 12:34 PM
Yesterday I experienced a kind of coding poltergeist with the following simple function:
The program did strange things when printing the string returned by strings(): it printed other strings of the program that had nothing to do, and then froze. The reason was I had supposed the DIMed strings were initialized to an empty string but they are not; it took time to find out. When I added a simple line, everything worked as expected:
I've searched in the forum, but found no reference about this. The DIM wiki page doesn't mention string initialitazion. I just want to confirm this issue before updating the wiki. Are strings not initialized to empty strings because of a technical issue or simply because it's not implemented yet? Is this definitive or will it change in the future?
Code:
function strings(times as ubyte, text as string ) as string
dim i as ubyte
dim result as string
for i = 1 to times
let result = result + text
next i
return result
end function
The program did strange things when printing the string returned by strings(): it printed other strings of the program that had nothing to do, and then froze. The reason was I had supposed the DIMed strings were initialized to an empty string but they are not; it took time to find out. When I added a simple line, everything worked as expected:
Code:
dim result as string
let result = ""
I've searched in the forum, but found no reference about this. The DIM wiki page doesn't mention string initialitazion. I just want to confirm this issue before updating the wiki. Are strings not initialized to empty strings because of a technical issue or simply because it's not implemented yet? Is this definitive or will it change in the future?
Marcos Cruz
http://programandala.net
http://programandala.net