Sign in to follow this  
Followers 0
olympus

GUICtrlCreateCombo

3 posts in this topic

I'm trying to create a GUI with a drop down list of the available drives on the computer. The default value of the drive will be read from an INI file but if the INI file or the section is not found it should display 'none' as default. When the user chooses a drive from the list and the clicks on OK, the new drive letter is written over the old drive letter in the INI file... but my script below does not seem to fully work:

#include <GUIConstantsEx.au3>

Example()

Func Example()
    
    $gui = GUICreate("My GUI combo", 200, 200)

    $driveini = IniRead("test.ini", "settings", "drive", "none")

    $drives = DriveGetDrive ("fixed")

    $choosedrive = GUICtrlCreateCombo("", 10, 10, 80, 80)

    For $i = 1 to $drives[0]
        GUICtrlSetData(-1, $drives[$i], $driveini)
    Next

    $drivechosen = GUICtrlRead($choosedrive)

    $okbutton = GUICtrlCreateButton("OK", 10, 100)

    $cancelbutton = GUICtrlCreateButton("CANCEL", 50, 100)


    GUISetState(@SW_SHOW, $gui)

    ; Run the GUI until the dialog is closed
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($gui)
                Exit

            Case $okbutton
                IniWrite("test.ini", "settings", "drive", $drivechosen)
                Exit

            Case $cancelbutton
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>Example

The INI file:

[settings]

drive=c:

When the INI file is not present or when the section is not found, the default value is blank, not 'none' as wanted. Also when choosing a new drive and clicking on OK, it does not write the new drive letter to the INI file. Any suggestions on how I can solve this problem? Thank you.

Share this post


Link to post
Share on other sites



Hi,

this should work:

#include <GUIConstantsEx.au3>

Example()

Func Example()
    
    $gui = GUICreate("My GUI combo", 200, 200)

    $driveini = IniRead("test.ini", "settings", "drive", "none")

    $drives = DriveGetDrive ("fixed")

    $choosedrive = GUICtrlCreateCombo("", 10, 10, 80, 80)

    For $i = 1 to $drives[0]
        GUICtrlSetData(-1, $drives[$i], $driveini)
    Next
    
    If $driveini = "none" Then GUICtrlSetData (-1, $driveini, $driveini)

    $okbutton = GUICtrlCreateButton("OK", 10, 100)

    $cancelbutton = GUICtrlCreateButton("CANCEL", 50, 100)


    GUISetState(@SW_SHOW, $gui)

    ; Run the GUI until the dialog is closed
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($gui)
                Exit

            Case $okbutton
                $drivechosen = GUICtrlRead($choosedrive)
                IniWrite("test.ini", "settings", "drive", $drivechosen)
                Exit

            Case $cancelbutton
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites

That worked beautifully! Thank you! ;)

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