Android Question Dim variants?

Troberg

Well-Known Member
Licensed User
I've seen two variants of assigning initial value to variables:

B4X:
Dim x as int = 1
Dim x = 1 as int
Are these just two ways of doing the same thing, or is there any difference?
 

Enrique Gonzalez R

Well-Known Member
Licensed User
Being VB an inline programming lenguage, i think the compiler reads the whole line before translating it.

the later is most used for several variables declarations

B4X:
dim x = 1, z = 2 as int
 

Troberg

Well-Known Member
Licensed User
Ah, I never thought of that option. I guess I'm to stuck in VB, where:

Dim a, b as int

means that a is a variant and b is an int.

I just wanted to ask, to make sure that it didn't do anything that just looked the same, such as:

Dim x = 1 as int

would evaluate as:

x casted to object
1 casted to int
x becoming an int as it was assigned 1
 

LucaMs

Expert
Licensed User
I've seen two variants of assigning initial value to variables:

B4X:
Dim x as int = 1
Dim x = 1 as int
Are these just two ways of doing the same thing, or is there any difference?
If you use the second version, could you have:
dim x = a * 10 + 5 / floor(c).... As Int <---- murderess :D

If so, it would be like a thriller: you can discover the murderess (type) only in the final :D

I definitely prefer the first.
 
Top