Sign in to follow this  
Followers 0
lopolop

Combo box selecting file..

13 posts in this topic

well i aint the greatest with using GUI and code.. so i am makeing a program :whistle: with different settings that need to be specified according to what is needed for that task... but i want you to be able to select different settings through a combo box...

ehhh kind of hard to explain.

<Combo Box> ... Each selection is selecting a *.ini file from Program Folder...

But when you select the Pre-Made *.ini it updates the settings...

If you dont understand ill try to explain it better...


Share this post


Link to post
Share on other sites



well i aint the greatest with using GUI and code.. so i am makeing a program :whistle: with different settings that need to be specified according to what is needed for that task... but i want you to be able to select different settings through a combo box...

ehhh kind of hard to explain.

<Combo Box> ... Each selection is selecting a *.ini file from Program Folder...

But when you select the Pre-Made *.ini it updates the settings...

If you dont understand ill try to explain it better...

Sounds like fun and tedious, post the code when you're done :).

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

ehh that was a question.. but after searching*sorry* i came up with this unworking code...

#include <GUIConstants.au3>


$Form1 = GUICreate("Test Form", 273, 409, 387, 194)
GUISetBkColor(0xA6CAF0)
$Group2 = GUICtrlCreateGroup("Input", 144, 8, 121, 49)
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group1 = GUICtrlCreateGroup("Profile", 8, 8, 121, 49)
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Profiles = GUICtrlCreateCombo("", 16, 24, 105, 21)
$Input = GUICtrlCreateInput("0000000", 152, 24, 105, 21, -1, $WS_EX_CLIENTEDGE)
$Search = FileFindFirstFile(".ini")
$spl = "|"

GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
While 1
    $spl = $spl & FileFindNextFile($search) & "|"
    If @error Then ExitLoop
WEnd
$filearray=StringSplit($spl,"|")
GUICtrlSetData($Profiles,$spl,$filearray[2])
FileClose($search)
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        ;;;;;;;
    EndSelect
WEnd
Exit

gives me a blank selection for me to choose from combo

Edited by lopolop

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$Search = FileFindFirstFile("*.ini")

will do the trick

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

yes thank you! but now i got the second thing i was asking before... how can i do this that when i select the *.ini that the Input will change to what is in the ini file..

so something like this...

#include <GUIConstants.au3>

$inp = "0000000"

$Form1 = GUICreate("Test Form", 273, 409, 387, 194)
GUISetBkColor(0xA6CAF0)
$Group2 = GUICtrlCreateGroup("Input", 144, 8, 121, 49)
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group1 = GUICtrlCreateGroup("Profile", 8, 8, 121, 49)
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Profiles = GUICtrlCreateCombo("", 16, 24, 105, 21)
$Input = GUICtrlCreateInput($inp, 152, 24, 105, 21, -1, $WS_EX_CLIENTEDGE)
$Search = FileFindFirstFile("*.ini")
$spl = "|"

GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
While 1
    $spl = $spl & FileFindNextFile($search) & "|"
    If @error Then ExitLoop
WEnd
$filearray=StringSplit($spl,"|")
GUICtrlSetData($Profiles,$spl,$filearray[2])
FileClose($search)
$file = GUICtrlRead($Profiles)
$inp = IniRead($file, "Settings", "Input", "default")

GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        ;;;;;;;
    EndSelect
WEnd
Exit

This didnt work but i see why just dont know how to make it $inp like Refresh..


Share this post


Link to post
Share on other sites

Read it all with the ini functions and guictrlsetdata()


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

what do you mean read it all?

i tried this:

#include <GUIConstants.au3>

$inp = "0000000"

$Form1 = GUICreate("Test Form", 273, 409, 387, 194)
GUISetBkColor(0xA6CAF0)
$Group2 = GUICtrlCreateGroup("Input", 144, 8, 121, 49)
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group1 = GUICtrlCreateGroup("Profile", 8, 8, 121, 49)
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Profiles = GUICtrlCreateCombo("", 16, 24, 105, 21)
$Input = GUICtrlCreateInput($inp, 152, 24, 105, 21, -1, $WS_EX_CLIENTEDGE)
$Search = FileFindFirstFile("*.ini")
$spl = "|"

GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
While 1
    $spl = $spl & FileFindNextFile($search) & "|"
    If @error Then ExitLoop
WEnd
$filearray=StringSplit($spl,"|")
GUICtrlSetData($Profiles,$spl,$filearray[2])
FileClose($search)
$file = GUICtrlRead($Profiles)
$inp = IniRead($file, "Settings", "Input", "default")

GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    GUICtrlSetData($Input, $inp)
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        ;;;;;;;
    EndSelect
WEnd
Exit

that semi-worked because it did change the Value from 00000 to the first file that was selected in the combo box but.. when i change the combo box to a different *.ini file it Wont "Refresh"


Share this post


Link to post
Share on other sites

do IniReadSection() ... parse the array into the info you want, and go from there with GUICtrlSetData()


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

what do you mean by parse... i change $inp and GuiCtrlSetData to this but it still didnt work...

$inp = IniReadSection($file, "Settings")

GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    for $i = 1 to $inp[0][0]
    GUICtrlSetData($Input, $inp[$i][1])
    Next

Well if this cant really work i guess i could just have a load button which would always work. Thanks for the help!

Edited by lopolop

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

My solution.

#include <GUIConstants.au3>
#Include <Array.au3>

$Form1 = GUICreate("Test Form", 273, 209, 387, 194)
GUICtrlCreateGroup("Input", 144, 8, 121, 49)
GUICtrlCreateGroup("Profile", 8, 8, 121, 49)
$Profiles = GUICtrlCreateCombo("", 16, 24, 105, 21)
$Input = GUICtrlCreateInput("", 152, 24, 105, 21, -1, $WS_EX_CLIENTEDGE)

$Search = FileFindFirstFile(@ScriptDir & "\" & "*.ini")
$ProfileArray = _ArrayCreate($Search)

While 1
    $File = FileFindNextFile($Search)
    If @error Then ExitLoop
    _ArrayAdd($ProfileArray, $File)
WEnd

FileClose($Search)

For $r = 1 To UBound($ProfileArray, 1) - 1
    GUICtrlSetData($Profiles, StringTrimRight($ProfileArray[$r], 4))
Next

$Current_Profile = GUICtrlRead($Profiles)

GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case GUICtrlRead($Profiles) <> $Current_Profile
        GUICtrlSetData($Input, IniRead(GUICtrlRead($Profiles)&".ini", "Settings", "Input", "default"))
        $Current_Profile = GUICtrlRead($Profiles)
    Case Else
        ;;;;;;;
    EndSelect
WEnd
Exit
Edited by Zib

Share this post


Link to post
Share on other sites

wow thanks alot! works perfectly :whistle:


Share this post


Link to post
Share on other sites

This thread gave me an idea to populate through an Ini if I wanted to go through each value in a GUI.... Just change MyIni.ini to whatever... not really what your looking for here, but I think I'll find a use for it.

#include <guiconstants.au3>
Opt('GUIOnEventMode', 1)

Global $IniInfo = _IniGetSKV(@DesktopDir & '\MyIni.ini')
Global $IniSect, $IniKey, $IniValue

$MainGUI = GUICreate('Example', 200, 100)
$Combo = GUICtrlCreateCombo('', 10, 10, 180, 150)
$Input = GUICtrlCreateInput('', 10, 35, 180, 20, $ES_CENTER)

For $i = 1 To UBound($IniInfo, 1) - 1
    $IniSect &= $IniInfo[$i][$i][0] & '|'
Next

GUICtrlSetData($Combo, $IniSect)

GUICtrlSetOnEvent($Combo, '_CheckIniStat')
GUISetOnEvent($GUI_EVENT_CLOSE, '_ExitNow', $MainGUI)

GUISetState()
While 1
    Sleep(1000)
WEnd

Func _CheckIniStat()
    Local $sString = GUICtrlRead($Combo), $iFound
    Local $iCount, $ixCount, $xCount, $sHold
    For $ixCount = 1 To UBound($IniInfo, 1) - 1
        For $iCount = 1 To UBound($IniInfo, 2) - 1
            If $sString = $IniInfo[$ixCount][$iCount][0] Then
                For $xCount = 1 To UBound($IniInfo, 2) - 1
                    $sHold &= $IniInfo[$ixCount][$xCount][1] & '|'
                Next
                $iFound = 1
                ExitLoop
            ElseIf $sString = $IniInfo[$ixCount][$iCount][1] Then
                $sHold &= $IniInfo[$ixCount][$iCount][2] & '|'
                $iFound = 1
                ExitLoop
            ElseIf $sString = $IniInfo[$ixCount][$iCount][2] Then
                GUICtrlSetData($Input, $sString)
                GUICtrlSetData($Combo, '')
                GUICtrlSetData($Combo, StringTrimRight($IniSect, 1))
                $iFound = 3
                ExitLoop
            EndIf
        Next
        If $iFound Then ExitLoop
    Next
    If Not $iFound Then Return SetError(1, 0, 0)    
    If $iFound <> 3 Then 
        GUICtrlSetData($Combo, '')
        GUICtrlSetData($Combo, $sString & '|' & StringTrimRight($sHold, 1), $sString)
    EndIf
EndFunc

Func _ExitNow()
    Exit
EndFunc

Func _IniGetSKV($hIniLocation)
    ;Get All Sections
    Local $aSections = IniReadSectionNames($hIniLocation)
    If @error Then Return SetError(1, 0, 0)
    ;Get All The Keys and Values for Each section
    Local $aKeyValues[$aSections[0]+1][1][3]
    For $iCount = 1 To $aSections[0]
        $aKV = IniReadSection($hIniLocation, $aSections[$iCount])
        ReDim $aKeyValues[$aSections[0]+1][$aKV[0][0]+1][3]
        For $xCount = 1 To $aKV[0][0]
            $aKeyValues[$iCount][$xCount][0] = $aSections[$iCount]
            $aKeyValues[$iCount][$xCount][1] = $aKV[$xCount][0]
            $aKeyValues[$iCount][$xCount][2] = $aKV[$xCount][1]
        Next
    Next
    Return $aKeyValues ;Return a 3 Dimensional Array
EndFunc
It's not cleaned up, but it works.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

ok i got two more problems or well maybe just questions...

But first thing, i have check Boxes that need to be changed according to profile, but i cant seem to find a way to make them change i tried(setting ini to have $GUI_Checked) and doing this at the end of Zib's code

GUICtrlSetState($test, IniRead(GUICtrlRead($Profiles)&".ini", "Settings", "test", "default"))

;And

$testState = IniRead(GUICtrlRead($Profiles)&".ini", "Settings", "test", "default")
        GUICtrlSetState($test, $testState)

but no luck..

Also for the second thing i would like to know the best way to call the data.. should it be done directly from the ini? or should i just use GuiCtrlRead()?

Edited by lopolop

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