Android Question Maximum length of a variable in b4A

beelze69

Active Member
Licensed User
Longtime User
Hi !

Sorry if I sound too basic.

What is the maximum length of a variable in b4A ?

Note: I tried giving this declaration like
Dim strThisWillHoldTheItemDescription as String

- and the Compiler did not give me any error..

I just want to know what is the maximum length that is allowed

Thanks..
 
Last edited:

AnandGupta

Expert
Licensed User
Longtime User
beelze69 is asking for varible name length, not string value length.

Maybe it is in document.

Regards

Anand
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Upvote 0

beelze69

Active Member
Licensed User
Longtime User

Sorry Mahares,
As Anand Gupta pointed out, I want to know what is the maximum length of a variable name that can be declared in b4A.

For example, in case of visual basic (if you see this link : https://docs.microsoft.com/en-us/do...ures/declared-elements/declared-element-names , it appears to be maximum 1023 characters long ..

So what is the limit in b4A

Thanks..
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Don't be so hard, @LucaMs . You just have to realize the possibilities. Imagine having code like this:
B4X:
Sub ShowPrivacyPolicy

    dim Privacy_Policy_This_Privacy_Policy_describes_Our_policies_and_procedures_on_the_collection_use_and_disclosure_of_Your_information_when_You_use_the_Service_and_tells_You_about_Your_privacy_rights_and_how_the_law_protects_You_We_use_Your_Personal_data_to_provide_and_improve_the_Service_By_using_the_Service_You_agree_to_the_collection_and_use_of_information_in_accordance_with_this_Privacy_Policy_The_words_of_which_the_initial_letter_is_capitalized_have_meanings_defined_under_the_following_conditions_The_following_definitions_shall_have_the_same_meaning_regardless_of_whether_they_appear_in_singular_or_in_plural As String = "" ' Obviously shortened here, should be much longer - but that's ok because Java can apparently use unlimited-length identifiers. By the way, why did you scroll all the way over here, have you nothing better to do? :)

    ' Add reflector code to get variable name

    ' Add code to replace underscores with whitespace and whatnot

End Sub

The possibilites!

Sorry for derailing the thread.
 
Upvote 0

beelze69

Active Member
Licensed User
Longtime User
I wonder why you would like to use a variable name that is thousands of characters long.
About thirty are already too many a
I'm not. I think this is a superfluous question, useful only to get rid of a curiosity, since variables with enormously long names will not be used and certainly there will be no problems with names that are 30 or 40 characters long.
I agree with you Lucas. I asked just out of curiosity ... But if it is documented anywhere for b4A then you can guide me to this information..

Thanks
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
On a serious note, I imagine that Erel has set some sort of sane (but high) value for max chars in variable names. It's not really related to Java only, it's also the cross-platform aspect. Imagine a developer using B4A setting variable names that are 1000 chars all over their code. And once they start to move it to B4i, they hit a brick wall because ObjC only allow 32. (I have no idea what the limit is in ObjC, I'm just trying to illustrate a challenge.)

The same reasoning could be applied to what chars are allowed, which probably differ in Java, ObjC and whatever comes after that. In Javascript this is allowed:
B4X:
var ❤ = true;


But I agree, this discussion seems largely academic. It's not like it's possible to test, or anything.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
But if it is documented anywhere for b4A then you can guide me to this information
I don't think it is documented.

Anyway, as far as I know everything is developed with C#, so the limitations are those of that language.
BTW, these:
For example, in case of visual basic (if you see this link : https://docs.microsoft.com/en-us/do...ures/declared-elements/declared-element-names , it appears to be maximum 1023 characters long .
have probably been outdated.

Earlier versions of Visual Basic enforced boundaries in code, such as the length of variable names, the number of variables allowed in modules, and module size. In Visual Basic .NET, these restrictions have been relaxed, giving you greater freedom in writing and arranging your code.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Anyway, as far as I know everything is developed with C#, so the limitations are those of that language.
The IDE is indeed written in C# but it will no doubt process the identifiers in B4X code as strings whose maximum length in .NET is 2^30 (1,073,741,824) characters, since a 2GB limit is imposed by the Microsoft CLR (Common Language Runtime) and each character is coded as UTF16 and so occupies 2 bytes.
 
Last edited:
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
So what is the limit in b4A

I tell you the correct answer.

The limit of B4A variable is 30

If you write variable name longer than 30 then the IDE will beg you not to do so for the benefit of other members of our Forum who will eventually read and use your code which you will share of the marvelous app you will make with easy and fast B4X language.

Regards,

Anand
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Tested a var name 1050 chrs length: it's ok.

BTW...

a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a2345678901234567890123456789012345678901234567890a234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

its name ?
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Is it Elon Musk next kid name?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…