Sign in to follow this  
Followers 0
Grantgimp

File List to Array to Listbox

8 posts in this topic

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] & """")

Share this post


Link to post
Share on other sites



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. :D

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. :D

Change the relevant lines in your code to this:

For $x = 1 To $FileList[0]
        GUICtrlSetData($hCombo, $FileList[$x])

And all should be well.

M23

P.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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Another method since you already have array.au3 #included

#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!"

Share this post


Link to post
Share on other sites

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

#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] & """")

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 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!"

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (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.

M23

Edit: speeling

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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.

#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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0