If statement

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

I can't seem to work this 'If statement' out..

what I have is:

B4X:
dim value as string = "4"
If value => "1" & =< "10" Then Return "Number is between 1 and 10""

but I get the following error:
Error description: Object reference not set to an instance of an object.
Occurred on line: 305
If value => "1" & =< "10" Then Return "Number is between 1 and 10"
Word: =

Anyone got any ideas what I am doing wrong?
 

barx

Well-Known Member
Licensed User
Longtime User
An '&' is for concatination. You need the logical AND

Using your example would become

B4X:
If (value => "1") AND (value =< "10") Then Return
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
I think you have these wrong too:

=>

=<

They should be

>= and <=

then i was thinking? perhaps => and =< are functions for casting strings into numbers and then checking for greater than or less than so I did this:

B4X:
Dim value As String = "4"
If value => "1" AND value =< "10" Then 
      ToastMessageShow("Number is between 1 and 10", True)
End If
but I got a syntax error so I'm pretty sure that your test needs to be without quotes as well

This works:
B4X:
Dim value As String = "4"
If value >= 1 AND value <= 10 Then 
     ToastMessageShow("Number is between 1 and 10", True)
End If

No, I was wrong, this also works:
B4X:
Dim value As String = "4"
If value >= "1" AND value <= "10" Then 
     ToastMessageShow("Number is between 1 and 10", True)
End If
so you can leave them in quotes if you want but you have to get the operators correct.
 
Last edited:
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Thanks for your reply's..

I ended up doing it like below and it worked:

B4X:
dim value as string = "4"
If (value > "0") AND (value < "11") Then Return "between 1 and 10"
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Good work IanMc, I do keep missing these little details. Mind it is usually early in a morning when I post. Good job others follow me up lol.

Maybe I should stick to reading in the mornings and leave posting for evenings:sign0013:
 
Upvote 0
Top