Android Question Initial state of variables

Paulo Rosa

Member
Licensed User
Hi,

Just a small doubt I couldn't find the answer for in B4X documentation:

In VB 6 variables are always initialized when they are declared. For instance, if I declare "Public myflag as boolean", I can be sure that myflag variable will have the initial state of false... and so on for the other types of variables (zero for numeric types, empty string for strings, etc.).

Do B4A, B4J, etc. have the same behaviour? Can I always assume that variables are initialized with their default values, at the moment they are declared?

Regards,
 
This is because Items is an array, not a simple variable of "simple" type.
No, it's because items is a field of a type and the Type object must be initialized
 
Upvote 0
And stop making me hungry!
 
Upvote 0
@LucasMs
#24 that i meant there is a.IsInitialized=False but it can be used.
before i had this idea for you
Code: Copy
Type MyInt(Value As Int)
and thought it raised an error
 
Upvote 0
Try this:

Code: Copy
' Process_Globals
Type MyType (Name As String, Item As Int)


Sub SomeRoutine

   Dim a As MyType
   a.Name = "even more angry"
   a.Item = 2
 
   Log(a.Name & TAB & a.Item)
Just because it works and raised no errors does not mean it's the correct way to do it!
 
Upvote 0
@LucasMs
have a solution :) how about :
DimNotInitialized a as mytype
DimNotInitialized b as int
 
Upvote 0
@LucasMs
he will say no and maybe a compiler option DoNotInitialize is better.
 
Upvote 0
a compiler option DoNotInitialize is better.
upload_2018-9-8_13-45-16.png
 
Upvote 0
The rolling stones were right...
You can't always get what you want!
 
Upvote 0
Back
Top