bobbintb Posted May 15, 2012 Share Posted May 15, 2012 i've been searching the forums but cant quite find a way to do what i need. i have a gui that is supposed to read the removable drives into an array and display them, along with other information in a drop down box. then i want the program to run commands based on what option is selected. the problem i'm facing is that once the array has been parsed into the gui with the additional info, i cant figure a way to keep the array associated with the selected item in the dropdown so that when an option is selected i can still work with the array itself and not all the extra information added for the user's sake. and i can't really just use GUICtrlRead and parse in back because thats just not going to work for my purposes. here's what i have so for: #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $aArray = DriveGetDrive("REMOVABLE") $Form1_1 = GUICreate("Form1", 615, 437, 264, 339) $Label1 = GUICtrlCreateLabel("Select removeable drive to load Windows onto:", 16, 8, 227, 17) $Combo1 = GUICtrlCreateCombo("", 32, 80, 445, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) If @error Then ; An error occurred when retrieving the drives. MsgBox(4096, "DriveGetDrive", "No removable drives found or some other error occured.") Else For $i = 1 To $aArray[0] $label = DriveGetLabel($aArray[$i]) if $label="" then $label ="[no label]" ;~ MsgBox(4096,"",$aArray[$i]) GUICtrlSetData(-1, $label& " (" &StringUpper($aArray[$i]) & ") " & Round(DriveSpaceTotal($aArray[$i]), 0) & " MB Total" & " Windows Volume ID: " & DriveGetSerial($aArray[$i])) Next EndIf ;~ GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;~ MsgBox(4096,"test",GUICtrlRead($Combo1,1)) Exit EndSwitch WEnd the easiest and most effective thing i can think of is to somehow query the order number of the item in the drop down is selected (meaning the nth option is selected) and plug that into my $aArray. i just cant think of how to do it. any help would be appreciated. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2012 Moderators Share Posted May 15, 2012 bobbintb, You could read the combo, extract the Drive letter and then search the array for that letter like this: While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Combo1 $aRet = _StringBetween(GUICtrlRead($Combo1), "(", ")") $iIndex = _ArraySearch($aArray, $aRet[0]) If Not @error Then MsgBox(0, "Drive", "Array Index = " & $iIndex & @CRLF & "Drive: " & $aArray[$iIndex]) EndIf EndSwitch WEnd Any use? M23 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...
bobbintb Posted May 15, 2012 Author Share Posted May 15, 2012 (edited) i thought about that but if anything else in the string, like the label, has parenthesis then that could break something. is there a way to attach a variable to the dropdown? in the loop where GUICtrlSetData is parsing out the extra info, maybe i can also assign a numerical value to each dropdown option. then i can reference it with the array. could i use GUICtrlSetData to set more than one piece of data to the control (an array maybe), and only display to the user the part that i wish? id like to avoid using GUICtrlRead because there are too many ways it could break the script in this instance. Edited May 15, 2012 by bobbintb Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2012 Moderators Share Posted May 15, 2012 bobbintb,but if anything else in the string, like the label, has parenthesis then that could break somethingYou are determining the format of the combo entries - just ensure that there is nothing else in parentheses. And even if you do put several items in parentheses, _StringBetween returns an array of all matches, so all you have to do is to use the correct element. Why do you need to access the array again anyway? Surely just getting the drive letter from the combo entry is enough as that is all the array contains? M23 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...
bobbintb Posted May 15, 2012 Author Share Posted May 15, 2012 (edited) bobbintb,You are determining the format of the combo entries - just ensure that there is nothing else in parentheses. And even if you do put several items in parentheses, _StringBetween returns an array of all matches, so all you have to do is to use the correct element. Why do you need to access the array again anyway? Surely just getting the drive letter from the combo entry is enough as that is all the array contains? M23i could just get the drive letter from the combo entry but then i would have to plan for all script breaking eventualities, such as the drive label having parenthesis and determining if what's between the parenthesis is the actual drive letter or part of the drive label.instead of getting the list of removable drives and from that list make a gui with extra info for the user and then reading the control to see what the user selected and parsing it out and making sure that what the script thinks is the drive letter is actually the drive letter, it seems easier for me and more precise do it another way.i had an idea to take the array of drive letter and add another dimension that contains the additional info for the user, then populate the gui with that info. that way i can link the actual drive letter in the first dimension of the array (as opposed to parsed one) to the GUI info in the second, so that when the script checks which item was selected, it can compare the GUICtrlRead with the correct info in the array to make certain the drive letter is correct. now i just need to add a second dimension to the existing array, if i can figure out how to do that. Edited May 15, 2012 by bobbintb Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2012 Moderators Share Posted May 15, 2012 bobbintb,now i just need to add a second dimension to the existing array, if i can figure out how to do thatI think there is a UDF around here somewhere to do that - look in the sigs of BrewManNH or guinness. If you cannot find it, use UBound to find the size of the returned array, use that to declare a 2D array of the correct size and then loop through the first array to fill the second. M23 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...
bobbintb Posted May 15, 2012 Author Share Posted May 15, 2012 ok, i think im on the right track. i havent coded in a while so im a little rusty, especially at explaining what im trying to do to others. thanks for the help and patience, melba. Link to comment Share on other sites More sharing options...
BrewManNH Posted May 15, 2012 Share Posted May 15, 2012 (edited) Here's one way of doing it. #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $aArray = DriveGetDrive("REMOVABLE") $Form1_1 = GUICreate("Form1", 615, 437, 264, 339) $Label1 = GUICtrlCreateLabel("Select removeable drive to load Windows onto:", 16, 8, 227, 17) $Combo1 = GUICtrlCreateCombo("", 32, 80, 445, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) $Button = GUICtrlCreateButton(" Read ", 32, 150) If @error Then ; An error occurred when retrieving the drives. MsgBox(4096, "DriveGetDrive", "No removable drives found or some other error occured.") Else For $i = 1 To $aArray[0] $label = DriveGetLabel($aArray[$i]) If $label = "" Then $label = "[no label]" GUICtrlSetData($Combo1, $label & " (" & StringUpper($aArray[$i]) & ") " & Round(DriveSpaceTotal($aArray[$i]), 0) & " MB Total" & " Windows Volume ID : " & DriveGetSerial($aArray[$i])) Next EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button $sCombo = GUICtrlRead($Combo1) ConsoleWrite("Combo contents = " & $sCombo & @CRLF) For $i = 1 To $aArray[0] If StringInStr($sCombo, $aArray[$i]) Then ConsoleWrite("Drive letter chosen = " & $aArray[$i] & @CRLF) EndIf Next EndSwitch WEnd Uses the contents of the combobox and the contents of the array without altering either one. Seeing as how drive labels can't contain the colon, there's no way to give a drive a label with one. So this search can't fail because unless you do something like put colons in the combo contents the only time it will match the string to the array is when the drive letters match. EDIT: I just realized that you had a colon in the combo box information, see the line in the code above which corrects this. I added a space between "Windows Volume ID" and the following colon so it won't misread that line as a drive letter. Note, this would ONLY affect something if you had a D: drive that was also a removable drive. Edited May 15, 2012 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
BrewManNH Posted May 15, 2012 Share Posted May 15, 2012 Updated the above code, see the edit. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
rover Posted May 16, 2012 Share Posted May 16, 2012 (edited) Or, you can use the functions designed to do this that are built into the listbox api. Sets the application defined value for each internal listbox item. The AutoIt native Combobox is not using this parameter, it is always 0 or you can use the UDF combobox, either way, this is how you do it. expandcollapse popup#include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListBox.au3> #include <GuiComboBox.au3> $aArray = DriveGetDrive("REMOVABLE") $Form1_1 = GUICreate("Form1", 615, 437, 264, 339) $Label1 = GUICtrlCreateLabel("Select removeable drive to load Windows onto:", 16, 8, 227, 17) $Combo1 = GUICtrlCreateCombo("", 32, 80, 445, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) $Button = GUICtrlCreateButton(" Read ", 32, 150) $tInfo = 0 $hList = 0 $iIdx = 0 If _GUICtrlComboBox_GetComboBoxInfo($Combo1, $tInfo) Then $hList = DllStructGetData($tInfo, "hList") If @error Then ; An error occurred when retrieving the drives. MsgBox(4096, "DriveGetDrive", "No removable drives found or some other error occured.") Else For $i = 1 To $aArray[0] $label = DriveGetLabel($aArray[$i]) If $label = "" Then $label = "[no label]" GUICtrlSetData($Combo1, $label & " (" & StringUpper($aArray[$i]) & ") " & Round(DriveSpaceTotal($aArray[$i]), 0) & " MB Total" & " Windows Volume ID: " & DriveGetSerial($aArray[$i])) $iIdx = _GUICtrlComboBox_GetCount($Combo1) If @error Or $iIdx = -1 Then ContinueLoop _GUICtrlListBox_SetItemData($hList, $iIdx - 1, $iIdx) ;use a 1-based index Next EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button $iIdx = _GUICtrlListBox_GetItemData($hList, _GUICtrlComboBox_GetCurSel($Combo1)) If $iIdx >= 1 Then ConsoleWrite("Drive letter chosen = " & $aArray[$iIdx] & @CRLF) EndSwitch WEnd Edited May 16, 2012 by rover I see fascists... 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