
Jibberish
Active Members-
Posts
39 -
Joined
-
Last visited
Everything posted by Jibberish
-
AutoIt and Universal Windows Platform (UWP)
Jibberish replied to Jibberish's topic in AutoIt General Help and Support
Junkew, Thanks for the help. Yes your suggestions sped the test up quite a bit. I will implement your suggestions in my code. I said above that our company is converting a Windows app to UWP, and I want to convert my automated tests to work with the new UWP interface. I'm unable to share our app due to IP, so I built a basic UWP app that simulates part of an app we are converting to UWP. It's just 3 buttons with message boxes responding to clicking any of the main buttons. The package was too big to include, so I included the Visual Studio 2015 source, attached as UITest.7z. Using your tools I am able to click the any of the 3 main buttons (AutoIt source below only clicks the first button) but am unable to get AutoIt to click the OK or Exit buttons that pop up after clicking one of the main buttons. My AutoIt source from SimpleSpy is below. I have not implemented any of your recommendations from above yet, so pardon the messy code. #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP1=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=UITest;controltype:=UIA_WindowControlTypeId;class:=ApplicationFrameWindow", $treescope_children) _UIA_Action($oP1,"setfocus") Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=UITest;controltype:=UIA_WindowControlTypeId;class:=Windows.UI.Core.CoreWindow", $treescope_children) _UIA_Action($oP0,"setfocus") ;~ First find the object in the parent before you can do something ;~$oUIElement=_UIA_getObjectByFindAll("ButtonOne.mainwindow", "title:=Button One;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Button One;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) ;~_UIA_action($oUIElement,"highlight") _UIA_action($oUIElement,"click") ;~~~ ; ^ Works ; ; v Doesn't work ;~~~ Local $oP5=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=UITest;controltype:=UIA_WindowControlTypeId;class:=ApplicationFrameWindow", $treescope_children) _UIA_Action($oP5,"setfocus") Local $oP4=_UIA_getObjectByFindAll($oP5, "Title:=;controltype:=UIA_WindowControlTypeId;class:=Shell_Dialog", $treescope_children) _UIA_Action($oP4,"setfocus") Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=Dialog window;controltype:=UIA_PaneControlTypeId;class:=FlyoutElement", $treescope_children) _UIA_Action($oP3,"setfocus") ;~ First find the object in the parent before you can do something $oUIElement=_UIA_getObjectByFindAll("OK.mainwindow", "title:=OK;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) Local $oUIElement=_UIA_getObjectByFindAll($oP3, "title:=OK;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) _UIA_action($oUIElement,"highlight") _UIA_action($oUIElement,"click") As I said, the first button gets clicked by the app, opening the dialog box. However I can't get the second part to click the OK button. Apologies if I have missed something simple. I renamed the $op variables in the second part in case duplication was causing problems. I also uncommented two lines in the bottom part just in case they were necessary (no joy there...) If you see where I'm going wrong trying to get the OK button to press, please let me know! I truly appreciate your assistance! Jibs UITest.7z -
AutoIt and Universal Windows Platform (UWP)
Jibberish replied to Jibberish's topic in AutoIt General Help and Support
And Finally 1+3=4 #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <constants.au3> #include <WinAPI.au3> #include <debug.au3> #include "CUIAutomation2.au3" #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os Local $oDesktop Local $oUIElement, $oUIElement1, $oUIElement2, $oUIElement3 run("calc.exe") ;~ *** Standard code maintainable *** AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=Calculator;controltype:=UIA_WindowControlTypeId;class:=ApplicationFrameWindow") ;Calculator _UIA_setVar("oP2","Title:=Calculator;controltype:=UIA_WindowControlTypeId;class:=Windows.UI.Core.CoreWindow") ;Calculator _UIA_setVar("oP3","Title:=;controltype:=UIA_GroupControlTypeId;class:=LandmarkTarget") ; $oUIElement=_UIA_getObjectByFindAll("One.mainwindow", "title:=One;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement","Title:=One;controltype:=UIA_ButtonControlTypeId;class:=Button") ;ControlType:=UIA_ButtonControlTypeId;classname:=Button") ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") _UIA_action("oUIElement","highlight") _UIA_action("oUIElement","click") $oUIElement1 =_UIA_getObjectByFindAll("One.mainwindow", "title:=Plus;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement1","Title:=Plus;controltype:=UIA_ButtonControlTypeId;class:=Button") ;ControlType:=UIA_ButtonControlTypeId;classname:=Button") ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") _UIA_action("oUIElement1","highlight") _UIA_action("oUIElement1","click") $oUIElement2 =_UIA_getObjectByFindAll("One.mainwindow", "title:=Three;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement2","Title:=Three;controltype:=UIA_ButtonControlTypeId;class:=Button") ;ControlType:=UIA_ButtonControlTypeId;classname:=Button") ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") _UIA_action("oUIElement2","highlight") _UIA_action("oUIElement2","click") $oUIElement3 =_UIA_getObjectByFindAll("One.mainwindow", "title:=Equals;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement3","Title:=Equals;controltype:=UIA_ButtonControlTypeId;class:=Button") ;ControlType:=UIA_ButtonControlTypeId;classname:=Button") ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") _UIA_action("oUIElement3","highlight") _UIA_action("oUIElement3","click") I learn by example; I hope this helps others. However I have a long way to go! If you have other solutions or ways to shorten this code, please feel free to post examples! -
AutoIt and Universal Windows Platform (UWP)
Jibberish replied to Jibberish's topic in AutoIt General Help and Support
There are two examples from SimpleSpy. The above is from the first example. This is from the 2nd example and starts calc and then apparently clicks the Windows button on my desktop. #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <constants.au3> #include <WinAPI.au3> #include <debug.au3> #include "CUIAutomation2.au3" #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os Local $oDesktop run("calc.exe") AutoItSetOption("MustDeclareVars", 1) Local $oP2=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Calculator;controltype:=UIA_WindowControlTypeId;class:=ApplicationFrameWindow", $treescope_children) _UIA_Action($oP2,"setfocus") Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Calculator;controltype:=UIA_WindowControlTypeId;class:=Windows.UI.Core.CoreWindow", $treescope_children) _UIA_Action($oP1,"setfocus") Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_GroupControlTypeId;class:=LandmarkTarget", $treescope_children) ;~ First find the object in the parent before you can do something ;~$oUIElement=_UIA_getObjectByFindAll("One.mainwindow", "title:=One;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=One;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) ;~_UIA_action($oUIElement,"highlight") _UIA_action($oUIElement,"click") I had deleted the SimpleSpy output so I ran it again. The entire output is attached for anyone who wants to play with it to see if they get the same results as mine. SimpleSpyOutputCalc.au3 -
AutoIt and Universal Windows Platform (UWP)
Jibberish replied to Jibberish's topic in AutoIt General Help and Support
Using SimpleSpy and some of the code from above I got this working: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <constants.au3> #include <WinAPI.au3> #include <debug.au3> #include "CUIAutomation2.au3" #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os Local $oDesktop run("calc.exe") ;~ *** Standard code maintainable *** AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=Calculator;controltype:=UIA_WindowControlTypeId;class:=ApplicationFrameWindow") ;Calculator _UIA_setVar("oP2","Title:=Calculator;controltype:=UIA_WindowControlTypeId;class:=Windows.UI.Core.CoreWindow") ;Calculator _UIA_setVar("oP3","Title:=;controltype:=UIA_GroupControlTypeId;class:=LandmarkTarget") ; ;~ $oUIElement=_UIA_getObjectByFindAll("One.mainwindow", "title:=One;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement","Title:=One;controltype:=UIA_ButtonControlTypeId;class:=Button") ;ControlType:=UIA_ButtonControlTypeId;classname:=Button") ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") _UIA_action("oUIElement","highlight") _UIA_action("oUIElement","click") Takes a while for the button to be pushed... about 8 seconds. I wonder if there is unnecessary code here. Haven't tried anything else yet. I wanted to post the solution I found so others didn't have to (other solutions are welcome however!) -
AutoIt and Universal Windows Platform (UWP)
Jibberish replied to Jibberish's topic in AutoIt General Help and Support
Just noticed I had a leftover line from the original source: $oNotepad=_UIA_getFirstObjectOfElement($oDesktop,"class:=Notepad", $treescope_children) Removed it and still get the error, as I expected. -
AutoIt and Universal Windows Platform (UWP)
Jibberish replied to Jibberish's topic in AutoIt General Help and Support
Thanks @careca, I followed your example with just pressing '1' in calc. However I get an error I don't understand. #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <constants.au3> #include <WinAPI.au3> #include <debug.au3> #include "CUIAutomation2.au3" #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os Local $oDesktop run("calc.exe") $oCalc=_UIA_getFirstObjectOfElement($oDesktop,"class:=CalcFrame", $treescope_children) $oNotepad=_UIA_getFirstObjectOfElement($oDesktop,"class:=Notepad", $treescope_children) $sText="1" $oButton=_UIA_getFirstObjectOfElement($oCalc,"name:=" & $sText, $treescope_subtree) $oInvokeP=_UIA_getpattern($oButton,$UIA_InvokePatternID) $oInvokeP.Invoke >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Scripts\Calc_Push_1_Test.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop "C:\Scripts\Calc_Push_1_Test.au3" (21) : ==> Variable must be of type "Object".: $oInvokeP.Invoke $oInvokeP^ ERROR ->15:22:02 AutoIt3.exe ended.rc:1 The calculator opens but no button push due to the error. Running on Windows 10 RS3. Calc_Push_1_Test.au3 -
Hi, I am having the same problem as Shirdish. I checked Danyfirex's solution and I have that line (line 84 above is line 47 in my code). Still returns blank. It's late so I'm posting my code here in the hopes someone can figure out what I've done wrong, and I can fix it and move on sometime tomorrow! This is the beginning of a search program. I have the search working in another function, I just wanted to add some features. When finished, it will look in the specific Log file for the search parameter. I've generalized the SelectSearchFile func to look in whatever directory this is run in, since that part really doesn't matter at this point. Your help is truly appreciated! #include-once #include <WinAPIFiles.au3> #include <AutoItConstants.au3> #include <Misc.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> #include <FontConstants.au3> #include <MsgBoxConstants.au3> Local $bButton Local $sUserInput Local $idInput Local $sSelectedFile = SelectSearchFile() ;Select a file to search ;Create the GUI with Search Text, checkbox for Whole Words Only & checkbox for Case Sensitive GUICreate("Search Parameters",800,800) GUISetFont(10,$FW_BOLD) GUICtrlCreateLabel("Enter the parameters for the search in the selected Log File ",10,10) GUISetFont(10,$FW_NORMAL) GUICtrlCreateLabel($sSelectedFile,10,30) GUISetFont(10,$FW_BOLD) GUICtrlCreateLabel("Enter the search word or phrase.",10,60) Local $idInput = GUICtrlCreateInput("",10,80) ;Need a way to require input. No blanks allowed GUICtrlSetState(-1,$GUI_SHOW) Local $idBtn = GUICtrlCreateButton("Ok", 380, 750, 40, 20, $BS_DEFPUSHBUTTON) ;GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtn GUIDelete() ExitLoop EndSwitch WEnd $sUserInput = GUICtrlRead($idInput) ;Don't allow a blank entry MsgBox(0,"","User Entry is ",$sUserInput) Func SelectSearchFile() ;Thank you AutoIt Examples! ; Create a constant variable in Local scope of the message to display in FileOpenDialog. Local Const $sMessage = "Select a single file of any type." ; Display an open dialog to select a file. Local $sFileOpenDialog = FileOpenDialog($sMessage, @WorkingDir & "\", "(*.*)", $FD_FILEMUSTEXIST) If @error Then ; Display the error message. MsgBox($MB_SYSTEMMODAL, "", "No file was selected.") ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) Else ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog. $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF) ; Return the selected file. Return $sFileOpenDialog EndIf EndFunc ;==>Example
-
AutoIt and Universal Windows Platform (UWP)
Jibberish replied to Jibberish's topic in AutoIt General Help and Support
I was having trouble finding simplespy, and was asking here where it was. Then I found it. Thanks Jibberish -
I need to read log files into an array to search for errors. However when I display the array I get garbage or "chinese characters". Our developers say they are using UTF-8, but FileGetEncoding says the logs are "2048" or $FO_UTF16_BE_NOBOM (2048) = Use Unicode UTF16 Big Endian (without BOM) from the Encoding codes in FileOpen(). There is an app called Detenc that detects the encoding used by files. You have to guess, but it returns correctly when I set the Encoder for UTF-8. I understand Encoding is not etched in stone, but the first character of the file is a capital B, using HxD Hex Editor. I even have another topic here about running PowerShell to reencode the file so AutoIt will store the file properly in the array - See: So I am trying to figure out why AutoIt thinks my logs are not UTF-8. Here is sample code: #include <array.au3> #include <File.au3> Local $aRetArrayFile _FileReadToArray("C:\Logs\Myplayer1.log", $aRetArrayFile) _ArrayDisplay($aRetArrayFile) I won't post the results as it is illegible, but I did attach a screenshot of the _ArrayDisplay results, and this is the first line of the Log file: BANNER 10/10/2017 15:56:00 ====================================================================== And the Hex from the beginning of the file: 42 41 4E 4E 45 52 20 31 30 2F 31 30 2F 32 30 31 37 20 31 34 3A 33 31 3A 33 35 20 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 0D 0A 42 41 4E 4E 45 52 20 So I don't understand why AutoIt thinks the file is UTF16 BE. If I can get the Powershell script running, I have a workaround. BTW none of my other arrays display as garbage, just the log files. Weird. Rereading my post, what seems to be missing is the question. I guess my question is, does anyone know why these logs are being displayed incorrectly? Cheers Jibs
-
AutoIt and Universal Windows Platform (UWP)
Jibberish replied to Jibberish's topic in AutoIt General Help and Support
Yes I did, and thanks! -
Hi all, I need to read a log file into an array, but the log file is encoded as $FO_UTF16_BE_NOBOM (2048) = Use Unicode UTF16 Big Endian (without BOM) per FileGetEncoding (it returns 2048). I have searched how to convert these log files to UTF-8 and finally found a Powershell command. Since then I have been racking my brain trying to get the function to work. The command itself works from a Powerscript prompt: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content C:\Logs\Myplayer_10-10-17-02-31.log | Set-Content -Encoding utf8 C:\Logs\Myplayer1.log This is my sandbox; #include <array.au3> #include <File.au3> Local $aArrayLogFile Local $sLogDir = "C:\Logs\" Local $sLogFile = "Myplayer_10-10-17-02-31.log" Local $sConvertedLog = "ConvertedLog.log" Local $sLogDirFile = $sLogDir&$sLogFile RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir) _FileReadToArray($sLogDirFile, $aArrayLogFile) _ArrayDisplay($aArrayLogFile) Also tried RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir) and ShellExecuteWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"," -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir) Tried without -Command and a bunch of other parameters that were sprinkled throughout the internet from people trying to get this to work. Thanks Jibs
- 2 replies
-
- powershell
- encoding
-
(and 1 more)
Tagged with:
-
Wow! This must be tough! I usually get responses fairly quickly!
- 3 replies
-
- guictrlcreateinput
- array
-
(and 1 more)
Tagged with:
-
I am having difficulties getting updated results from GUICtrlCreateInput. I wrote a small script to demonstrate what I am trying to do. This script reads a text file into an array and displays the Name and Number from the text file. The user can check a name and change the number, and the results are displayed in _ArrayDisplay. Only the Checked names are displayed in their original position. This is necessary for future plumbing. The problem with this script is the original number is returned, not the changed number. I cannot figure out how to get the updated number to be displayed. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; This script reads a text file into an array and displays the Name and Number from the text file. ; The user can check a name and change the number, and the results are displayed in _ArrayDisplay. ; Only the Checked names are displayed in their original position. This is necessary for future ; plumbing. ; ; The problem with this script is the original number is returned, not the changed number. I cannot ; figure out how to get the updated number to be displayed. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include-once #include <MsgBoxConstants.au3> #include <array.au3> #include <Date.au3> #include <WinAPIFiles.au3> #include <AutoItConstants.au3> #include <Misc.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Local $iMax = 6 ;Default number of Videos - 1 for the array counter Dim $aTextFile[$iMax][2] ; [start with 5 entries][Name, Number] Don't get confused! [Row][Column] Local $i = 0 Local $iLeft = 30 Local $iTop = 30 Local $sName Local $sNumber Local $aArray Local $iMaxCol = 5 Local $iRow = 0 Local $iCol = 0 Local $aNumberCount[$iMaxCol][2] $aArray1 = ReadFile() $aNamesNumbers = DisplayNames($aArray1) _ArrayDisplay($aNamesNumbers) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; ReadFile() places the contents of the NameNumber.txt file in an array ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func ReadFile() Local $sFileData = @ScriptDir & "\NameNumber.txt" Local $iStrReturn = 0 Local $aArrayFile Local $aTextFile[$iMaxCol][2] Local $aName Local $sCheckBox1 Const $iL = 10 ; Count from Left for GUI so all buttons line up Local $sFill Local $iA = 0, $iN = 0 ; Put the Names into an Array _FileReadToArray($sFileData, $aArrayFile) For $iA = 0 To $aArrayFile[0] ; Step through the array looking for Names If StringInStr($aArrayFile[$iA], "Name:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next $iCol = 1 $iRow = 0 $sFill = "" For $iA = 1 To $aArrayFile[0] ; Step through the array looking for Numbers If StringInStr($aArrayFile[$iA], "Number:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next Return $aTextFile EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the Name and Number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayNames($aArray1) Local $aName[$iMax] Local $aNumbers[$iMax] $iMMCount = UBound($aArray1) $iMMCount -=1 Local $iWidth = 300 Local $iLength = 300;$iMMCount * 30 GUISetFont(12) $hGUI = GUICreate("Edit / Update Number Test", $iWidth, $iLength, -1, -1) GUICtrlCreateLabel(" Name Number",1,5) ;$iTop += 30 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display Name with a Checkbox. Only Checked Names should be saved. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For $i = 0 to $iMMCount Step 1 $sNameText = $aArray1[$i][0] $iNameLength = StringLen($sNameText) $aName[$i] = GUICtrlCreateCheckbox($sNameText,$iLeft, $iTop) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the number from the text file below each name. Allow the user to change the number and display the ; new number. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iLeft = 60 GUIStartGroup() $iTop = 28 For $i = 0 to $iMMCount Step 1 $sNumberText = $aArray1[$i][1] $aNumberCount[$i][1] = $sNumberText $aNumberCount[$i][0] = GUICtrlCreateInput($sNumberText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aNumberCount[$i][0],200) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read the checked names and (possibly updated) number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iMMCount = UBound($aNumberCount) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedNameNumber[$iMMCount][2] $iLeft = 30 Local $idCloseGUI = GUICtrlCreateButton("Close",$iLeft, $iTop) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aName[$i]) Case $GUI_CHECKED $aCheckedNameNumber[$i][0] = $aArray1[$i][0] Case $GUI_UNCHECKED EndSwitch Switch GUICtrlRead($aNumberCount[$i][0]) Case $aCheckedNameNumber[$i][1] = GUICtrlRead($aNumberCount[$i][1]) EndSwitch Next ExitLoop EndSwitch WEnd For $i = 0 to $iMMNewCount step 1 GUICtrlRead($aNumberCount[$i][0]) If $aCheckedNameNumber[$i][0] <> "" Then $aCheckedNameNumber[$i][1] = $aNumberCount[$i][1] EndIf Next GUIDelete($hGUI) Return $aCheckedNameNumber EndFunc This is the text file I am reading. If you want to try this out put the NameNumber.txt file in your script directory. It's attached to the post. * This is a dummy file with a Name and Number * The only purpose of this file is to read the updated Number. Name:Taggart Number:916 Name:Mongo Number:90 Name:Hedley Lamarr Number:22 Name:Bart Number:9999 Name:The Waco Kid Number:2244 If I change the number, the original number is displayed at the end, not the updated/modified number. I need the modified number to be displayed. Thanks in advance for any assistance! Jibberish NameNumber.txt
- 3 replies
-
- guictrlcreateinput
- array
-
(and 1 more)
Tagged with:
-
GUICtrlCreateEdit with Arrays in Case Statements
Jibberish replied to Jibberish's topic in AutoIt GUI Help and Support
OK I created a new script that can be run so you can see my problem. I need to display the updated number in the final display. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; This script reads a text file into an array and displays the Name and Number from the text file. ; The user can check a name and change the number, and the results are displayed in _ArrayDisplay. ; Only the Checked names are displayed in their original position. This is necessary for future ; plumbing. ; ; The problem with this script is the original number is returned, not the changed number. I cannot ; figure out how to get the updated number to be displayed. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include-once #include <MsgBoxConstants.au3> #include <array.au3> #include <Date.au3> #include <WinAPIFiles.au3> #include <AutoItConstants.au3> #include <Misc.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Local $iMax = 6 ;Default number of Videos - 1 for the array counter Dim $aTextFile[$iMax][2] ; [start with 5 entries][Name, Number] Don't get confused! [Row][Column] Local $i = 0 Local $iLeft = 30 Local $iTop = 30 Local $sName Local $sNumber Local $aArray Local $iMaxCol = 5 Local $iRow = 0 Local $iCol = 0 Local $aNumberCount[$iMaxCol][2] $aArray1 = ReadFile() $aNamesNumbers = DisplayNames($aArray1) _ArrayDisplay($aNamesNumbers) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; ReadFile() places the contents of the NameNumber.txt file in an array ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func ReadFile() Local $sFileData = @ScriptDir & "\NameNumber.txt" Local $iStrReturn = 0 Local $aArrayFile Local $aTextFile[$iMaxCol][2] Local $aName Local $sCheckBox1 Const $iL = 10 ; Count from Left for GUI so all buttons line up Local $sFill Local $iA = 0, $iN = 0 ; Put the Names into an Array _FileReadToArray($sFileData, $aArrayFile) For $iA = 0 To $aArrayFile[0] ; Step through the array looking for Names If StringInStr($aArrayFile[$iA], "Name:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next $iCol = 1 $iRow = 0 $sFill = "" For $iA = 1 To $aArrayFile[0] ; Step through the array looking for Numbers If StringInStr($aArrayFile[$iA], "Number:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next Return $aTextFile EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the Name and Number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayNames($aArray1) Local $aName[$iMax] Local $aNumbers[$iMax] $iMMCount = UBound($aArray1) $iMMCount -=1 Local $iWidth = 300 Local $iLength = 300;$iMMCount * 30 GUISetFont(12) $hGUI = GUICreate("Edit / Update Number Test", $iWidth, $iLength, -1, -1) GUICtrlCreateLabel(" Name Number",1,5) ;$iTop += 30 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display Name with a Checkbox. Only Checked Names should be saved. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For $i = 0 to $iMMCount Step 1 $sNameText = $aArray1[$i][0] $iNameLength = StringLen($sNameText) $aName[$i] = GUICtrlCreateCheckbox($sNameText,$iLeft, $iTop) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the number from the text file below each name. Allow the user to change the number and display the ; new number. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iLeft = 60 GUIStartGroup() $iTop = 28 For $i = 0 to $iMMCount Step 1 $sNumberText = $aArray1[$i][1] $aNumberCount[$i][1] = $sNumberText $aNumberCount[$i][0] = GUICtrlCreateInput($sNumberText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aNumberCount[$i][0],200) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read the checked names and (possibly updated) number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iMMCount = UBound($aNumberCount) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedNameNumber[$iMMCount][2] $iLeft = 30 Local $idCloseGUI = GUICtrlCreateButton("Close",$iLeft, $iTop) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aName[$i]) Case $GUI_CHECKED $aCheckedNameNumber[$i][0] = $aArray1[$i][0] Case $GUI_UNCHECKED EndSwitch Switch GUICtrlRead($aNumberCount[$i][0]) Case $aCheckedNameNumber[$i][1] = GUICtrlRead($aNumberCount[$i][1]) EndSwitch Next ExitLoop EndSwitch WEnd For $i = 0 to $iMMNewCount step 1 GUICtrlRead($aNumberCount[$i][0]) If $aCheckedNameNumber[$i][0] <> "" Then $aCheckedNameNumber[$i][1] = $aNumberCount[$i][1] EndIf Next GUIDelete($hGUI) Return $aCheckedNameNumber EndFunc The text file that is read is here: * This is a dummy file with Somebody.name and Number * The only purpose of this file is to read the updated Number. Name:Taggart Number:916 Name:Mongo Number:90 Name:Hedley Lamarr Number:22 Name:Bart Number:9999 Name:The Waco Kid Number:2244 Copy the text above into NameNumber.txt and store the file in your script directory. Run the script, Check a Checkbox and change that associated number and continue. You will see the original number is displayed, not the one you just modified. How do I get the updated data from the GUI?- 2 replies
-
- guictrlcreateedit
- arrays in a case statement
-
(and 2 more)
Tagged with:
-
I am working on a Video Player Test Script. I am reading a text file into a 3d array to be displayed in a GUI. Array Content: [x][0]FileName.mp4 [x][1]UsageCount -> Up to a 4 digit number [x][2]EnableUsageCount (True/False) In the GUI the user can check the filename box, edit the number of usages and check EnableUsageCount to turn on the UsageCount control using the UsageCount number for the maximum number of plays. To make this easier to deal with I have removed the EnableUsageCount section, and am just concentrating on getting a method to put the edited (or unchanged) UsageCount in the array. Currently nothing is read into the array, due to my using the wrong method in the Case statement. Here are code snippets of what I am trying to do: ; Snippets from script ; I read the text file at the bottom and put the .mp4 filenames in $aManifest[x][0] and UsageCount in $aManifest[x][1] ; Then I create a GUI to display the .mp4 filenames with checkboxes and the UsageCount to the right. UsageCount is editable by the user. ; If the filename is checked, I want to read the filename into $aCheckedVideos[x][0] and the updated UsageCount in $aCheckedVideos[x][1] ; The GUICtrlRead($aVideoName[$i]) with Case $GUI_CHECKED & UNCHECKED works for the checkboxes ; This section puts the filenames in the GUI with a checkbox For $i = 0 to $iMMCount Step 1 $sMP4Text = $aManifest[$i][0] $iMP4Length = StringLen($sMP4Text) $aVideoName[$i] = GUICtrlCreateCheckbox($sMP4Text,$iLeft, $iTop) $iTop += 30 Next ; This section reads numbers from the Manifest array, and I want to be able to change the number and have them saved. ; So the Case $GUI_CHECKED & UNCHECKED won't work here, and I can't figure out what I should be doing here. For $i = 0 to $iMMCount Step 1 $sUsageText = $aManifest[$i][1] $aUsageCount[$i] = GUICtrlCreateInput($sUsageText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aUsageCount[$i],200) $iTop += 30 Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aVideoName[$i]) Case $GUI_CHECKED $aCheckedVideos[$i][0] = $aManifest[$i][0] ; If checked, I put the results into a two D array Case $GUI_UNCHECKED ; where Video Name is $aCheckedVideos[x][0] EndSwitch Switch GUICtrlRead($aUsageCounter[$i]) Case $GUI_CHECKED $aCheckedVideos[$i][1] = $aUsageCount[$i] ;I want to put the text (numbers) in $aCheckedVideos[x][1] Case $GUI_UNCHECKED ;but what is returned is blank, probably due to EndSwitch ; $GUI_CHECKED being the wrong thing. Next ExitLoop EndSwitch WEnd ;The txt file I'm reading has the following: ;~ /** Title #1: Big Buck Bunny 1080p **/ ;~ "Name": "Big Buck Bunny", ;~ "URI": "..\\MediaFiles\\bbb_1080_60s.mp4", ;~ "UsageCount": 9999, ;~ "URI": "..\\MediaFiles\\bbb_1080_60s_enc1.mp4", ;~ "UsageCount": 45, ;~ "URI": "..\\MediaFiles\\bbb_1080_60s_enc1.mp4", ;~ "UsageCount": 2, ;~ /** Title #2: Tears of Steel 4K **/ ;~ "Name": "Tears of Steel 4K", ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC.mp4", ;~ "UsageCount": 9876, ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC_enc2.mp4", ;~ "UsageCount": 0, ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC_enc2.mp4", ;~ "UsageCount": 5, I am certain that the section Switch GUICtrlRead($aUsageCounter[$i]) Case $GUI_CHECKED $aCheckedVideos[$i][1] = $aUsageCount[$i] ;I want to put the text (numbers) in $aCheckedVideos[x][1] Case $GUI_UNCHECKED ;but what is returned is blank, probably due to EndSwitch ; $GUI_CHECKED being the wrong thing. is wrong, and this is what I am looking for help with. Instead of $GUI_CHECKED what should I be looking for? The worst part of this is I had this working late last night, and then lost my changes and cannot for the life of me remember how I had this working. Help is truly appreciated! Jibberish
- 2 replies
-
- guictrlcreateedit
- arrays in a case statement
-
(and 2 more)
Tagged with:
-
Hello, I have used this forum to get help many times. I thought it was time to (hopefully) help others. I created a script that reads a text file with a list of videos, displays the videos in a GUI with checkboxes next to the names, and displays the selected videos. This will become a part of a larger script I am creating to test a video player. The tough part for me was creating the GUI and Dynamic list of videos. I had a lot of trouble finding samples to help me, but finally found one written by Melba23. The link is in the code, so he gets credit for helping! I also have not used arrays much and they are very picky about looping through the arrays without getting the dreaded error " Array variable has incorrect number of subscripts or subscript dimension range exceeded." However diligence paid off! To run this code, take the video names commented below and create a videos.txt file in your script execution directory. You can put however many video names in this list. Thus the dynamic features of the code. Cheers! Jibberish #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Local $sMediaFile = @ScriptDir & "\videos.txt" ;~ Videos in videos.txt are: ;~ bbb_1080_60s.mp4 ;~ bbb_1080_60s_1.mp4 ;~ bbb_1080_60s_2.mp4 ;~ tos_4K_60s_HEVC.mp4 ;~ tos_4K_60s_HEVC_1.mp4 ;~ tos_4K_60s_HEVC_2.mp4 ;~ ;~ Additional videos can be added to this list. The functions are Dynamic. Dim $aMediaManifest Local $aArrayFile Local $aVideos Local $sVideoName Local $i ; MAIN ; Put the Video File Names into an Array _FileReadToArray($sMediaFile, $aArrayFile) Local $iVideoCount = UBound($aArrayFile) -1 ; Get the number of videos - 1 to prevent errors _ArrayDelete($aArrayFile, 0) ;Counter just gets in the way ; Move backwards through the array deleting the blank lines For $i = $iVideoCount - 1 To 0 Step -1 If $aArrayFile[$i] = "" Then _ArrayDelete($aArrayFile, $i) EndIf Next $aVideos = DisplayVideos($aArrayFile) $iVideoCount = UBound($aArrayFile) -1 _ArrayDisplay($aVideos) ; Display the checked videos ;~ End of MAIN ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; GUI to display Videos in checkboxes ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayVideos($aArrayFile) Local $iTop = -1 Local $iLeft = -1 Local $iWidth Local $iHeight = $iVideoCount * 30 Local $iL = 10 Local $iT = 10 Local $iRow = 0 Local $aVideo Local $iA = 0, $iB = 0 Local $sFill = "" $iMMCount = UBound($aArrayFile) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedVideos[$iMMCount] ; Put the Video File Names into an Array $hGUI = GUICreate("Video Checkbox", $iLeft, $iTop, $iWidth, $iHeight) GUICtrlCreateLabel("Videos", 180, $iT) $iT = $iT + 30 ; This is a great example of using arrays to create GUI check boxes or radio buttons For $i = 0 To $iMMNewCount Step 1 $sMP4Text = $aArrayFile[$i] $aGUICheckbox[$i] = GUICtrlCreateCheckbox($sMP4Text, 30, $iT) $iT += 30 Next $idClose1 = GUICtrlCreateButton("Start", $iL, $iT) GUISetState(@SW_SHOW) ; This section reads the checkboxes and puts the video names in an array in their original position ; in case this is important (as it is to me) ; This was the toughest part to code, and I found no samples online until I saw Melba23's sample here: ; https://www.autoitscript.com/forum/topic/119843-dynamic-gui-problem/#comment-832672 ; I got this working with only a little modification. THANK YOU MELBA23 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idClose1 For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aGUICheckbox[$i]) Case $GUI_CHECKED $aCheckedVideos[$i] = $aArrayFile[$i] Case $GUI_UNCHECKED EndSwitch Next ExitLoop EndSwitch WEnd GUIDelete($hGUI) Return $aCheckedVideos EndFunc ;==>DisplayVideos
-
Hello I am trying to insert or replace data in an existing 2D array. _ArrayInsert seems to always add a row when inserting the data to the specified column. This code is from the _ArrayInsert Function Reference, with only the modified sample I think I want to use... #include <Array.au3> Local $aArray_Base[10][3] For $i = 0 To 9 For $j = 0 To 2 $aArray_Base[$i][$j] = $i & " - " & $j Next Next _ArrayDisplay($aArray_Base, "2D - Original") ; Insert single item in defined column $aArray = $aArray_Base _ArrayInsert($aArray, 0, "True", 2) ; <- I want to add this data to Row 0, Column 3 but retain the data in Columns_ and 1. _ArrayDisplay($aArray, "2D - Defined column") If you run the above code you will see it adds a new row and inserts "True" into column 3. How can I do this without adding a row?
-
Hi, I am automating the testing of a video player. I search a file for ".mp4" and want to create a GUI with radio buttons to select what video to play. The number of videos can change based on the user's library so this must be created automatically. I have searched for how to accomplish this and there are several posts out there that help a little but I can't figure out the solution. I pulled the offending code from my main script and created the file below to make this easier to read. I am sure one of our experts here can help! #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Local $sMediaFile = "D:\MediaFiles\MediaFiles.txt" Local $iStrReturn = 0 Local $aText Local $aArrayFile Local $iMax = 6 ;Default number of Videos - 1 for the array counter Local $aVideoName[$iMax] = [0] Local $sCheckBox1 Local $iT = 0, $iVideoCount = 0, $iCount Local $ix = 0 Local $iy = 0 Local $idClose1 Const $iL = 10 ; Count from Left for GUI so all buttons line up ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read a list of video file names and create a GUI with Radio Buttons to select a single video. ; Problem: We don't know how many video names will be in the text file, so we can't hard code Case Statements & their variables ; Put the Video File Names into an Array _FileReadToArray($sMediaFile, $aArrayFile) For $a = 1 To $aArrayFile[0] ; Step through the array looking for .mp4 If StringInStr($aArrayFile[$a], ".mp4") Then $iVideoCount = $iVideoCount + 1 $aText = StringSplit($aArrayFile[$a],"\\") ; This video player reads double backslashes For $a1 = 1 to $aText[0] ; Check that the array is big enough If StringInStr($aText[$a1], ".mp4") Then ;MsgBox(0,"","Video is " & $aText[$a1]) If UBound($aVideoName) = $iVideoCount Then ; Resize the array when $iCount is equal to the element count in the array to prevent subscript error ReDim $aVideoName[$aVideoName[0] + $iMax] EndIf $aVideoName[$iVideoCount] = $aText[$a1]; add data to new index element $aVideoName[0] = $a1 ; update the index count for future reference ; The idea is to create a GUI width to accommodate long video file names $it = StringLen($aVideoName[$iVideoCount]) If $iT > $ix Then $ix = $iT EndIf EndIf Next EndIf Next ; Move backwards through the array deleting blank rows For $iCount = UBound($aVideoName) - 1 To 0 Step -1 If $aVideoName[$iCount] = "" Then _ArrayDelete($aVideoName, $iCount) EndIf Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Create the GUI - Names and Radio Button counts will vary - How do I do this? ; ;_ArrayDisplay($aVideoName) ;Local $aVarName[$aVideoName[0]] Local $iRows = UBound($aVideoName, $UBOUND_ROWS) $iRows = $iRows -1 $aVideoName[0] = $iRows ; Prep the GUI to display the FileNames with Radio Buttons - Can only select one at a time. $a = 0 $ix = $ix + 200 $iy = ($aVideoName[0] * 30) + 60 $hGUI = GUICreate("Videos", $ix, $iy) ;$iT = $iT+30 ; Create the variable names for the Case statement - Video count may change so Video Names displayed and GUICtrlCreateRadio count may change. ;~ For $a = 1 to $aVarName[0] ;~ If UBound($aVarName) = $aVarName Then ;~ ; Resize the array when $iCount is equal to the element count in the array to prevent subscript error ;~ ReDim $aVarName[$aVarName[0] + $iMax] ;~ EndIf ;~ Assign("$bVideoName" & $a, $a) ;~ Local $aVarName[$a] = Eval($bVideoName[$a]) ;~ ; $aVarName[$a] = GUICtrlCreateRadio($aVarName[$a], $iL, $iT) ;~ Next $iCount = 1 ;MsgBox(0,"","VideoName[0] is "&$aVideoName[0]) ;_ArrayDisplay($aVideoName) Local $bVideoName1 If $iCount < $aVideoName[0] Then $bVideoName1 = GUICtrlCreateRadio($aVideoName[$iCount], $iL, $iT) GUICtrlSetState($bVideoName1, $GUI_CHECKED) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0]) Then Local $bVideoName2 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0]) Then Local $bVideoName3 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0]) Then Local $bVideoName4 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0] -1) Then Local $bVideoName5 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0] -1) Then Local $bVideoName6 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0] -1) Then Local $bVideoName7 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iT = $iT + 30 $idClose1 = GUICtrlCreateButton("Go!", $iL, $iT) GUISetState(@SW_SHOW) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Switch Statement ; ;Local $nMsg = "" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $bVideoName1 Case $bVideoName2 Case $bVideoName3 Case $bVideoName4 Case $bVideoName5 ;Case $bVideoName6 <- Fails because there are only 5 videos - Need variable $bVideoNames ;Case $bVideoName7 <- Fails because there are only 5 videos Case $idClose1 $bVideoName1 = GUICtrlRead($bVideoName1) $bVideoName2 = GUICtrlRead($bVideoName2) $bVideoName3 = GUICtrlRead($bVideoName3) $bVideoName4 = GUICtrlRead($bVideoName4) $bVideoName5 = GUICtrlRead($bVideoName5) ;$bVideoName6 = GUICtrlRead($bVideoName6) ;$bVideoName7 = GUICtrlRead($bVideoName7) ExitLoop EndSwitch WEnd GUIDelete($nMsg) MsgBox(0,"","Case " & $nMsg & " was selected.") ; Always returns 8. ??? This is the "MediaFiles.txt" file I am reading: D:\\MediaFiles\\BigBuckBunny.mp4 D:\\MediaFiles\\BigBuckBunny60fps.mp4 D:\\MediaFiles\\Sintel.mp4 D:\\MediaFiles\\sintel-2048-surround.mp4 D:\\MediaFiles\\TearsOfSteel.mp4 D:\\MediaFiles\\tearsofsteel_4K.mp4 I'm sure I have several mistakes (or poor coding methods) in my AutoIt file.
-
Hi, I am creating a GUI with options for tests. As this script grows I keep updating, changing and adding checkboxes and radio buttons. I started out manually incrementing the location of the controls like so: ; Create Log Level Radio Buttons $bSelect1 = GUICtrlCreateRadio("Info Level Logging.", 10, 10) $bSelect2 = GUICtrlCreateRadio("Error Level Logging.", 10, 40) $bSelect3 = GUICtrlCreateRadio("Debug Level Logging.", 10, 70) After about 20 Radio buttons and checkboxes this gets a bit unwieldy. I would like to replace the "Left" and "Top" numbers with variables like $iL1, $iT1 & $iL2, $iT2 $bSelect1 = GUICtrlCreateRadio("Info Level Logging.", $iL, $iT1) $bSelect2 = GUICtrlCreateRadio("Error Level Logging.", $iL, $iT2) $bSelect3 = GUICtrlCreateRadio("Debug Level Logging.", $iL, $iT3) Then I would like to increment the $iTx by 30 I have searched the forums and Internet and have not found anything that makes sense to me. Granted, I am not a programmer; just a Validation Engineer with enough programming experience to write simple scripts. Any help would be appreciated. Something like: Local $iT1 = 10, $iT2, $iT3, $iT4, $iT5, $iT6, $iT7, $iT8, $iT9, $iT10, $iT11, $iT12, $iT13, $iT14, $iT15, $iT16, $iT17, $iT18, $iT19, $iT20, $iInc for $iInc = 2 to 20 $iT & $iInc = $iT & $iInc +30 Next where this adds $iInc to $iT to equal $iT1, and assign +30 to that variable so I end up with $iT1 = 10, $iT2 = 40, $iT3 = 70, etc. Is this possible?
-
OK I figured it out. I neglected to put a [3] after my declaration. Local @aOptions[3] solved the issue. This is weird because usually when I declare an array in other code I don't have to add [x] as in : Local $aArray << has worked before vs Local $aArray[3] << required for this particular script... I don't understand why!