Midimaster Active Member Licensed User Oct 12, 2020 #1 Today I did a copy/paste typo and the IDE did not find this bug, but handled the sub call as normal. But the variable was empty afterwards. Lets say I would have this function: B4X: Sub Button1_Click Dim Original As String ="abcdefg" Dim After As String =NonSenseFunction(Original) Log("<" & After & "><" & Original &">") End Sub Sub NonSenseFunction(text As String) As String Return "12345" End Sub this would return: <12345><abcdefg> Click to expand... But if I do this typo: Code: Sub Button1_Click Dim Original As String ="abcdefg" Dim After As String =NonSenseFunction(Original),Original Log("<" & After & "><" & Original &">") End Sub Sub NonSenseFunction(text As String) As String Return "12345" End Sub it returns this: <12345><> Click to expand... Is this a valid code line? Shouldn't the IDE find that error?
Today I did a copy/paste typo and the IDE did not find this bug, but handled the sub call as normal. But the variable was empty afterwards. Lets say I would have this function: B4X: Sub Button1_Click Dim Original As String ="abcdefg" Dim After As String =NonSenseFunction(Original) Log("<" & After & "><" & Original &">") End Sub Sub NonSenseFunction(text As String) As String Return "12345" End Sub this would return: <12345><abcdefg> Click to expand... But if I do this typo: Code: Sub Button1_Click Dim Original As String ="abcdefg" Dim After As String =NonSenseFunction(Original),Original Log("<" & After & "><" & Original &">") End Sub Sub NonSenseFunction(text As String) As String Return "12345" End Sub it returns this: <12345><> Click to expand... Is this a valid code line? Shouldn't the IDE find that error?
agraham Expert Licensed User Longtime User Oct 12, 2020 #2 Yes, it is valid code. You are reDimming Original so it is now empty. You will probably get a missing type warning if you look. Upvote 0
Yes, it is valid code. You are reDimming Original so it is now empty. You will probably get a missing type warning if you look.
stevel05 Expert Licensed User Longtime User Oct 12, 2020 #3 Although you should see a warning in the log, something like: B4X: Variable declaration type is missing. String type will be used. (warning #5) Upvote 0
Although you should see a warning in the log, something like: B4X: Variable declaration type is missing. String type will be used. (warning #5)
DonManfred Expert Licensed User Longtime User Oct 12, 2020 #4 Midimaster said: Dim After As String =NonSenseFunction(Original),Original Click to expand... Upvote 0
Midimaster Active Member Licensed User Oct 12, 2020 #5 Yes afterwards I recognized the warning. (It was there from the beginning, but I did not see. ) But did you expect that already inside the SUB the value was redimmed? Code: Sub NonSenseFunction(text As String) As String log("TEXT=" & text") ' shows an empty string' Return "12345" End Sub Upvote 0
Yes afterwards I recognized the warning. (It was there from the beginning, but I did not see. ) But did you expect that already inside the SUB the value was redimmed? Code: Sub NonSenseFunction(text As String) As String log("TEXT=" & text") ' shows an empty string' Return "12345" End Sub
agraham Expert Licensed User Longtime User Oct 12, 2020 #6 Midimaster said: But did you expect that already inside the SUB the value was redimmed? Click to expand... No, it will be compiled in this order B4X: Dim Original As String = "" Original = "abcdefg" Dim After As String = "" After = NonSenseFunction(Original) Dim Original As String = "" Log("<" & After & "><" & Original &">") Upvote 0
Midimaster said: But did you expect that already inside the SUB the value was redimmed? Click to expand... No, it will be compiled in this order B4X: Dim Original As String = "" Original = "abcdefg" Dim After As String = "" After = NonSenseFunction(Original) Dim Original As String = "" Log("<" & After & "><" & Original &">")