Just some thoughts of mine and wondering about your opinions...
B4A casts automatically a numerical String to a number so the following code-samples work fine:
also, this variant works:
However, I feel more comfortable by explicitly casting a numerical String to an Int and then checking its Int-value to other numbers (Int), like this:
I just feel that the first and second approaches are not natural while at the same it is great that B4A does the casting for us automatically.
Don't get me wrong - it works.
I don't know what to think and which approach to use from now on... ?
B4A casts automatically a numerical String to a number so the following code-samples work fine:
B4X:
If IsNumber(txtNumInput.Text) Then
If txtNumInput.Text > "9" Or txtNumInput.Text = "0" 'the first values are both casted to Double and then compared, the last check is using ".equals" in java-sources
MsgboxAsync("Sorry but your number must be between 1 and 9. Please try again","Result")
txtNumInput.Text = ""
txtNumInput.RequestFocus
Return
End If
End If
also, this variant works:
B4X:
If IsNumber(txtNumInput.Text) Then
If txtNumInput.Text > 9 Or txtNumInput.Text = 0 Then 'the first value is casted to Double and then compared to 9, the last check is using ".equals" in java-sources
MsgboxAsync("Sorry but your number must be between 1 and 9. Please try again","Result")
txtNumInput.Text = ""
txtNumInput.RequestFocus
Return
End If
End If
However, I feel more comfortable by explicitly casting a numerical String to an Int and then checking its Int-value to other numbers (Int), like this:
B4X:
If IsNumber(txtNumInput.Text) Then
Dim InNum As Int = txtNumInput.Text 'explicit casting to Int in generated Java-sources
If InNum > 9 Or InNum = 0 Then
MsgboxAsync("Sorry but your number must be between 1 and 9. Please try again","Result")
txtNumInput.Text = ""
txtNumInput.RequestFocus
Return
End If
End If
I just feel that the first and second approaches are not natural while at the same it is great that B4A does the casting for us automatically.
Don't get me wrong - it works.
I don't know what to think and which approach to use from now on... ?