Hamo Member Licensed User Longtime User May 28, 2014 #1 Does anyone know if this function just checks that all characters of the string are numbers, or does it check to see if the string can be converted to a number that B4A can handle. I mean what about this IsNumber("432432432443243234323254325437893478932489327589327589375893257893275893275932") Would this return true ? Hamo Last edited: May 28, 2014
Does anyone know if this function just checks that all characters of the string are numbers, or does it check to see if the string can be converted to a number that B4A can handle. I mean what about this IsNumber("432432432443243234323254325437893478932489327589327589375893257893275893275932") Would this return true ? Hamo
M Mahares Expert Licensed User Longtime User May 28, 2014 #3 I did test it for you as Steve suggested. By the way, you need IsNumber not isNumeric. Sure enough, it does show that it is a number. Why in the world would you be testing for such a big number. What is the purpose? maybe you can educate us. Code: Copy If IsNumber("432432432443243234323254325437893478932489327589327589375893257893275893275932") Then Msgbox("Yes, I am a big number","") 'it shows that it is a number Else Msgbox("No, I am not a number","") End If Upvote 0
I did test it for you as Steve suggested. By the way, you need IsNumber not isNumeric. Sure enough, it does show that it is a number. Why in the world would you be testing for such a big number. What is the purpose? maybe you can educate us. Code: Copy If IsNumber("432432432443243234323254325437893478932489327589327589375893257893275893275932") Then Msgbox("Yes, I am a big number","") 'it shows that it is a number Else Msgbox("No, I am not a number","") End If
Hamo Member Licensed User Longtime User May 28, 2014 #4 Thanks for the replies, I guess I should have tested it instead of asking here. I have a standalone controller which sends the status of all inputs and various flags as zeros and ones over RS232. This controller also echoes everything it receives from the Android tablet and sometimes the sent messages include garbage. To filter out any garbage and validate the received string, I simply check that the long string received is all numbers. Upvote 0
Thanks for the replies, I guess I should have tested it instead of asking here. I have a standalone controller which sends the status of all inputs and various flags as zeros and ones over RS232. This controller also echoes everything it receives from the Android tablet and sometimes the sent messages include garbage. To filter out any garbage and validate the received string, I simply check that the long string received is all numbers.
Reviewnow Active Member Licensed User Longtime User May 28, 2014 #5 The following sub will work to catch the garbage using regular expressions Log("value Numeric " & isnumeric("432432432443243234323254325437893478932489327589327589375893257893275893275932")) Log("value Numeric " & isnumeric("43243243244x3243234323254325437893478932489327589327589375893257893y275893275932")) Code: Copy Sub isnumeric(input As String) As Boolean Dim MatchInput As Matcher = Regex.Matcher("^[0-9]*$", input) If MatchInput.Find = False Then Return False Else Return True End If End Sub Upvote 0
The following sub will work to catch the garbage using regular expressions Log("value Numeric " & isnumeric("432432432443243234323254325437893478932489327589327589375893257893275893275932")) Log("value Numeric " & isnumeric("43243243244x3243234323254325437893478932489327589327589375893257893y275893275932")) Code: Copy Sub isnumeric(input As String) As Boolean Dim MatchInput As Matcher = Regex.Matcher("^[0-9]*$", input) If MatchInput.Find = False Then Return False Else Return True End If End Sub
LucaMs Expert Licensed User Longtime User May 29, 2014 #6 A little bit off topic but ... I needed something like this: Code: Copy Private Sub IsNumeric(var As Object) As Boolean Return ((var Is Int) OR (var Is Double) OR (var Is Long) OR (var Is Short) OR (var Is Float) OR (var Is Double) OR (var Is Byte)) End Sub I would ask you to inform me if it is not enough or if there is a B4A function I do not know. Upvote 0
A little bit off topic but ... I needed something like this: Code: Copy Private Sub IsNumeric(var As Object) As Boolean Return ((var Is Int) OR (var Is Double) OR (var Is Long) OR (var Is Short) OR (var Is Float) OR (var Is Double) OR (var Is Byte)) End Sub I would ask you to inform me if it is not enough or if there is a B4A function I do not know.
stevel05 Expert Licensed User Longtime User May 29, 2014 #7 How about: Code: Copy Sub IsNumeric(Var As Object) As Boolean Try Var = Var * 1 Return True Catch Return False End Try End Sub Should also work for a numeric value in a string. Last edited: May 29, 2014 Upvote 0
How about: Code: Copy Sub IsNumeric(Var As Object) As Boolean Try Var = Var * 1 Return True Catch Return False End Try End Sub Should also work for a numeric value in a string.
LucaMs Expert Licensed User Longtime User May 29, 2014 #8 stevel05 said: How about: Code: Copy Sub IsNumeric(Var As Object) As Boolean Try Var = Var * 1 Return True Catch Return False End Try End Sub Should also work for a numeric variable in a string. Click to expand... New Snippet? Upvote 0
stevel05 said: How about: Code: Copy Sub IsNumeric(Var As Object) As Boolean Try Var = Var * 1 Return True Catch Return False End Try End Sub Should also work for a numeric variable in a string. Click to expand... New Snippet?
LucaMs Expert Licensed User Longtime User May 29, 2014 #9 Thinking better... I had the need to know if a variable is numeric, not its value. In this case I will use my function, in other cases the function of Steve. Upvote 0
Thinking better... I had the need to know if a variable is numeric, not its value. In this case I will use my function, in other cases the function of Steve.
Cüneyt Gargin Member Licensed User Longtime User Sep 22, 2015 #10 What about IsInteger ? or IsDecimal ? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Sep 24, 2015 #11 Please start a new thread for this question. Upvote 0