Android Question Private variable warning for Boolean in Activity

stanmiller

Active Member
Licensed User
Longtime User
Should this boolean variable declaration and usage cause a warning?

Below is an example where Private bButtonClicked As Boolean is generating a warning. Whereas Private nCountClicks As Int on the line above raises no concern.

b4a_private_var_warning_zpshn1avmog.jpg


If I change the variable to Public as in Public bButtonClicked As Boolean the warning goes away.

Is there something unique about Boolean scoping in B4A?

Using B4A v5.50

Thanks!
 

sorex

Expert
Licensed User
Longtime User
set it public and the warning will probably go away.

it sometimes gives this warnings on plain dim's aswell.
 
Upvote 0

stanmiller

Active Member
Licensed User
Longtime User
Thanks for the replies.

I see now. Luca you were spot on. I was using nCountClicks after all. In the button click I counted clicks whereas with bButtonClicked I simply assigned True.

That the compiler doesn't warn when the scope is set to Public seems to indicate that it won't pass judgment on usage in the current module as there may be an external reference which the compiler can't see during the warning pass.

The takeaway is the warning was valid. I was only assigning a value without any operations on a private variable in the current module.

Doing anything with the variable (a test, assignment to other boolean) will satisfy the linter.

b4a_private_var_warning_sovled_zpsibcvcwdk.jpg


I'm not suggesting one should add a random "if" or an assignment as a workaround. Use, the 'ignore comment trick if you must.

In the app from which this example was taken, I had commented out the test on the bButtonClicked variable and then started getting the warning. Just needed to comment out a few more lines where the variable was declared and assigned.
 
Last edited:
Upvote 0
Top