Qwerty212 Posted July 30, 2010 Share Posted July 30, 2010 Hello from Barcelona.I need some help with a combobox. I've tried hard to find info on the net, but I'm completely lostI'm trying to make an script with a combobox that let the user choose one CD Drive.Looking on the forums I've found that:;~ the program looks how many cd drives we have on the computer Dim $a_DriveList = DriveGetDrive('CDROM'), $s_DriveList For $i_aDriveList = 1 To $a_DriveList[0] $s_DriveList &= StringUpper($a_DriveList[$i_aDriveList]) & '|' Next GUICtrlSetData($gi_Drive, StringLeft($s_DriveList, StringLen($s_DriveList) - 1))taken from: http://www.autoitscript.com/forum/index.php?showtopic=16463and then I create the combobox with:$gi_Drive = GUICtrlCreateCombo ("All", 323, 245, 40, 30 ,$CBS_DROPDOWNLIST) GuiCtrlSetData($gi_Drive, "" & $s_DriveList) GUICtrlCreateLabel("Choose what CD Drive must be opened later:", 37, 250) GUICtrlSetFont(9, 400, 4, "MS Sans Serif") GUICtrlSetColor(-1, 0x0000AE)GUICtrlCreateCombo ("All", 323, 245, 40, 30 ,$CBS_DROPDOWNLIST)creates a combobox with the default option All.I've tried to change the value ofGuiCtrlSetData($gi_Drive, "" & $s_DriveList)to force the combo to have the first unit found as the default option on the combobox, but the closer I've get was with:$gi_Drive = GUICtrlCreateCombo ("" & $a_DriveList[1], 323, 245, 40, 30 ,$CBS_DROPDOWNLIST) GuiCtrlSetData($gi_Drive, "" & $s_DriveList)This creates the combobox and the default value is "f:" (in my case, the first CD Rom unit), but if I click in the combobox the list have the f: and F:,H:(in caps letters).Is it possible to set the first unit that the program found as the default selected option on the combobox?Will I can use the choosen unit later for another control?$U = GUICtrlRead($gi_Drive) combined withCDTray($U, "open") must open the choosed unit in the combobox, didn't it?At least I'm learning about arrays Help in any direction will be much apreciatted. Link to comment Share on other sites More sharing options...
taietel Posted July 30, 2010 Share Posted July 30, 2010 (edited) Hi adolfito121! First thing, before searching the forum: read the help file! Let's see: #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIComboBox.au3> _ShowDrives() Func _ShowDrives() Local $hGUI = GUICreate("Choose a CD/DVD drive", 300, 50) Local $Label = GUICtrlCreateLabel("Choose a CD/DVD unit:", 8, 8, 118, 17) Local $a_DriveList = DriveGetDrive('CDROM'), $s_DriveList For $i_aDriveList = 1 To UBound($a_DriveList)-1 $s_DriveList &= StringUpper($a_DriveList[$i_aDriveList]) & '|' Next Local $cboDrive = GUICtrlCreateCombo("All", 128, 8, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, $s_DriveList) _GUICtrlComboBox_SetCurSel($cboDrive, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $cboDrive MsgBox(0,"","You've chosen drive " & GUICtrlRead($cboDrive)) EndSwitch WEnd EndFunc Something like that? Edited July 31, 2010 by taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
Qwerty212 Posted July 31, 2010 Author Share Posted July 31, 2010 Hi adolfito121! First thing, before searching the forum: read the help file! Let's see: #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIComboBox.au3> _ShowDrives() Func _ShowDrives() Local $hGUI = GUICreate("Choose a CD/DVD drive", 300, 50) Local $Label = GUICtrlCreateLabel("Choose a CD/DVD unit:", 8, 8, 118, 17) Local $a_DriveList = DriveGetDrive('CDROM'), $s_DriveList For $i_aDriveList = 1 To UBound($a_DriveList)-1 $s_DriveList &= StringUpper($a_DriveList[$i_aDriveList]) & '|' Next Local $cboDrive = GUICtrlCreateCombo("All", 128, 8, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, $s_DriveList) _GUICtrlComboBox_SetCurSel($cboDrive, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $cboDrive MsgBox(0,"","You've chosen drive " & GUICtrlRead($cboDrive)) EndSwitch WEnd EndFunc Something like that? That's it!! Now I don't need the "All" anymore,I remove it Local $cboDrive = GUICtrlCreateCombo("", 323, 245, 40, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) and changed this part to force the program to show the first unit GUICtrlSetData(-1, $s_DriveList) _GUICtrlComboBox_SetCurSel($cboDrive, [b]0[/b]) Thank you very much! You're right, next time I will look before on the help file. Link to comment Share on other sites More sharing options...
taietel Posted July 31, 2010 Share Posted July 31, 2010 De nada!M.I. Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text 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