Grantgimp Posted September 28, 2009 Share Posted September 28, 2009 I keep getting this error and can't fix it - ------- C:\Documents and Settings\Owner\My Documents\AutoIT Scripts\start service.au3 (20) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: GUICtrlSetData($hCombo,$FileList[$X][0]) GUICtrlSetData($hCombo,^ ERROR ------------ #Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> #include <GUIComboBox.au3> $Directory=@DesktopDir & "\Current Service" $FileList=_FileListToArray($Directory,"*.ppt") If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf ;- _ArrayDisplay($FileList,"$FileList") if $FileList[0] = 1 Then $x = 1 Else $hGUI = GUICreate("My GUI combo",300,100) ; will create a dialog box that when displayed is centered $hCombo = GUICtrlCreateCombo("", 10, 10,"","",$CBS_DROPDOWNLIST) ;$hCombo = _GUICtrlComboBox_Create($hGUI, "", 2, 2, 296, 20,$CBS_DROPDOWNLIST ) ;Populate For $X = 0 to Ubound($FileList)-1 GUICtrlSetData($hCombo,$FileList[$X][0]) ;_GUICtrlComboBox_AddString($hCombo,$aData[$X][0]) Next $hButton = GUICtrlCreateButton("Retrieve Value",100,40,100) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton MsgBox(0,"",$aData[_GUICtrlComboBox_GetCurSel($hCombo)][0]) EndSwitch WEnd ;~ _ArrayDisplay($FileList,"$FileList") ;~ $x = InputBox("Select Service", "Please select the PowerPoint file you wish to show", 1) EndIf MsgBox("", "",@ProgramFilesDir & "\Microsoft Office\OFFICE11\POWERPNT.EXE /s """ & $Directory & "\" & $FileList[$x] & """") Run(@ProgramFilesDir & "\Microsoft Office\OFFICE11\POWERPNT.EXE /s """ & $Directory & "\" & $FileList[$x] & """") Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2009 Moderators Share Posted September 28, 2009 Grantgimp,First, welcome to the AutoIt forums.A good start - some code to work on and a clear question. I wish some other newcomers would do the same. You are trying to call a 1-D array with 2 dimension coordinates. FileListToArray produces a 1D array ($FileList), so when you try and list it with 2 dimensions (GUICtrlSetData($hCombo,$FileList[$X][0])) you get an error.You should also not put the first element in the combobox - it is merely a count of the remaining elements. But you can use it to limit the loop. Change the relevant lines in your code to this:For $x = 1 To $FileList[0] GUICtrlSetData($hCombo, $FileList[$x])And all should be well.M23P.S. It makes it easier to read your code if you use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
GEOSoft Posted September 28, 2009 Share Posted September 28, 2009 Another method since you already have array.au3 #included expandcollapse popup#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> #include <GUIComboBox.au3> $Directory=@DesktopDir & "\Current Service" $FileList=_FileListToArray($Directory,"*.ppt") If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf ;- _ArrayDisplay($FileList,"$FileList") if $FileList[0] = 1 Then $x = 1 Else $hGUI = GUICreate("My GUI combo",300,100) ; will create a dialog box that when displayed is centered $hCombo = GUICtrlCreateCombo("", 10, 10,"","",$CBS_DROPDOWNLIST) ;$hCombo = _GUICtrlComboBox_Create($hGUI, "", 2, 2, 296, 20,$CBS_DROPDOWNLIST ) ;Populate GUICtrlSetData($hCombo,_ArrayToString($FileList)) $hButton = GUICtrlCreateButton("Retrieve Value",100,40,100) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton MsgBox(0,"",$aData[_GUICtrlComboBox_GetCurSel($hCombo)][0]) EndSwitch WEnd ;~ _ArrayDisplay($FileList,"$FileList") ;~ $x = InputBox("Select Service", "Please select the PowerPoint file you wish to show", 1) EndIf MsgBox("", "",@ProgramFilesDir & "\Microsoft Office\OFFICE11\POWERPNT.EXE /s """ & $Directory & "\" & $FileList[$x] & """") Run(@ProgramFilesDir & "\Microsoft Office\OFFICE11\POWERPNT.EXE /s """ & $Directory & "\" & $FileList[$x] & """") George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Grantgimp Posted September 28, 2009 Author Share Posted September 28, 2009 Thanks to you both. One final question in connection with George's response - Is there anyway of not including [0] item when GUICtrlSetData($hCombo,_ArrayToString($FileList)) as I don't want the number of items in the array included in the combo box? Another method since you already have array.au3 #included expandcollapse popup#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> #include <GUIComboBox.au3> $Directory=@DesktopDir & "\Current Service" $FileList=_FileListToArray($Directory,"*.ppt") If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf ;- _ArrayDisplay($FileList,"$FileList") if $FileList[0] = 1 Then $x = 1 Else $hGUI = GUICreate("My GUI combo",300,100) ; will create a dialog box that when displayed is centered $hCombo = GUICtrlCreateCombo("", 10, 10,"","",$CBS_DROPDOWNLIST) ;$hCombo = _GUICtrlComboBox_Create($hGUI, "", 2, 2, 296, 20,$CBS_DROPDOWNLIST ) ;Populate GUICtrlSetData($hCombo,_ArrayToString($FileList)) $hButton = GUICtrlCreateButton("Retrieve Value",100,40,100) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton MsgBox(0,"",$aData[_GUICtrlComboBox_GetCurSel($hCombo)][0]) EndSwitch WEnd ;~ _ArrayDisplay($FileList,"$FileList") ;~ $x = InputBox("Select Service", "Please select the PowerPoint file you wish to show", 1) EndIf MsgBox("", "",@ProgramFilesDir & "\Microsoft Office\OFFICE11\POWERPNT.EXE /s """ & $Directory & "\" & $FileList[$x] & """") Run(@ProgramFilesDir & "\Microsoft Office\OFFICE11\POWERPNT.EXE /s """ & $Directory & "\" & $FileList[$x] & """") Link to comment Share on other sites More sharing options...
GEOSoft Posted September 28, 2009 Share Posted September 28, 2009 (edited) Thanks to you both. One final question in connection with George's response - Is there anyway of not including [0] item when GUICtrlSetData($hCombo,_ArrayToString($FileList)) as I don't want the number of items in the array included in the combo box? Sure is GUICtrlSetData($hCombo,_ArrayToString($FileList, "|", 1)) Edit: If you want it to set a default value then use it like this GUICtrlSetData($hCombo,_ArrayToString($FileList, "|", 1), $FileList[1]) Yiu can change the [1] to whatever element you want as the default. The example uses the first element but changing it to [3] would set it to the third. Edited September 28, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Grantgimp Posted September 28, 2009 Author Share Posted September 28, 2009 Sorry to bother you again but you last solution has a negative knock-on effect on $FileList[_GUICtrlComboBox_GetCurSel($hCombo)] as this only returns a number now instead of the actual text Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2009 Moderators Share Posted September 28, 2009 (edited) Grantgimp,_GUICtrlComboBox_GetCurSel returns the "Zero-based index of the currently selected item". So you need to add 1 to the return to get the value of the text (remember that element [0] is a count!). But you can get the selected text directly by using:GUICtrlRead($hCombo)I hope this helps.M23Edit: speeling Edited September 28, 2009 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Grantgimp Posted September 28, 2009 Author Share Posted September 28, 2009 Thanks to GeoSoft and Melba23, here is the final script which copies all files from $Source (in this case "F:") to $Directory (in this case "Current Service" on the Desktop) then if there is only 1 PowerPoint file in $Source, it automatically shows it, otherwise if there's more than 1, the user selects the powerpoint file they want from a list and then it is automatically shown. expandcollapse popup#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> #include <GUIComboBox.au3> $Source="F:\*.*" $Directory=@DesktopDir & "\Current Service" $FileExtn="*.ppt" $ApplSrce=@ProgramFilesDir & "\Microsoft Office\OFFICE11\POWERPNT.EXE /s """ FileCopy($Source, $Directory & "\", 9) $FileList=_FileListToArray($Directory,$FileExtn) If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf if $FileList[0] = 1 Then Run($ApplSrce & $Directory & "\" & $FileList[1] & """") Else $hGUI = GUICreate("Multiple Services",300,100) ; will create a dialog box that when displayed is centered $hCombo = GUICtrlCreateCombo("", 10, 10,"","",$CBS_DROPDOWNLIST) GUICtrlSetData($hCombo,_ArrayToString($FileList, "|", 1), $FileList[1]) $hButton = GUICtrlCreateButton("Show",100,40,100) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton Run($ApplSrce & $Directory & "\" & $FileList[_GUICtrlComboBox_GetCurSel($hCombo)+1] & """") WinClose("Multiple Services") EndSwitch WEnd EndIf Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now