Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/04/2024 in all areas

  1. ioa747

    StringRegExp Assistance

    Func _MoveSourceAudioData($sFolderPath) If FileExists($sFolderPath & "\wav") Then MsgBox($MB_TOPMOST, "NOTICE!", "Made it to _MoveSourceAudioData...with..." & @CRLF & " ..." & $sFolderPath & "...as the \wav path!") Else MsgBox($MB_TOPMOST, "NOTICE!", "... the \wav folder is missing in" & @CRLF & $sFolderPath) EndIf EndFunc ;==>_MoveSourceAudioData
    1 point
  2. ioa747

    StringRegExp Assistance

    $test = "Type_1" ConsoleWrite("--> " & StringRegExp($test, "Type_[1-4]") & @CRLF) $test = "Type_10" ConsoleWrite("--> " & StringRegExp($test, "Type_[1-4]") & @CRLF) $test = "Type_5" ConsoleWrite("--> " & StringRegExp($test, "Type_[1-4]") & @CRLF) $test = "Type_10" ConsoleWrite("--> " & StringRegExp($test, "Type_[1-4]$") & @CRLF)
    1 point
  3. ioa747

    StringRegExp Assistance

    ; ----------------------------------------------- #include <MsgBoxConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- _BrowseForFolder() ; ----------------------------------------------- Func _BrowseForFolder() While 1 Local $SetName = FileSelectFolder("Please select a valid Type_#\Set_Name folder...", "F:\Audio") ; ----------------------------------------------- Local $_aType = StringSplit($SetName, "\") If $_aType[0] = 4 Then ConsoleWrite("[0]=" & $_aType[0] & @CRLF) ConsoleWrite("[1]=" & $_aType[1] & @CRLF) ConsoleWrite("[2]=" & $_aType[2] & @CRLF) ConsoleWrite("[3]=" & $_aType[3] & @CRLF) ConsoleWrite("[4]=" & $_aType[4] & @CRLF) If $_aType[2] = "Audio" And StringRegExp($_aType[3], "Type_[1-4]") Then Local $_sTypeFolder = $_aType[1] & "\" & $_aType[2] & "\" & $_aType[3] & "\" & $_aType[4] _MoveSourceAudioData($_sTypeFolder) ExitLoop EndIf EndIf ; ----------------------------------------------- MsgBox($MB_TOPMOST, "Notice!", "Invalid [F:\Audio\Type_#\Set_Name] folder selected...") WEnd EndFunc ;==>_BrowseForFolder ; ----------------------------------------------- Func _MoveSourceAudioData($sFolderPath) ConsoleWrite("Inside of _MoveSourceAudioData...with: " & $sFolderPath & "\wav" & @CRLF) EndFunc ;==>_MoveSourceAudioData ; -----------------------------------------------
    1 point
  4. ioa747

    StringRegExp Assistance

    If $_aType[2] = "Audio" And StringRegExp($_aType[3], "Type_[1-4]") Then What does the line mean? if we have the path: F:\Audio\Type_2\AllMe then is $_aType[0] = 4 $_aType[1] = F: $_aType[2] = Audio $_aType[3] = Type_2 $_aType[4] = AllMe If $_aType[2] = "Audio" And $_aType[3] = Type_ and a number from 1 to 4 Then Edit: I also updated this... ...to this... If $_aType[3] = $_aType[3] And StringRegExp($_aType[3], "Type_[1-4]") Then What does the line mean?
    1 point
  5. Hello Argumentum, Thanks for your reply. We want to run test cases against the current release version using MS Access and a version we are working on, which is a migration to SQLite. We had the idea of doing the same scenarios in both versions with the help of AutoIt and then check that both DBs (at least the changed DB tables) are still identical (the MS Access as well as the SQLite). I experimented on this script a little more and it seems I need to give the control clicks some time to complete before doing the next script action. This code starts the application and fills out the add new cow dialogue: ; start Easy Dairy Run("C:\Easy Dairy Automation Systems\Easy Dairy\EasyDairy.exe", "") ; wait for the main form to show up Local $hWnd = WinWaitActive("[CLASS:TfrmEDMain]", "", 2) ; select Cow toolbar button ControlClick($hWnd, "", "[CLASS:TToolBar; INSTANCE:1]", "left", 1, 160, 34) Sleep(50) ; click Add Cow ControlClick($hWnd, "", "[CLASS:TBitBtn; INSTANCE:4]", "left", 1, 54, 15) Sleep(50) ; enter Cow ID Send("99999") Send("{TAB}{TAB}") ; enter Name Send("Test Cow") Send("{TAB}") ; enter Date of Birth Send("010124") Send("{TAB}") ; enter move to Purchase Date Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}") ; enter Purchase Date Send("010524") Send("{TAB}{TAB}") One step at the time. But that is definitely progress. 🙂 Salut, Mathias
    1 point
  6. I started on this before you found your above solution, but never had time to finish. I thought I might as well share it now since I completed it. It’s a bit more complex looking than yours, and can also be broken a few different ways. But it does works for the examples you posted, here it is. #include <StringConstants.au3> ; looking to discern the parameters with RegExp ConsoleWriteDebug(anyFunc(' ''1''', "2""", @ScriptLineNumber) & @CRLF) ; add @ScriptLineNumber ConsoleWriteDebug('This, is'' a string' & @CRLF) ; add @ScriptLineNumber ConsoleWriteDebug("This, is' a string" & @CRLF) ; add @ScriptLineNumber ConsoleWriteDebug('This, is'' a string' & @CRLF, @ScriptLineNumber) ; don't add @ScriptLineNumber ConsoleWriteDebug("This, is' a string" & @CRLF, 88, 1, 2) ; don't add @ScriptLineNumber ;~ ConsoleWriteDebug("This is' a string" & @CRLF, @ScriptLineNumber, 1, 2) ; don't touch Global $sString = "This is' a string" ConsoleWriteDebug($sString & @CRLF, @ScriptLineNumber) ; don't add @ScriptLineNumber ConsoleWriteDebug($sString, @ScriptLineNumber) ; don't add @ScriptLineNumber ConsoleWriteDebug($sString) ; ConsoleWriteDebug(anyFunc(anyFunc(' ''1''', "2""", @ScriptLineNumber), "2""", @ScriptLineNumber) & @CRLF) ; add @ScriptLineNumber ConsoleWriteDebug("10", "2") ; add @ScriptLineNumber ConsoleWriteDebug(-1, "2") ; add @ScriptLineNumber anyFunc(ConsoleWriteDebug("10")) ; add @ScriptLineNumber ;~ ConsoleWriteDebug("This is' a string" & @CRLF, 123, 1, 2) ; don't touch ConsoleWrite(_Add_ScriptLineNumber(FileRead(@ScriptFullPath)) & @CRLF) Func _Add_ScriptLineNumber($sScript, $sFuncName = "ConsoleWriteDebug", $iAddAtParameterNumber = 2) Local $sFixedScript = "", $sLine, $sAddCRLF = @CRLF, $sEmptyAddParam = '""' Local $asScript[0], $asMatch[0] Local Const $iQuoteChar = 34 Local $iParam = 1, $iFuncLevel = 1, $iLine = 0 ConsoleWrite("> =========== BEGINNING ===========" & @CRLF) $asScript = StringSplit($sScript, @CRLF, $STR_ENTIRESPLIT) For $i = 1 To $asScript[0] $sLine = $asScript[$i] $iLine += 1 If ($i = $asScript[0]) Then $sAddCRLF = "" If StringRegExp($sLine, "\Q" & $sFuncName & "\E\(") And Not StringRegExp($sLine, "^(?:[\s]*;|[\s]*\b[fF][uU][nN][cC]\b[ ]|[\s]*\b[eE][nN][dD][fF][uU][nN][cC]\b[ ])") Then ; If function is in the line, and not commented out, and not the Func declaration itself. $iParam = 1 $iFuncLevel = 1 $asMatch = StringRegExp($sLine, ".*\Q" & $sFuncName & "\E\([/s]*", $STR_REGEXPARRAYMATCH) _AddLine($sFixedScript, $sLine, $asMatch, $iLine, $sAddCRLF) Do If ($iParam = $iAddAtParameterNumber) And ($iFuncLevel = 1) Then If StringRegExp($sLine, "^[\d]") Then ; Raw digit in position. $asMatch = StringRegExp($sLine, "^[\d]*", $STR_REGEXPARRAYMATCH) If IsArray($asMatch) And ($iLine <> $asMatch[0]) Then ConsoleWrite("! Line " & $iLine & ", Raw line number is incorrect! Current = " & $asMatch[0] & "; Should be: " & $iLine & @CRLF) ElseIf StringRegExp($sLine, "^\Q@ScriptLineNumber\E") Then ; @ScriptLineNumber in position, do nothing. Else $asMatch = StringRegExp($sLine, "^.+?(?:\)|,)", $STR_REGEXPARRAYMATCH) ; Retrieve data to next comma or end parenthesis. If IsArray($asMatch) Then If StringRegExp($asMatch[0], "[^\d\), " & Chr($iQuoteChar) & "]") Then ; See if parameter contains anything other than digits, quotes and/or spaces. ConsoleWrite("- Line " & $iLine & ", Encountered parameter not containing @ScriptLineNumber and no line number alone:" & @TAB & $sLine & @CRLF) ElseIf StringRegExp($asMatch[0], "[\d]") Then ; See if parameter contains digits. $asMatch = StringRegExp($sLine, "[\d]+", $STR_REGEXPARRAYMATCH) If IsArray($asMatch) And ($iLine <> $asMatch[0]) Then ConsoleWrite("! Line " & $iLine & ", Raw quoted line number is incorrect! Current = " & $asMatch[0] & "; Should be: " & $iLine & @CRLF) ElseIf Not StringRegExp($asMatch[0], "\Q@ScriptLineNumber\E") Then ConsoleWrite("- Line " & $iLine & ", Encountered parameter not containing @ScriptLineNumber:" & @TAB & $sLine & @CRLF) Else ConsoleWrite("- Line " & $iLine & ", Encountered unknown parameter in @ScriptLineNumber position:" & @TAB & $sLine & @CRLF) EndIf EndIf EndIf $sFixedScript &= $sLine & $sAddCRLF ExitLoop EndIf Select Case StringRegExp($sLine, "^[a-zA-Z_]") ; A function as it starts with a letter or underscore. $asMatch = StringRegExp($sLine, "^[\w]+\(?[ ]*", $STR_REGEXPARRAYMATCH) _AddLine($sFixedScript, $sLine, $asMatch, $iLine, $sAddCRLF) $iFuncLevel += 1 ; Show I am in a function in a Parameter, and not the main ConsoleWriteDebug function. Case StringRegExp($sLine, "^[\[\(]") ; A Bracket. $asMatch = StringRegExp($sLine, "^((?:\(.+?\)|\[.+?\])[\s]*)", $STR_REGEXPARRAYMATCH) _AddLine($sFixedScript, $sLine, $asMatch, $iLine, $sAddCRLF) ;~ Case StringRegExp($sLine, "^\$") ; A Variable. ; $asMatch = StringRegExp($sLine, "(^\$[\w\[\]]*[\s]*)", $STR_REGEXPARRAYMATCH) ; can be broken with spaces in array brackets $aArray[ 0] $asMatch = StringRegExp($sLine, "(^\$[\w]*[\s]*)", $STR_REGEXPARRAYMATCH) _AddLine($sFixedScript, $sLine, $asMatch, $iLine, $sAddCRLF) Case StringRegExp($sLine, "^['" & Chr($iQuoteChar) & "]") ; A String. $asMatch = StringRegExp($sLine, "^((?:'.*?'|" & Chr($iQuoteChar) & ".*?" & Chr($iQuoteChar) & ")[\s]*)", $STR_REGEXPARRAYMATCH) _AddLine($sFixedScript, $sLine, $asMatch, $iLine, $sAddCRLF) Case StringRegExp($sLine, "^[@&]") ; A Macro or joiner. $asMatch = StringRegExp($sLine, "^((?:@|&)[\w]*[\s]*)", $STR_REGEXPARRAYMATCH) _AddLine($sFixedScript, $sLine, $asMatch, $iLine, $sAddCRLF) Case StringRegExp($sLine, "^[\-\d]") ; A digit, including a negative. $asMatch = StringRegExp($sLine, "^([\-\d,\.]+[\s]*)", $STR_REGEXPARRAYMATCH) _AddLine($sFixedScript, $sLine, $asMatch, $iLine, $sAddCRLF) Case StringRegExp($sLine, "^\)") ; An ending parenthesis. If ($iFuncLevel = 1) Then ; I'm in the main ConsoleWriteDebug function, determine if I need to add @ScriptLineNumber. Else I'm in a function in a function, just decrease count and process. If ($iParam < ($iAddAtParameterNumber - 1)) Then ; Minus 1 to compensate for @ScriptLineNumber parameter being added. While ($iParam < ($iAddAtParameterNumber - 1)) ; If Parameter to fill in @ScriptLineNumber isn't current one, add blanks $sFixedScript &= ", " & $sEmptyAddParam $iParam += 1 WEnd EndIf ConsoleWrite("- Adding @ScriptLineNumber to line: " & $iLine & @CRLF) $sFixedScript &= ", " & "@ScriptLineNumber" & $sLine & $sAddCRLF ExitLoop Else $iFuncLevel -= 1 $asMatch = StringRegExp($sLine, "^\)[\s]*", $STR_REGEXPARRAYMATCH) _AddLine($sFixedScript, $sLine, $asMatch, $iLine, $sAddCRLF) EndIf Case StringRegExp($sLine, "^,") ; A comma. If ($iFuncLevel = 1) Then $iParam += 1 ; I'm in the main ConsoleWriteDebug function, increase Parameter count. Else I'm in a function in a function, just process. $asMatch = StringRegExp($sLine, "^,[\s]*", $STR_REGEXPARRAYMATCH) _AddLine($sFixedScript, $sLine, $asMatch, $iLine, $sAddCRLF) Case Else ; Unexpected character, trim one off ConsoleWrite("> Encountered an unexpected character, trimming it off: " & StringLeft($sLine, 1) & @CRLF) $sFixedScript &= StringLeft($sLine, 1) ; add the removed character to the script string. $sLine = StringTrimLeft($sLine, 1) $asMatch = StringRegExp($sLine, "^[\s]*", $STR_REGEXPARRAYMATCH) ; Remove any white space. _AddLine($sFixedScript, $sLine, $asMatch, $iLine, $sAddCRLF) EndSelect Until $sLine = "" Else ; Just copy the line. $sFixedScript &= $sLine & $sAddCRLF EndIf Next ConsoleWrite("+ =========== FINISHED ===========" & @CRLF) Return $sFixedScript ; with the added ", @ScriptLineNumber)" where needed EndFunc ;==>_Add_ScriptLineNumber Func _AddLine(ByRef $sFixedScript, ByRef $sLine, ByRef $asArray, $iLine, $sAddCRLF) If Not IsArray($asArray) Then ConsoleWrite("! Identification failed on line: " & $iLine & " Skipping" & @CRLF) $sFixedScript &= $sLine & $sAddCRLF $sLine = "" Else $sFixedScript &= $asArray[0] ; add the beginning of the string to the script string. $sLine = StringTrimLeft($sLine, StringLen($asArray[0])) EndIf EndFunc ;==>_AddLine Func ConsoleWriteDebug($sStr = @CRLF, $iLine = @ScriptLineNumber, $iError = @error, $iExtended = @extended) Local $iRet = ConsoleWrite("@@ Debug (" & $iLine & ") : " & $sStr & (StringRight($sStr, 2) = @CRLF ? "" : @CRLF)) Return SetError($iError, $iExtended, $iRet) ; https://www.autoitscript.com/forum/topic/139260-autoit-snippets/?do=findComment&comment=1538974 EndFunc ;==>ConsoleWriteDebug Func anyFunc($1 = "", $2 = "", $3 = "") Return 'anyFunc' & $1 & $2 & $3 EndFunc ;==>anyFunc Can be broken if: A parameter contains an Array variable with spaces in the element $aArray[ 0] [Modified above script with a fix If ConsoleWriteDebug is commented out, but the comment mark (;) is not the first Character (besides whitespaces). Benefits: Works when ConsoleWriteDebug is nested. Works when functions in ConsoleWriteDebug are nested, i.e. ConsoleWriteDebug(anyFunc(anyFunc( Checks for accuracy raw line numbers. Can place @ScriptLineNumber in different Parameter place, filling in skipped parameters with a predesignated string. Maybe it will give some options.
    1 point
  7. argumentum

    AutoIt Snippets

    Report_GetDriveSpaceFree() Func Report_GetDriveSpaceFree($sDrive = "C:\", $iLine = @ScriptLineNumber) ; how I use it in my project Local $iFree = GetDriveSpaceFree($sDrive), $iTotal = @extended, $iError = @error, $iUsed = $iTotal - $iFree ConsoleWriteDebug(($iFree < 10 ? "!" : "+") & " DriveSpaceFree(" & $sDrive & "): " & $iFree & ' GB free of ' & $iTotal & ' GB total (Used: ' & $iUsed & ' GB)(Error: ' & $iError & ').' & @CRLF, $iLine) EndFunc ;==>Report_GetDriveSpaceFree Func GetDriveSpaceFree($sDrive = "C:\") ; in GB Local $iError = 0, $iFree = DriveSpaceFree($sDrive) $iError += @error ; https://www.autoitscript.com/forum/topic/139260-autoit-snippets/?do=findComment&comment=1538974 Local $iTotal = DriveSpaceTotal($sDrive) $iError += @error Return SetError($iError, Int($iTotal / 1024), Int($iFree / 1024)) EndFunc ;==>GetDriveSpaceFree Func ConsoleWriteDebug($sStr = @CRLF, $iLine = @ScriptLineNumber, $iError = @error, $iExtended = @extended) Local $iRet = ConsoleWrite("@@ Debug (" & $iLine & ") : " & $sStr & (StringRight($sStr, 2) = @CRLF ? "" : @CRLF)) Return SetError($iError, $iExtended, $iRet) ; https://www.autoitscript.com/forum/topic/139260-autoit-snippets/?do=findComment&comment=1538974 EndFunc ;==>ConsoleWriteDebug I needed GetDriveSpaceFree() for a project and ConsoleWriteDebug() is a good idea. ..and, code to add the @ScriptLineNumber to your main script.
    1 point
  8. ioa747

    FileSelectFolder Issues

    I tried it and I couldn't produce the message above no matter what I chose. and that's why I mentioned it I also shrunk the function a bit. Func _BrowseForFolder() While 1 $g_SetName = FileSelectFolder("Please select a valid Type_#\Set_Name folder...", "F:\Audio\") ; "F:\Audio\" ConsoleWrite("$g_SetName=" & $g_SetName & @CRLF) ; ----------------------------------------------- If @error Then MsgBox($MB_TOPMOST, "", "No valid Type_#\Set_Name folder was selected." & @CRLF & "Please select a valid Type_#\Set_Name folder") ContinueLoop EndIf ; ----------------------------------------------- If StringRegExp($g_SetName & "\", "\\Type_[1-4]\\") Then ConsoleWrite("$_aGetType=" & $g_SetName & @CRLF) ;_MoveSourceAudioData($g_SetName) ExitLoop Else MsgBox($MB_TOPMOST, "NOTICE!", "You must to select a valid Type_#\Set_Name folder...") EndIf WEnd EndFunc ;==>_BrowseForFolder ; -----------------------------------------------
    1 point
  9. maniootek, I meant inside the function code that you call when the HotKey is pressed - here is a simple example for which checks which SHIFT key was pressed: #include <MsgBoxConstants.au3> #include <Misc.au3> Local $hDLL = DllOpen("user32.dll") HotKeySet("{ESC}", "_Exit") HotKeySet("+p", "Test") ; Shift-P While 1 Sleep(10) WEnd Func Test() If _IsPressed("A0", $hDLL) Then ; Left SHIFT key MsgBox($MB_SYSTEMMODAL, "Pressed", "LEFT Shift Key") Else ; Must be Right SHIFT key MsgBox($MB_SYSTEMMODAL, "Pressed", "RIGHT Shift Key") EndIf EndFunc ;==>Test Func _Exit() DllClose($hDLL) Exit EndFunc ;==>_ExitClearer now? M23
    1 point
×
×
  • Create New...