Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/16/2023 in all areas

  1. If you're on a roll then you're on a roll. Sometimes just completing the task is better than finding the most optimal way. However that being said, you are definitely doing more typing/work than needed for your X1-Y4 pairs. You're providing each corner of a rectangle, even though you only need opposing corners (like top left and bottom right). For example: ; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global $aQuad[][] = [ _ ; Provide coordinates in groups, [Top Left] and [Bottom Right] ["X1", "Y1", "X2", "Y2"], _ [223, 223, 325, 325], _ ;1 [750, 425, 850, 525] _ ;26 ] While 1 Global $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only, 0 - " & UBound($aQuad) - 1, $id + 1) If @error Then Exit $id = Int($sInputBoxAnswer) If $id < 0 Or $id >= UBound($aQuad) Then ConsoleWrite('Invalid number' & @CRLF) ContinueLoop EndIf For $iY = 1 To 3 Step 2 For $iX = 0 To 2 Step 2 MouseMove($aQuad[$id][$iX], $aQuad[$id][$iY], 1) ToolTip($aQuad[$id][$iX] & ", " & $aQuad[$id][$iY], _ $aQuad[$id][$iX] + 20, _ ; offset so we can see the whole tooltip without the mouse in the way $aQuad[$id][$iY], _ 'X' & ($iX + 2) / 2 & ', Y' & ($iY + 1) / 2) Sleep(250) Next Next ;Sleep(350) ToolTip("") WEnd Here, we're only using X1,Y1 and X2,Y2. These points are the Top Left and Bottom Right coordinates, that's all we need to make a rectangle. That'll save you half the typing for coordinates. I also simplified the main loop, and swapped having 4 mouse moves to a couple of loops. If you wanted to keep that part expanded though, here's what that would look like: MouseMove($aQuad[$id][0], $aQuad[$id][1], 1) ToolTip($aQuad[$id][0] & ", " & $aQuad[$id][1], $aQuad[$id][0], $aQuad[$id][1], "Top left") Sleep(250) MouseMove($aQuad[$id][2], $aQuad[$id][1], 1) ToolTip($aQuad[$id][2] & ", " & $aQuad[$id][1], $aQuad[$id][2], $aQuad[$id][1], "Top right") Sleep(250) MouseMove($aQuad[$id][0], $aQuad[$id][3], 1) ToolTip($aQuad[$id][0] & ", " & $aQuad[$id][3], $aQuad[$id][0], $aQuad[$id][3], "Bottom left") Sleep(250) MouseMove($aQuad[$id][2], $aQuad[$id][3], 1) ToolTip($aQuad[$id][2] & ", " & $aQuad[$id][3], $aQuad[$id][2], $aQuad[$id][3], "Bottom right") Sleep(250) The nice part with not having each one as its own thing is that if you want to change a part of it, instead of changing it 4 places it's only 1. Also I noticed that your coordinates are almost a pattern, at least besides the first 1 or 2 points of the pattern. But, would something like this work? ; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global $sInputBoxAnswer Global $aiCoords[2] While 1 $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only", $id + 1) If @error Then Exit $id = Int($sInputBoxAnswer) If $id <= 0 Then ConsoleWrite('Invalid number' & @CRLF) ContinueLoop EndIf For $iY = 0 To 1 $aiCoords[1] = 225 + (100 * (Floor($id / 10) + $iY)) For $iX = 0 To 1 $aiCoords[0] = 250 + (100 * Mod(($id - 1) + $iX, 10)) MouseMove($aiCoords[0], $aiCoords[1], 1) ToolTip(String($aiCoords[0]) & ", " & String($aiCoords[1]), _ $aiCoords[0] + 20, _ ; offset so we can see the whole tooltip without the mouse in the way $aiCoords[1], _ 'X' & ($iX + 1) & ', Y' & ($iY + 1)) Sleep(250) If $iX = $iY Then ConsoleWrite('id: ' & $id & ' X' & $iX & ',Y' & $iY & ': ' & _ String($aiCoords[0]) & ", " & String($aiCoords[1]) & @CRLF) Next Next ;Sleep(350) ToolTip("") WEnd This assumes that you start at 250 instead of 223, and also hit 350 instead of 335. Everything else just seems to be multiples of 100, with 10 points in X before moving to a new Y and repeating. I think I had some other stuff to say, but then took a work meeting and forgot. Let me know if you have questions.
    2 points
  2. Register WM_COMMAND and look for the respective EN_UPDATE call. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <WinAPIConv.au3> Global $hGUI = GUICreate("Example") Global $c_Input = GUICtrlCreateInput("", 10, 10, 200, 20) Global $h_Input = GUICtrlGetHandle($c_Input) Global $c_Button = GUICtrlCreateButton("Test", 10, 50, 200, 20) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $nNotifyCode = _WinAPI_HiWord($wParam) Local $iId = _WinAPI_LoWord($wParam) Local $hCtrl = $lParam If $hCtrl = $h_Input Then If $nNotifyCode = $EN_UPDATE Then ; Sent when an edit control is about to redraw itself. This notification code is sent after the control has formatted the text, but before it displays the text. ; https://learn.microsoft.com/en-us/windows/win32/controls/en-update ConsoleWrite(GUICtrlRead($c_Input) & @CRLF) If GUICtrlRead($c_Input) Then GUICtrlSetState($c_Button, $GUI_DISABLE) Else GUICtrlSetState($c_Button, $GUI_ENABLE) EndIf EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND
    1 point
  3. TheDcoder

    Tester needed ^^

    On my desktop (Xfce), that does happen, but the positions are not permanent, and they spring back to their correct locations once there is enough space available.
    1 point
  4. No it was never questioned but if you see a fix please post Just the example code so others can benefit.
    1 point
  5. I agree with the array approach example: ; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global $aQuad[][] = [ _ ["X", "Y", "W", "H"], _ [100, 100, 200, 200], _ [200, 100, 300, 300], _ [500, 200, 800, 600], _ [300, 300, 1000, 700]] ;~ _ArrayDisplay($aQuad) While 1 Global $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only", $id + 1) Select Case @error = 0 ;OK - The string returned is valid ConsoleWrite("$sInputBoxAnswer=" & $sInputBoxAnswer & @CRLF) $id = Int($sInputBoxAnswer) If $id > 0 And $id <= UBound($aQuad) - 1 Then ConsoleWrite("X=" & $aQuad[$id][0] & ", ") ConsoleWrite("Y=" & $aQuad[$id][1] & ", ") ConsoleWrite("W=" & $aQuad[$id][2] & ", ") ConsoleWrite("H=" & $aQuad[$id][3] & @CRLF) MouseMove($aQuad[$id][0], $aQuad[$id][1]) ToolTip($aQuad[$id][0] & ", " & $aQuad[$id][1], $aQuad[$id][0], $aQuad[$id][1], "MouseMove XY") Sleep(500) MouseMove($aQuad[$id][2], $aQuad[$id][3]) ToolTip($aQuad[$id][2] & ", " & $aQuad[$id][3], $aQuad[$id][2], $aQuad[$id][3], "MouseMoveWH") EndIf Case @error = 1 ;The Cancel button was pushed Exit EndSelect Sleep(3000) ConsoleWrite("" & @CRLF) ToolTip("") WEnd
    1 point
  6. Check in help file Eval() function.
    1 point
  7. Zedna

    MS SQL connection

    Here is more general example showing working with ADO directly without any includes: ; https://www.w3schools.com/asp/ado_intro.asp $objErr = ObjEvent("AutoIt.Error","MyErrFunc") $sServer = 'server1' $sDatabase = 'master' $sUID = 'admin' $sPWD = 'pwd' $DSN = 'DRIVER={SQL Server};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUID &';PWD=' & $sPWD & ';' $oConn = ObjCreate ("ADODB.Connection") $oConn.ConnectionTimeout = 3 ; default is 15 s (must be supported by data provider DSN) $oConn.Open($DSN) If @error Then Exit ; simple select returns 1 value (1 column and 1 row: count() max() TOP 1) $value = $oConn.Execute('select max(col1) from admin.table').Fields(0).Value ConsoleWrite($value & @CRLF) ; simple SQL command INSERT/UPDATE/DELETE without return value $oConn.Execute('update admin.table set col1 = value where key = id') ; general SELECT returns more columns/rows $oRS = ObjCreate ("ADODB.Recordset") $oRS.CursorType = 2 $oRS.LockType = 3 $oRS.Open ('select * from admin.table', $oConn) If @error Then Exit If $oRS.RecordCount Then ; -1 While Not $oRS.EOF $value = $oRS.Fields(0).Value & ' | ' & $oRS.Fields(1).Value ; read only first and second column ConsoleWrite($value & @CRLF) $oRS.MoveNext WEnd EndIf ; execute stored procedure, doesn't support input params and result set Local $rowcount $oConn.Execute('admin.sp_my_procedure', $rowcount, 132) ; adCmdStoredProc=4 + adExecuteNoRecords=0x80 (128) $oRS.Close $oConn.Close MsgBox(64, 'OK', 'Finished') Func MyErrFunc() MsgBox(48, 'COM Error', $objErr.description) SetError(1) EndFunc
    1 point
  8. ...who allowed you two to come out of the chat room ! If you're not on topic, don't spam the thread.
    0 points
×
×
  • Create New...