Muhammad_Awais_Sharif

StringIsDigit Does not work properly

9 posts in this topic




the reason is you using the == operator, which is dedicated to case-sensitive string comparison, for boolean and numeric comparison, not cool.

Share this post


Link to post
Share on other sites

okay thank you :D

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

"1" is a string, and 1 is a number, TRUE is boolean....

you should not compare a string with a number ! The result of a comparison is TRUE or FALSE

(1 = "1") is (should be) FALSE   //EDIT (but NOT in AutoIt because of datatype "variant"?! ) so (1="1") in AutoIt is TRUE

(1 = TRUE) is TRUE

Edited by AndyG

Share this post


Link to post
Share on other sites

okay :D 

problem is that in C++ or java single = operator assign value.

So that's why i was using double equal :D

i got it ty :D 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

More precisely, when you write:

If StringIsDigit($tmp) == True Then

the interpretor understands:

If '1' == 'True' Then

because == forces the conversion of its operands to strings and StringIsDigit returns the integer 0 or 1 (1 in your case), while the string 'True' stays by itself. Since the == comparison is over verbatim (case-insensitive) strings, it clearly fails.

The lazy, simple and robust way to code that condition is:

If StringIsDigit($tmp) Then
Edited by jchd
2 people like this

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

3 hours ago, jchd said:

 

The lazy, simple and robust way to code that condition is:

If StringIsDigit($tmp) Then
 
 
 
 

Indeed!

@Muhammad_Awais_Sharif  ...Use a single equals (=) for comarison, as well as assignment in AutoIt for cases like this...or just say "If X Then" (whenever X is true..."Then" will execute)

(...It took me a few minutes to wrap my head around the 'single equals comparison' as well, so you're in good company!) :)

bloopie

Edited by bloopie
clarification
1 person likes this

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • CT83
      Is it possible to Use Selenium Commands in AutoIt? (I don't mean the other way round)
      By CT83
      I recently discovered Selenium, and in theory it sounds awesome if there were a way to use my existing autoit project's code, in Selenium. is this possible? if not, is there a way to import my au3s to Selenium project without having to rewrite all of the code.?
    • OldGuyWalking
      Dummy Control Not Triggering
      By OldGuyWalking
      I wanted a quick way to identify screen coordinates and created a simple form.  I also wanted to collect the information. Goal was to move the mouse to different locations, hit a key combination and have the program  collect info for that position and write it to a file.
      I couldn't use a button on the form and HotKeys was not recommended (according to some posts I'd read on here).
      I discovered GUIAccelerators but I'm stuck on what triggers the accelerator key.  I've looked at the help file for GUISetAccelerators which references GUICtrlCreateDummy and used the code from both of those.  I'm not getting any errors and everything seems to run okay except when I press Ctrl + [F3] nothing is captured. 
      This is a work in progress so there's extra code that I haven't cleaned up yet.
      Any help would be appreciated. 
      Bill
      ; Displays the Window Handle, Window Text, Control Handle, and mouse position. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=Y #AutoIt3Wrapper_Res_Comment=Show screen coordinates. #AutoIt3Wrapper_Res_Description=Show screen coordinates. #AutoIt3Wrapper_Res_Fileversion=0.0.0.1 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiButton.au3> Global $Debug = 0 Dim $sWinTitle Dim $sWinText Dim $sWinHnd Dim $sWinCtrlRef Dim $sWinCtrlText Dim $sWinCtrlHnd Dim $aPos Dim $mPos Dim $sMousePos Dim $sControlPos Dim $iFile Dim $sFileLogName = @WorkingDir & "\WinfoFile" & @YDAY & ".log" Dim $sReport ; HotKeySet("!{Esc}", "Terminate") ; HotKeySet("!{F3}", "WriteLogFile") #Region ### START Koda GUI section ### Form=F:\AutoIT Apps\Misc Mini Utilities\Coordinates\Coordinates.kxf Global $Coordinates = GUICreate("Coordinates", 340, 225, 1, 750, -1, $WS_EX_TOPMOST) Global $lblXPos = GUICtrlCreateLabel("XPos:", 7, 16, 39, 20, $SS_RIGHT) Global $XPos = GUICtrlCreateLabel("XPos", 95, 16, 36, 20, $SS_RIGHT) Global $lblYPos = GUICtrlCreateLabel("YPos:", 7, 34, 40, 20, $SS_RIGHT) Global $YPos = GUICtrlCreateLabel("YPos", 95, 34, 37, 20, $SS_RIGHT) Global $lblWinTitle = GUICtrlCreateLabel("Window Title:", 7, 61, 84, 20, $SS_RIGHT) Global $WinTitle = GUICtrlCreateLabel("WinTitle", 95, 61, 250, 20) Global $lblHandle = GUICtrlCreateLabel("Handle:", 7, 78, 51, 20, $SS_RIGHT) Global $WinHandle = GUICtrlCreateLabel("Win Handle", 95, 78, 100, 20) Global $lblCtrlID = GUICtrlCreateLabel("Control ID:", 7, 104, 65, 20, $SS_RIGHT) Global $ControlID = GUICtrlCreateLabel("ControlID", 95, 104, 100, 20) Global $lblCtrlText = GUICtrlCreateLabel("Control Text:", 7, 125, 78, 20, $SS_RIGHT) Global $ControlText = GUICtrlCreateLabel("Control Text", 95, 125, 120, 20) Global $lblCtrlPos = GUICtrlCreateLabel("Control Pos:", 7, 144, 76, 20, $SS_RIGHT) Global $ControlPos = GUICtrlCreateLabel("Control Pos", 95, 144, 73, 20) Global $btnExit = GUICtrlCreateButton("Exit", 8, 192, 75, 25) Global $sKey1 = GUICtrlCreateDummy() ; Set GUIAccelerators for the button controlID Ctrl + [F3] Global $aAccelKeys[1][2] = [["^{F3}", $sKey1]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() If $nMsg <> 0 Then ConsoleWrite("GUIGetMsg = " & $nMsg & @CRLF) ConsoleWrite("$sKey1 = " & $sKey1 & @CRLF) EndIf Switch $nMsg Case $GUI_EVENT_CLOSE If $nMsg <> 0 Then ConsoleWrite("Event Close = " & $nMsg & @CRLF) EndIf Exit Case $btnExit If $nMsg <> 0 Then ConsoleWrite("Terminate = " & $nMsg & @CRLF) EndIf Terminate() Case $sKey1 If $nMsg <> 0 Then ConsoleWrite("Report = " & $nMsg & @CRLF) EndIf $iFile = FileOpen($sFileLogName, 1) If $iFile = -1 Then MsgBox(0, "Error", "Unable to Open WinfoFile") EndIf $sWinTitle = WinGetTitle("", "") $sWinText = WinGetText($sWinTitle) $sWinHnd = WinGetHandle($sWinTitle) $sWinCtrlRef = ControlGetFocus($sWinHnd) $sWinCtrlText = ControlGetText($sWinHnd, "", $sWinCtrlRef) $sWinCtrlHnd = ControlGetHandle($sWinHnd, "", $sWinCtrlRef) ControlFocus($sWinHnd, "", $sWinCtrlRef) $aPos = ControlGetPos($sWinCtrlHnd, "", $sWinCtrlRef) $mPos = MouseGetPos() If IsString($sWinText) Then GUICtrlSetData($WinTitle, $sWinTitle) Else GUICtrlSetData($WinTitle, "") EndIf If IsHWnd($sWinHnd) Then GUICtrlSetData($WinHandle, $sWinHnd) Else GUICtrlSetData($WinHandle, "") EndIf GUICtrlSetData($ControlID, $sWinCtrlRef) GUICtrlSetData($ControlText, $sWinCtrlText) If IsArray($aPos) Then GUICtrlSetData($ControlPos, $aPos[0] & "," & $aPos[1]) $sControlPos = $aPos[0] & "," & $aPos[1] Else GUICtrlSetData($ControlPos, "") $sControlPos = "" EndIf If IsArray($mPos) Then GUICtrlSetData($XPos, $mPos[0]) GUICtrlSetData($YPos, $mPos[1]) $sMousePos = $mPos[0] & "," & $mPos[1] Else GUICtrlSetData($XPos, "") GUICtrlSetData($YPos, "") $sMousePos = "" EndIf $sReport = $sReport & "Window Title : " & $sWinTitle & @CRLF $sReport = $sReport & "Window Text : " & $sWinText & @CRLF $sReport = $sReport & "Window Handle : " & $sWinHnd & @CRLF $sReport = $sReport & "Control Refer : " & $sWinCtrlRef & @CRLF $sReport = $sReport & "Control Text : " & $sWinCtrlText & @CRLF $sReport = $sReport & "Control Handle : " & $sWinCtrlHnd & @CRLF $sReport = $sReport & "Control Position : " & $sControlPos & @CRLF $sReport = $sReport & "Mouse Position : " & $sMousePos & @CRLF If $Debug = 1 Then ConsoleWrite($sReport & @CRLF) EndIf FileWriteLine($iFile, "=====================================================") FileWriteLine($iFile, $sReport) FileWriteLine($iFile, "=====================================================") FileClose($iFile) If @error = -1 Then MsgBox(0, "Error", "Failed") Else MsgBox(0, "Report", "Report Completed") EndIf EndSwitch $sWinTitle = WinGetTitle("", "") $sWinText = WinGetText($sWinTitle) $sWinHnd = WinGetHandle($sWinTitle) $sWinCtrlRef = ControlGetFocus($sWinHnd) $sWinCtrlText = ControlGetText($sWinHnd, "", $sWinCtrlRef) $sWinCtrlHnd = ControlGetHandle($sWinHnd, "", $sWinCtrlRef) ControlFocus($sWinHnd, "", $sWinCtrlRef) $aPos = ControlGetPos($sWinCtrlHnd, "", $sWinCtrlRef) $mPos = MouseGetPos() If IsString($sWinText) Then GUICtrlSetData($WinTitle, $sWinTitle) Else GUICtrlSetData($WinTitle, "") EndIf If IsHWnd($sWinHnd) Then GUICtrlSetData($WinHandle, $sWinHnd) Else GUICtrlSetData($WinHandle, "") EndIf GUICtrlSetData($ControlID, $sWinCtrlRef) GUICtrlSetData($ControlText, $sWinCtrlText) If IsArray($aPos) Then GUICtrlSetData($ControlPos, $aPos[0] & "," & $aPos[1]) $sControlPos = $aPos[0] & "," & $aPos[1] Else GUICtrlSetData($ControlPos, "") $sControlPos = "" EndIf If IsArray($mPos) Then GUICtrlSetData($XPos, $mPos[0]) GUICtrlSetData($YPos, $mPos[1]) $sMousePos = $mPos[0] & "," & $mPos[1] Else GUICtrlSetData($XPos, "") GUICtrlSetData($YPos, "") $sMousePos = "" EndIf ;Sleep(500) WEnd Func WriteLogFile() Local $iFile Local $sFileLogName Local $sReport $sFileLogName = @WorkingDir & "\WinfoFile" & @YDAY & ".log" $iFile = FileOpen($sFileLogName, 1) If $iFile = -1 Then MsgBox(0, "Error", "Unable to Open WinfoFile") Return -1 EndIf $sReport = $sReport & "Window Title : " & $sWinTitle & @CRLF $sReport = $sReport & "Window Text : " & $sWinText & @CRLF $sReport = $sReport & "Window Handle : " & $sWinHnd & @CRLF $sReport = $sReport & "Control Refer : " & $sWinCtrlRef & @CRLF $sReport = $sReport & "Control Text : " & $sWinCtrlText & @CRLF $sReport = $sReport & "Control Handle : " & $sWinCtrlHnd & @CRLF $sReport = $sReport & "Control Position : " & $aPos[0] & "," & $aPos[1] & @CRLF $sReport = $sReport & "Mouse Position : " & $mPos[0] & "," & $mPos[1] & @CRLF FileWriteLine($iFile, "=====================================================") FileWriteLine($iFile, $sReport) FileWriteLine($iFile, "=====================================================") FileClose($iFile) MsgBox(0, "Report", "Report Completed") Return EndFunc ;==>WriteLogFile ;====================================================================================== ; Function: Terminate Hot Key = Alt+Esc ;====================================================================================== Func Terminate() ; Hot Key = Alt+Esc GUIDelete($Coordinates) Exit 0 EndFunc ;==>Terminate  
    • newcoding
      Generating Unique Combinations From Fixed Data
      By newcoding
      #include <Excel.au3> #include <File.au3> #include <String.au3> #include <Array.au3> Local $sku_array[0] ;13640 Local $name_array[0] ;13640 Local $sku_string Local $name = "Name Here"; hardcoded, iterate through final list Local $name_sku = "E001" ; hardcoded, iterate through final list For $size = 0 to 3 Step 1 For $mg = 0 to 30 Step 1 For $b = 0 to 1 Step 1 For $menthol = 0 to 4 Step 1 For $vg = 0 to 10 Step 1 $sku_string = String($name_sku & $size & $mg & $b & $menthol & $vg) _ArrayAdd($sku_array, $sku_string) _ArrayAdd($name_array, $name) Next Next Next Next Next ;_ArrayDisplay($name_sku_array, "Array Data:") Local $oExcel = _Excel_Open() Local $sWorkbook = @ScriptDir & "\FURLS_TRLM_Product_Listing_Eliquid.xls" Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook, Default, Default, True) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $sku_array, "B2:B13641") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $name_array, "J2:J13641") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $name_array, "A2:A13641") ;A2 or Column 1 - $name_string ;B2 or Column 2 - $sku_string ;J2 or Column 10 - $name_string So I am trying to generate every unique combination using 1 value from each set and then place each generated value into an array and then write to an excel sheet.
      Edit: Functional Code, F#CK THE FDA!
       
      I have the following data sets:
      Size: 10, 30, 50, 100
      MG: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30  (shortened in the above code for time constraints while testing)
      VG: 0,1,2,3,4,5,6,7,8,9,10
      Boost: 0,1
      Menthol: 0,1,2,3,4
    • afallenhope
      AutoitExe not working on Win 10
      By afallenhope
      Hello all! 
      I am having a bit of trouble and was wondering if anyone may have a workaround for my issue. I made a script that would automatically install a piece of software each night on a Windows 7 Box. Now I have been instructed to do the same with a Windows 10 box since the application is now being tested on Windows 10. 
      The way I did the win7 installation was that I made a script and then made an executable that I call with a batch file along with the Installer. So the process is 
      AutoitMainFile calls batch file, batch file opens Installer, and the automatedinstaller.exe  The automatedinstlaller waits 10-20 seconds to make sure the Installer has been fully loaded.
      When I try to do the same both get loaded but the automatedinstallation.exe does not send commands to the installer. The code does work and nothing from the program we are wanting to install has changed as our Windows 7 runs every night no problem. 
       
      Do I need to make a new automatedinstall script for windows 10? 
      Any advice is appreciated 
      Thanks,
      Richard
    • aa2zz6
      Load program from CMD
      By aa2zz6
      I have a .ini file that holds my path for our mapping software. I can't seem to get the CMD function to read the file path. I removed everything but the file path but it doesn't work.
      [ArcGIS Desktop]
      Path=C:\Users\<user name>\AppData\Local\ESRI\Desktop10.1\Launcher.exe
      Local Const $sFilePath = @ScriptDir & "\Mapping\Path\ " & "Path" & ".ini" Local $sFilewrite = IniWrite($sFilePath, "ArcGIS Desktop", "Path=", "C:\Users\aa2zz6\AppData\Local\ESRI\Desktop10.1\Launcher.exe") Start() Func Start() $MyCommand = $sFilewrite Run(@ComSpec & " /c " & $MyCommand, @SystemDir, @SW_HIDE) EndFunc ;==>Start