Jump to content
Sign in to follow this  
BryonR

Combo box values

Recommended Posts

BryonR

I'm having problems trying to get my combo box value to record. Its reading a text file for a list of values.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <EditConstants.au3>
$font = IniRead("c:\support.ini", "SiteInformation", "Font", "Times New Roman")
$editcallgui = GUICreate("My GUI test", 400, 400)
$APPLY = GUICtrlCreateButton("Apply", 1, 360, 129, 33, 0)
$CANCEL = GUICtrlCreateButton("CANCEL", 270, 360, 129, 33, 0)
$editcall_lbl_call = GUICtrlCreateLabel("Label1", 20, 150, 200, 50)
GUICtrlSetFont(-1, 12, 400, 0, $font)
GUICtrlSetColor(-1, 0x000080)
$call_list = FileOpen("c:\list.txt",0)
$angiocall = IniRead("C:\support.ini","CALL","DEPT","Default")

$calledit_combo_call = GUICtrlCreateCombo ($call,200,150,200,120)
                    If $call_list = -1 Then
                        MsgBox(0, "Error","Call file not built.")
                        Exit
                    EndIf
                    While 1
                        $line = FileReadLine($call_list)
                        If @error =-1 Then ExitLoop
                        $xc = StringFormat("%s",$line)
                        GUICtrlSetData($calledit_combo_call, $xc)
                    WEnd
                    FileClose($call_list)
                    $result_call = GUICtrlRead($calledit_combo_call, $xc)
                    IniWrite ("i:\radsupport\radsupport.ini","DMICALL","DEPT",$result_call)


GUISetState(@SW_SHOW)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $CANCEL
            ExitLoop
        Case $msg = $APPLY
            IniWrite ("C:\support.ini","CALL","DEPT",$result_call_angio)
            MsgBox(16, "Required", $result_call_angio)
            ExitLoop
    EndSelect
WEnd

Share this post


Link to post
Share on other sites
Valuater

Maybe..

While 1
                        $line = FileReadLine($call_list)
                        If @error =-1 Then ExitLoop
                        $xc = StringFormat("%s",$line)
                        $data &= $xc & "\"
                    WEnd
                    $data = StringTrimRight($data, 1)
                    GUICtrlSetData($calledit_combo_call, $data)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
BryonR

I tried the following code, however it only lists the first name in the list.txt file.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
$font = IniRead("c:\support.ini", "SiteInformation", "Font", "Times New Roman")
$editcallgui = GUICreate("My GUI test", 400, 400)
$APPLY = GUICtrlCreateButton("Apply", 1, 360, 129, 33, 0)
$message = GUICtrlCreateButton("test", 1, 50, 129, 33, 0)
$CANCEL = GUICtrlCreateButton("CANCEL", 270, 360, 129, 33, 0)
$editcall_lbl_call = GUICtrlCreateLabel("dept1", 20, 150, 200, 50)
GUICtrlSetFont(-1, 12, 400, 0, $font)
GUICtrlSetColor(-1, 0x000080)
$call_list = FileOpen("c:\list.txt", 0)
$call = IniRead("c:\support.ini", "CALL", "dept1", "Default")

$calledit_combo_call = GUICtrlCreateCombo($call, 200, 150, 200, 120)
If $call_list = -1 Then
    MsgBox(0, "Error", "Call file not built.")
    Exit
EndIf

While 1
    $line = FileReadLine($call_list)
    If @error = -1 Then ExitLoop
    $xc = StringFormat("%s", $line)
    $data = $xc & "\"
    WEnd
$data = StringTrimRight($data, 1)
GUICtrlSetData($calledit_combo_call, $data)
FileClose($call_list)
$result_call = GUICtrlRead($calledit_combo_call, $data)
IniWrite("c:\support.ini", "CALL", "dept1", $result_call)

Share this post


Link to post
Share on other sites
Valuater

Sorry, I was unable to test, it should be

$data &= $xc & "|"

8)

EDIT.... This will not work

$result_call = GUICtrlRead($calledit_combo_call, $data)

IniWrite("c:\support.ini", "CALL", "dept1", $result_call)

EDIT 2... This might do what you wanted

$result_call = $call & "|" & $data

IniWrite("c:\support.ini", "CALL", "dept1", $result_call)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
BryonR

How do I get the value of the combo box to wite to the ini?

Sorry, I was unable to test, it should be

$data &= $xc & "|"

8)

EDIT.... This will not work

$result_call = GUICtrlRead($calledit_combo_call, $data)

IniWrite("c:\support.ini", "CALL", "dept1", $result_call)

EDIT 2... This might do what you wanted

$result_call = $call & "|" & $data

IniWrite("c:\support.ini", "CALL", "dept1", $result_call)

Share this post


Link to post
Share on other sites
Valuater

This will get 1 selected item from the combobox

$Combo_Read = GUICtrlRead($calledit_combo_call)

IniWrite("c:\support.ini", "CALL", "dept1", $Combo_Read)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
BryonR

I must be missing something ^_^

I still can't get the item I've selected in the combo box to populate a var. It's always selecting the last item in the text file.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
$font = IniRead("c:\support.ini", "SiteInformation", "Font", "Times New Roman")
$editcallgui = GUICreate("My GUI test", 400, 400)
$APPLY = GUICtrlCreateButton("Apply", 1, 360, 129, 33, 0)
$message = GUICtrlCreateButton("test", 1, 50, 129, 33, 0)
$CANCEL = GUICtrlCreateButton("CANCEL", 270, 360, 129, 33, 0)
$editcall_lbl_call = GUICtrlCreateLabel("dept1", 20, 150, 200, 50)
GUICtrlSetFont(-1, 12, 400, 0, $font)
GUICtrlSetColor(-1, 0x000080)
$call_list = FileOpen("c:\list.txt", 0)
$call = IniRead("c:\support.ini", "CALL", "dept1", "Default")

$calledit_combo_call = GUICtrlCreateCombo($call, 200, 150, 200, 120)
If $call_list = -1 Then
    MsgBox(0, "Error", "Call file not built.")
    Exit
EndIf

While 1
    $line = FileReadLine($call_list)
    If @error = -1 Then ExitLoop
    $xc = StringFormat("%s", $line)
    $data = $xc & "\"
    GUICtrlSetData($calledit_combo_call, $data)
    WEnd
$data = StringTrimRight($data, 1)
FileClose($call_list)
$result_call = GUICtrlRead($calledit_combo_call, $data)
IniWrite("c:\support.ini", "CALL", "dept1", $result_call)


GUISetState(@SW_SHOW)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $CANCEL
            ExitLoop
        Case $msg = $APPLY
            IniWrite("c:\support.ini", "CALL", "dept1", $result_call)
            ExitLoop
        Case $msg = $message
            MsgBox(16, "Required", $data)
            endSelect
WEnd

Share this post


Link to post
Share on other sites
Melba23

BryonR,

You are only reading the combo immediately after it is created - hence $result_call always holds the default value.

Try moving "$result_call = GUICtrlRead($calledit_combo_call, $data)" to within the "Case $msg = $APPLY" code so that you get the actual value when you press the button. The relevant section of your script should read like this:

FileClose($call_list)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $CANCEL
            ExitLoop
        Case $msg = $APPLY
            $result_call = GUICtrlRead($calledit_combo_call, $data)
            IniWrite"c:\support.ini", "CALL", "dept1", $result_call)
            ExitLoop

With a test file I created in place of "c:\list.txt", this code gets the selected combo item into the ini file.

M23


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
BryonR

I'm a moron... thank you both.

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  

×