Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/15/2022 in all areas

  1. Subz

    List tags or array

    One other thing that I normally do in these situations is to use an external csv file or text file, which I write using Excel For example: Servers.txt Query "Server1"|Ping "Server1"|Reset "Service1" Query "Server2"|Ping "Server2"|Reset "Service2" Query "Server3"|Ping "Server3"|Reset "Service3" Query "Server4"|Ping "Server4"|Reset "Service4" Query "Server5"|Ping "Server5"|Reset "Service5" Query "Server6"|Ping "Server6"|Reset "Service6" Query "Server7"|Ping "Server7"|Reset "Service7" Query "Server8"|Ping "Server8"|Reset "Service8" Query "Server9"|Ping "Server9"|Reset "Service9" Query "Server10"|Ping "Server10"|Reset "Service10" Then simply read the file into an array and add directly to the listview, this way you can modify the commands without recompiling your script #include <Array.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <File.au3> #include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <GUIListView.au3> #include <GuiRichEdit.au3> #include <WinAPIGdi.au3> #include <WindowsConstants.au3> Local $aServers _FileReadToArray(@ScriptDir & "\Servers.txt", $aServers, 0, "|") If @error Then Exit MsgBox(16, "Error", "Unable to read Servers.txt to an array.") Local $iIndex, $sAction, $sCmd Local $hWnd = GUICreate("Form1", 550, 355) Local $idListview = GUICtrlCreateListView("Query|Ping|Reset", 10, 10, 530, 175) _GUICtrlListView_AddArray($idListview, $aServers) _GUICtrlListView_SetColumnWidth($idListview, 0, 150) _GUICtrlListView_SetColumnWidth($idListview, 1, 150) _GUICtrlListView_SetColumnWidth($idListview, 2, $LVSCW_AUTOSIZE_USEHEADER) Local $idActions = GUICtrlCreateCombo("", 10, 190, 100, 20, $CBS_DROPDOWNLIST) GUICtrlSetData($idActions, "Query|Ping|Reset", "Ping") Local $Button1 = GUICtrlCreateButton("Button1", 115, 189, 100, 23) Local $idEdit = _GUICtrlRichEdit_CreateEx($hWnd, "", 10, 220, 530, 125, Bitor($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) _GUICtrlRichEdit_SetBkColor($idEdit, 0xEEEEEE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $iIndex = Number(_GUICtrlListView_GetSelectedIndices($idListview)) $sAction = GUICtrlRead($idActions) Switch $sAction Case "Query" $sCmd = _GUICtrlListView_GetItemText($idListview, $iIndex, 0) Case "Ping" $sCmd = _GUICtrlListView_GetItemText($idListview, $iIndex, 1) Case "Reset" $sCmd = _GUICtrlListView_GetItemText($idListview, $iIndex, 2) Case Else ContinueLoop EndSwitch Local $iPID = Run(@ComSpec & ' /c ' & $sCmd, "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) _GUICtrlRichEdit_AppendText($idEdit, $sCmd & @CRLF) Local $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop WEnd While 1 $sOutput &= StderrRead($iPID) If @error Then ExitLoop WEnd _GUICtrlRichEdit_AppendText($idEdit, StringStripWS($sOutput,7) & @CRLF) _GUICtrlRichEdit_ScrollToCaret($idEdit) EndSwitch WEnd Func _GUICtrlRichEdit_CreateEx($hWnd, $sText, $iLeft, $iTop, $iWidth = 150, $iHeight = 150, $iStyle = -1, $iExStyle = -1) Local $hCtrl = _GUICtrlRichEdit_Create($hWnd, $sText, $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle) If @error Then Return SetError(@error) Local $hFont = _WinAPI_CreateFont(14, 0, 0, 0, 600, False, False, False, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Consolas") _SendMessage($hCtrl, $WM_SETFONT, $hFont, True) _WinAPI_DeleteObject($hFont) Return $hCtrl EndFunc
    1 point
  2. Subz

    List tags or array

    The other way is to write the cmd output to your gui, for instance: #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <GUIListView.au3> #include <GuiRichEdit.au3> #include <WinAPIGdi.au3> #include <WindowsConstants.au3> Local $iIndex, $sAction, $sCmd Local $hWnd = GUICreate("Form1", 550, 355) Local $idListview = GUICtrlCreateListView("Query|Ping|Reset", 10, 10, 530, 175) GUICtrlCreateListViewItem('server1qry|"' & @ComputerName & '"|service1reset', $idListview) GUICtrlCreateListViewItem("server2qry|server2ping|service2reset", $idListview) Local $idActions = GUICtrlCreateCombo("", 10, 190, 100, 20, $CBS_DROPDOWNLIST) GUICtrlSetData($idActions, "Query|Ping|Reset", "Query") Local $Button1 = GUICtrlCreateButton("Button1", 115, 189, 100, 23) Local $idEdit = _GUICtrlRichEdit_CreateEx($hWnd, "", 10, 220, 530, 125, Bitor($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) _GUICtrlRichEdit_SetBkColor($idEdit, 0xEEEEEE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $iIndex = Number(_GUICtrlListView_GetSelectedIndices($idListview)) $sAction = GUICtrlRead($idActions) Switch $sAction Case "Query" $sCmd = "Query " & _GUICtrlListView_GetItemText($idListview, $iIndex, 0) Case "Ping" $sCmd = "Ping " & _GUICtrlListView_GetItemText($idListview, $iIndex, 1) Case "Reset" $sCmd = "Reset " & _GUICtrlListView_GetItemText($idListview, $iIndex, 2) Case Else ContinueLoop EndSwitch Local $iPID = Run(@ComSpec & ' /c ' & $sCmd, "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) _GUICtrlRichEdit_AppendText($idEdit, $sCmd & @CRLF) Local $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop WEnd While 1 $sOutput &= StderrRead($iPID) If @error Then ExitLoop WEnd _GUICtrlRichEdit_AppendText($idEdit, StringStripWS($sOutput,7) & @CRLF) _GUICtrlRichEdit_ScrollToCaret($idEdit) EndSwitch WEnd Func _GUICtrlRichEdit_CreateEx($hWnd, $sText, $iLeft, $iTop, $iWidth = 150, $iHeight = 150, $iStyle = -1, $iExStyle = -1) Local $hCtrl = _GUICtrlRichEdit_Create($hWnd, $sText, $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle) If @error Then Return SetError(@error) Local $hFont = _WinAPI_CreateFont(14, 0, 0, 0, 600, False, False, False, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Consolas") _SendMessage($hCtrl, $WM_SETFONT, $hFont, True) _WinAPI_DeleteObject($hFont) Return $hCtrl EndFunc
    1 point
  3. Subz

    List tags or array

    Just surround the text with single quotes for example: GUICtrlCreateListViewItem('server1qry|ping "server1"|service1reset', $idListview)
    1 point
  4. The Number function returns a floating point number even without any additional flags (default). The only thing that must be followed is the valid notation for the separator, i.e. dot instead of comma. Example : #include <AutoItConstants.au3> Local $sText $sText = "0,01" ConsoleWrite($sText & @CRLF) ConsoleWrite("-> " & Number($sText) & @CRLF) $sText = "0.01" ConsoleWrite($sText & @CRLF) ConsoleWrite("-> " & Number($sText) & @CRLF) ; replace , with . $sText = "0,01" ConsoleWrite($sText & @CRLF) ConsoleWrite("Replace , with . :" & @CRLF) ConsoleWrite("-> " & Number(StringReplace($sText, ',', '.')) & @CRLF) @EAHuaroto : Use @Zedna 's example with the following modification : ; [...] $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" $sText = StringReplace(StringStripWS($sText, 8), ',', '.')
    1 point
  5. Subz

    List tags or array

    Didn't really understand what you were asking, did you mean something like: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <GUIListView.au3> #include <WindowsConstants.au3> Local $iIndex, $sAction, $sCmd GUICreate("Form1", 332, 267, 192, 124) Local $idListview = GUICtrlCreateListView("Query|Ping|Reset", 10, 10, 250, 175) GUICtrlCreateListViewItem("server1qry|server1ping|service1reset", $idListview) GUICtrlCreateListViewItem("server2qry|server2ping|service2reset", $idListview) Local $idActions = GUICtrlCreateCombo("", 10, 190, 100, 20) GUICtrlSetData($idActions, "Query|Ping|Reset", "Query") Local $Button1 = GUICtrlCreateButton("Button1", 10, 215, 100, 30) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $iIndex = Number(_GUICtrlListView_GetSelectedIndices($idListview)) $sAction = GUICtrlRead($idActions) Switch $sAction Case "Query" $sCmd = "Query " & _GUICtrlListView_GetItemText($idListview, $iIndex, 0) Case "Ping" $sCmd = "Ping " & _GUICtrlListView_GetItemText($idListview, $iIndex, 1) Case "Reset" $sCmd = "Reset " & _GUICtrlListView_GetItemText($idListview, $iIndex, 2) Case Else ContinueLoop EndSwitch WinActivate("Command Prompt") WinWaitActive("Command Prompt") Send($sCmd) EndSwitch WEnd
    1 point
  6. Please change those lines to: ConsoleWrite("-------------------------------------------------" & @CRLF) ConsoleWrite("TextOld =" & $sTextOld & "|" & @CRLF) ConsoleWrite("Text =" & $sText & "|" & @CRLF) .. and show us the output text when it still beeps while not changed.
    1 point
  7. To check the values of $sTextOld and $sText before comparing, include some ConsoleWrite's. The <> operator itself should not be the problem. ; [...] $sTextOld = '' While True If WinActive("[Title:Caja]") Then ; Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" ConsoleWrite("-------------------------------------------------" & @CRLF) ConsoleWrite("TextOld = " & $sTextOld & @CRLF) ConsoleWrite("Text = " & $sText & @CRLF) If $sText <> $sTextOld Then ; Beep if "TOTAL Textbox" value changes Beep(650, 200) ;Beep sound $sTextOld = $sText ConsoleWrite("Beep" & @CRLF) Else ConsoleWrite("no Beep" & @CRLF) EndIf EndIf Sleep(250) WEnd
    1 point
  8. $sTextOld = '' While True If WinActive("[Title:Caja]") Then ; Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" If $sText <> $sTextOld Then ;Beep if "TOTAL Textbox" value changes Beep(650, 200) ;Beep sound $sTextOld = $sText EndIf EndIf Sleep(250) WEnd
    1 point
  9. https://www.autoitscript.com/autoit3/files/beta/autoit/autoit-v3.3.16.1-rc2-setup.zip https://www.autoitscript.com/autoit3/files/beta/autoit/autoit-v3.3.16.1-rc2.zip 3.3.16.1 (xxx, 2022) (Release) AutoIt: - Fixed #3866: REGEXPCLASS broken in 3.3.16.0. - Fixed #3865: Image Control resizing behave as forced $GUI_DOCKWIDTH and $GUI_DOCKHEIGHT. - Fixed #3864: StringRegExp() crash with patterns that cause infinite recursion. - Fixed #3876: Hex Number Arithmetic is incorrect. - Fixed #3869: Subtraction operator before power operation is parsed incorrectly. - Fixed #3879: Dim Map to Array. - Fixed #3875: GUICtrlSetResizing() performance by Reverting #3831: GUICtrlSetPos() $GUI_DOCKHCENTER. - Fixed: missing uninstalling file GUICtrlInternals.au3 since 3.3.15.2. UDFs: - Added: UBound[2] example. - Added: StringRegExp[5] example. - Added: _GUICtrlEdit_SetPadding() function and example. - Added: _WinAPI_RegDeleteKey() can use $hKey as in RegRead(). - Added #3863: _WinAPI_GetCapture(). - Added: Allows _DebugArrayDisplay() to be used in UserFunc. - Added: _ArrayDisplay() and _DebugArrayDisplay() support Min Column width. - Added: _Array2DCreate() support 1D and/or 2D arrays. - Added: _DebugReportVar() display DllStruct content. - Added: _ArrayDisplay() and _DebugArrayDisplay() display {Array[dims]}, {Map[nentry]} and {Object}. - Fixed #3867: Changes in 'SecurityConstants.au3' to avoid name conflict. THIS IS A SCRIPT BREAKING CHANGE - Fixed: Regression in 3.3.15.1, _WinAPI_RegCreateKey() and _WinAPI_RegOpenkey(). - Fixed: Regression of #3835 on _GDIPlus_GraphicsGet*(). - Fixed #3871: _ArrayDisplay() Hang sorted array with Null element. - Fixed: _FTP_FileGetSize() very big size. - Fixed #3872: FTP-Server in AutoIt Help no longer accessible. - Fixed #3877: GUICtrlCreateLabel() overlapping controls doc precision ($WS_CLIPSIBLINGS). - Fixed #3883: _DebugArrayDisplay() produces uncalled console message.
    1 point
×
×
  • Create New...