B4J Question [BANano] Strange BANano behaviour

John Naylor

Active Member
Licensed User
Longtime User
B4J 9.8
BANano 7.37


I have a BANano custom view which, amongst other things, displays a text box. The value attribute of the text box contains an integer, default of 0

B4X:
<input Type="text" id="fname" name="fname" maxlength="2" size="2" style="border:none; text-align:center" value="0">

I get the BANano element with

B4X:
Dim fn As BANanoElement
fn.Initialize ("#fname")

So far so good. However when I execute the following...

B4X:
Dim x As Int
x = fn.GetAttr ("value")
x=x+1
fn.SetAttr ("value", x)

the value attribute gets set to "01".

Running the same function again I get "011". Changing the input type to "number" made no difference.

So my int value of x is being treated as a string. Is this a bug or am I thinking wrong about this / missed something in the booklet?
 

Star-Dust

Expert
Licensed User
Longtime User
B4J 9.8
BANano 7.37


I have a BANano custom view which, amongst other things, displays a text box. The value attribute of the text box contains an integer, default of 0

B4X:
<input Type="text" id="fname" name="fname" maxlength="2" size="2" style="border:none; text-align:center" value="0">

I get the BANano element with

B4X:
Dim fn As BANanoElement
fn.Initialize ("#fname")

So far so good. However when I execute the following...

B4X:
Dim x As Int
x = fn.GetAttr ("value")
x=x+1
fn.SetAttr ("value", x)

the value attribute gets set to "01".

Running the same function again I get "011". Changing the input type to "number" made no difference.

So my int value of x is being treated as a string. Is this a bug or am I thinking wrong about this / missed something in the booklet?
It is in the casting problem that in JavaScript it is handled differently. It is not strongly typed so to make sure it is handled as a number use the modification below

B4X:
Dim x As Int
x = fn.GetAttr ("value") * 1
x=x+1
fn.SetAttr ("value", x)


 
Last edited:
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
It is in the casting problem that in JavaScript it is handled differently. It is not strongly typed so to make sure it is handled as a number use the modification below

B4X:
Dim x As Int
x = fn.GetAttr ("value") * 1
x=x+1
fn.SetAttr ("value", x)
Also awesome!
 
Upvote 0
Top