vCompiler error on null assignment in v1.80 vs v1.70

raytronixsystems

Active Member
Licensed User
Longtime User
Hello:
I have been working on a project with B4A v1.70. Upon installing v1.80 yesterday, I had noticed that I was receiving compiler errors upon the assignment of "" to a string declared in the Process_Globals section of my code. v1.70 compiled a similar program error free. I put together a little test program with comments indicating what and what does not work. The assignment of "" to a string maybe totally wrong but I use it on occasion to put variable in some known state before use. The source code is below . I have also attached a .zip file of the test program and a screen capture of the error message I receive on my end of the world.
I hope this helps.
thx,
Ray


B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   
   'NOTE: the assignment statements below generate a compiler error 

   Dim TestString1 As String : TestString1 = ""         ' declaration and assignment to NULL (comment out and OK)
   
   Dim Teststring2 As String                        ' declaration only
   Teststring2 = ""                              ' assignment to NULL on separate line generates an error 
                                             ' comment this out and OK
   
   Dim TestString4 As String : TestString4 = "abc"         '  this is OK
   
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   Dim TestString5 As String: TestString5 = ""            'this is OK

End Sub

Sub Activity_Create(FirstTime As Boolean)
   '
   Dim TestString6 As String: TestString6 = ""            ' this DOES NOT generate a compiler error
   '
   '
   Teststring2 = ""                              ' this is OK                              ' 
   TestString5= ""                                 ' this is OK
   
End Sub
 

Attachments

  • TestFile.zip
    5.3 KB · Views: 207
  • ErrorScreenCapture.jpg
    38 KB · Views: 247
Last edited:

raytronixsystems

Active Member
Licensed User
Longtime User
Hi Erel!

I had removed the empty strings assignment in my code. From my past experience with programming it was always a good idea to assign a known value to variables upon the starting execution of an Application. Some older compilers did not initialize variables and one was left with whatever was on the stack. Most newer compilers pre-initialize variables to a known value, usually 0 for int's and and other variables and null strings for strings. I assume this is the case with B4A. Am I correct?

thx,
Ray
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…