Trong Posted January 17, 2022 Posted January 17, 2022 (edited) Eg 1: Global $exString = '1100' ConsoleWrite("StringIsDigit(" & $exString & ")=" & StringIsDigit($exString) & @CRLF) ConsoleWrite("IsInt(" & $exString & ")=" & IsInt($exString) & @CRLF) ConsoleWrite("IsNumber(" & $exString & ")=" & IsNumber($exString) & @CRLF) MsgBox(0, "Is Numerical ?","StringIsDigit(" & $exString & ")=" & StringIsDigit($exString) & @CRLF & "IsInt(" & $exString & ")=" & IsInt($exString) & @CRLF & "IsNumber(" & $exString & ")=" & IsNumber($exString)) EG2: if treat variable as number it works but value is not correct because i am checking input data is numeric or string: ;Global $exString = 'xx1100' Global $exString = '1100xx' $exString = Number($exString) ConsoleWrite("StringIsDigit(" & $exString & ")=" & StringIsDigit($exString) & @CRLF) ConsoleWrite("IsInt(" & $exString & ")=" & IsInt($exString) & @CRLF) ConsoleWrite("IsNumber(" & $exString & ")=" & IsNumber($exString) & @CRLF) MsgBox(0, "Is Numerical ?","StringIsDigit(" & $exString & ")=" & StringIsDigit($exString) & @CRLF & "IsInt(" & $exString & ")=" & IsInt($exString) & @CRLF & "IsNumber(" & $exString & ")=" & IsNumber($exString)) Edited January 17, 2022 by VIP ss Regards,
Trong Posted January 17, 2022 Author Posted January 17, 2022 (edited) I found this UDF to be a perfect alternative, but not the intent of my question: Code quote: expandcollapse popupDim $aNumbers[21] $aNumbers[1] = 12345 $aNumbers[2] = "-12345" $aNumbers[3] = +12345.678 $aNumbers[4] = "12345.678" $aNumbers[5] = "One" $aNumbers[6] = "" $aNumbers[7] = "123.One" $aNumbers[8] = 0xFF1165AB $aNumbers[9] = "0x0000Ff" $aNumbers[10] = 0x0000 $aNumbers[11] = "0x0000GG" $aNumbers[12] = 4.395179e+003 $aNumbers[13] = "4.395179e+003" $aNumbers[14] = 4.395179e-003 $aNumbers[15] = "4.395179e-003" $aNumbers[16] = 4e-003 $aNumbers[17] = 4E+003 $aNumbers[18] = "4e-003" $aNumbers[19] = "4E+003" For $i = 1 To 20 Step 1 MsgBox(0,"IsNumeric", '$aNumbers['& $i & '] = ' & $aNumbers[$i] & @CRLF & @CRLF & 'IsNumber() = ' & IsNumber($aNumbers[$i]) & @CRLF & @CRLF & 'IsString() = ' & IsString($aNumbers[$i]) & @CRLF & @CRLF & 'Number() = ' & Number($aNumbers[$i]) & @CRLF & @CRLF & '_IsNumerical() = ' & _IsNumerical($aNumbers[$i]) & @crlf ) Next ; #FUNCTION# ============================================================== ; Name...........: _IsNumerical ; Description ...: Uses a regular expression to check if $vValue can be interpreted as a numeric value ; Syntax.........: _IsNumerical($vValue) ; Parameters ....: $vValue - Value to test if it is numerical ; Return values .: True - If $vValue contains a numeric value ; ...............: False- If $vValue contains a non-numeric value ; Author ........: Bowmore <bowmore at lineone dot net> ; Modified.......: ; Remarks .......: Accepts values in Decimal, Hex and Exponential format. If $vValue is a string then ; the whole string must be numeric value for the function to return True ; Related .......: IsNumber, Number ; Link ..........: ; Example .......: Yes ; =============================================================== Func _IsNumerical($vValue) If IsNumber($vValue) Then Return True If StringRegExp($vValue, "(^[+-]?[0-9]+\.?[0-9]*$|^0x[0-9A-Fa-f]{1,8}$|^[0-9]+\.?[0-9]*[Ee][+-][0-9]+$)") Then Return True Return False EndFunc Edited January 17, 2022 by VIP Regards,
jchd Posted January 17, 2022 Posted January 17, 2022 29 minutes ago, VIP said: if treat variable as number it works but value is not correct because i am checking input data is numeric or string: Your question isn't clear. When and why do you find "value is not correct". Which input formats do you want to accept or filter out? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Trong Posted January 17, 2022 Author Posted January 17, 2022 Sorry for the unclear question. I don't understand what AutoIT's IsNumber function is used for? if the input data type is already numeric then it must be numeric, up I think it has to compare with different data types, specifically here is string. Regards,
junkew Posted January 17, 2022 Posted January 17, 2022 https://www.autoitscript.com/autoit3/docs/functions/IsNumber.htm its not to convert string to a number. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Rurorita Posted January 18, 2022 Posted January 18, 2022 (edited) ;Global $exString = 'xx1100' Global $exString = '1100xx' $exString = Number($exString) MsgBox(0, "", "Var(" & $exString & ") is : " & VarGetType($exString)) The Number func doesnt convert the given var into a Number datatype but into Int32, Int64 or Double. https://www.autoitscript.com/autoit3/docs/functions/Number.htm Also check out https://www.autoitscript.com/autoit3/docs/intro/lang_datatypes.htm Edited January 18, 2022 by Rurorita Amateur Coder - UDF's _storageS-UDF , _netcode-UDF (_netcode_Core-UDF, _netcode_AddonCore-UDF, _netcode_Proxy-UDF, _netcode_Relay-UDF, _netcode_Router-UDF)
Solution AlessandroAvolio Posted January 18, 2022 Solution Posted January 18, 2022 (edited) IsNumber asks whether the content of the variable is meant to represent a numeric quantity. A string is not meant to represent a number but a series of characters. IsNumber(variable) ... -> "variable" can be a number, array, string, pointer, boolean. Edited January 18, 2022 by AlessandroAvolio
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now