Sign in to follow this  
Followers 0
5t0n3r

ComboBox: Function returning "0" instead of selection in combo box

9 posts in this topic

I have a function withing a larger program that all it returns is "0". This is probably easy to figure out, but I can't seem to see the forest through the trees here.

Any help would be appreciated, thanks!

$reported_by = _reported_by()
MsgBox(0, "Test", $reported_by)

Func _reported_by()
    Local $sName
    $sName = GUICtrlCreateCombo("", 130, 415, 160, "", -1)
    GUICtrlSetData(-1, "Name 1|Name 2|Name 3|Name 4", "Name 1")
    Return GUICtrlRead($sName)
EndFunc

Share this post


Link to post
Share on other sites



You have to create a GUI first. Take a look at the help file for GUICtrlCreateCombo. Look at example at the bottom of the page. Also take a look at GUICreate in the help file.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

I already have the GUI created. Just a bit too big to put in here.

I'm looking to get this function working, then will put it back into the larger program.

So far, I can't see why it's not working.

Share this post


Link to post
Share on other sites

Dunno, works fine.

$gui = GUICreate("test")
$sName = GUICtrlCreateCombo("", 10, 10, 160, "", -1)
GUICtrlSetData(-1, "Name 1|Name 2|Name 3|Name 4", "Name 1")
$button = GUICtrlCreateButton("show", 10, 50)
GUISetState()

Do
    $msg = GUIGetMsg()
    Switch $msg
        Case $button
            ConsoleWrite(GUICtrlRead($sName) & @CRLF)
    EndSwitch
Until $msg = -3

Are you creating the GUI controls in weird places with incorrect Local/Global scope? Colliding variable names maybe?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Okay, here's the whole script. If I use $gui = GUICreate("test") within the function, it messes up the original script.

Sorry, I'm learning as I go and this is stumping me.

#include <ButtonConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("TrayMenuMode",1)
TraySetToolTip("Add / Remove Employee")
TraySetState()

$gui = GUICreate("Add / Remove Employee Process", 650, 700)
$tab = GUICtrlCreateTab(-10, -22, 665, 725)

; Main Menu Page
$main1Page1 = GUICtrlCreateTabItem("mainmenu1")
$main1Btn1 = GUICtrlCreateButton("New Employee", 125, 100, 150, 60)
$main1Btn2 = GUICtrlCreateButton("Terminated Employee", 350, 100, 150, 60)
GUICtrlCreateLabel("Choose this option for the" & @CRLF & "New Employee checklist.", 130, 200)
GUICtrlCreateLabel("Choose this option for the" & @CRLF & "Terminated Employee checklist.", 355, 200)
GUICtrlCreateLabel("Save output file to: ", 130, 355)
$savepath = GUICtrlCreateInput("",130,370,300,20)
$browse = GUICtrlCreateButton("Browse", 432,369,50,22)
GUICtrlCreateLabel("Report created by:", 130, 400)
$reported_by = _reported_by()
; End Main Menu page

Func _reported_by()
    $sName = GUICtrlCreateCombo("", 130, 415, 160, "", -1)
    GUICtrlSetData(-1, "Tech 1|Tech 2|Tech 3|Tech 4", "Tech 1")
    Return GUICtrlRead($sName)
EndFunc


; New Employee Page 1
$new1Page1 = GUICtrlCreateTabItem("new_employee_p1")
$newGroup1 = GUICtrlCreateGroup("New Employee - Network Permissions - Page [1/7]", 8, 10, 635, 645)
$new1Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$new1Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
; Option 1 Data
GUICtrlCreateLabel("1)  Has the user been added to Active Directory?", 30, 50)
$new1Radio1 = GUICtrlCreateRadio("Yes", 50, 80, 120, 20)
$new1Radio2 = GUICtrlCreateRadio("No", 50, 100, 120, 20)
$new1Radio3 = GUICtrlCreateRadio("N/A", 50, 120, 120, 20)
$new1Label1 = GUICtrlCreateLabel ("Date Added?", 180, 80, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetFont (-1,10)
$new1Input1 = GUICtrlCreateDate("", 180, 100, 150, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$new1Label2 = GUICtrlCreateLabel ("Click the button to add the user to Active Directory.", 180, 80, 400, 20)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetFont (-1,10)
$new1Input2 = GUICtrlCreateButton ("Active Directory Users and Computers", 180, 100, 200, 30)
GUICtrlSetState(-1, $GUI_HIDE)
; End Option 1 Data
; End New Employee Page 1

; New Employee Page 2
$new2Page1 = GUICtrlCreateTabItem("new_employee_p2")
$newGroup1 = GUICtrlCreateGroup("New Employee - [2/7]", 8, 10, 635, 645)
$new2Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$new2Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
GUICtrlCreateLabel("New Employee Page 2", 100, 200)
; End New Employee Page 2

; New Employee Page 3
$new3Page1 = GUICtrlCreateTabItem("new_employee_p3")
$newGroup1 = GUICtrlCreateGroup("New Employee - [3/7]", 8, 10, 635, 645)
$new3Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$new3Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
GUICtrlCreateLabel("New Employee Page 3", 100, 200)
; End New Employee Page 3

; New Employee Page 4
$new4Page1 = GUICtrlCreateTabItem("new_employee_p4")
$newGroup1 = GUICtrlCreateGroup("New Employee - [4/7]", 8, 10, 635, 645)
$new4Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$new4Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
GUICtrlCreateLabel("New Employee Page 4", 100, 200)
; End New Employee Page 4

; New Employee Page 5
$new5Page1 = GUICtrlCreateTabItem("new_employee_p5")
$newGroup1 = GUICtrlCreateGroup("New Employee - [5/7]", 8, 10, 635, 645)
$new5Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$new5Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
GUICtrlCreateLabel("New Employee Page 5", 100, 200)
; End New Employee Page 5

; New Employee Page 6
$new6Page1 = GUICtrlCreateTabItem("new_employee_p6")
$newGroup1 = GUICtrlCreateGroup("New Employee - [6/7]", 8, 10, 635, 645)
$new6Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$new6Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
GUICtrlCreateLabel("New Employee Page 6", 100, 200)
; End New Employee Page 6

; New Employee Page 7
$new7Page1 = GUICtrlCreateTabItem("new_employee_p7")
$newGroup1 = GUICtrlCreateGroup("New Employee - [7/7]", 8, 10, 635, 645)
$new7Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$new7Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
$new7Finish1 = GUICtrlCreateButton("Finish", 260, 195, 75, 25)
$final_exit = GUICtrlCreateButton("Exit", 560, 600, 75, 25)
GUICtrlCreateLabel("New Employee Page 7", 100, 200)
; End New Employee Page 7

;==================================================================

; Terminated Employee Page 1
$ter1Page1 = GUICtrlCreateTabItem("ter_employee_page1")
$terGroup2 = GUICtrlCreateGroup("Terminated Employee - [1/7]", 8, 10, 635, 645)
$ter1Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$ter1Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
; Option 1 Data
GUICtrlCreateLabel("1)  Has the user been disabled or removed from Active Directory?", 30, 50)
$ter1Radio1 = GUICtrlCreateRadio("Yes", 50, 80, 120, 20)
$ter1Radio2 = GUICtrlCreateRadio("No", 50, 100, 120, 20)
$ter1Radio3 = GUICtrlCreateRadio("N/A", 50, 120, 120, 20)
$ter1Label1 = GUICtrlCreateLabel ("Date Disabled/Removed?", 180, 80, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetFont (-1,10)
$ter1Input1 = GUICtrlCreateDate("", 180, 100, 150, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$ter1Label2 = GUICtrlCreateLabel ("Click the button to disable/remove the user from Active Directory.", 180, 80, 400, 20)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetFont (-1,10)
$ter1Input2 = GUICtrlCreateButton ("Active Directory Users and Computers", 180, 100, 200, 30)
GUICtrlSetState(-1, $GUI_HIDE)
; End Option 1 Data
; End Terminated Employee Page 1

; Terminated Employee Page 2
$ter2Page1 = GUICtrlCreateTabItem("ter_employee_page2")
$terGroup2 = GUICtrlCreateGroup("Terminated Employee - [2/7]", 8, 10, 635, 645)
$ter2Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$ter2Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
GUICtrlCreateLabel("Terminated Employee Page 2", 100, 200)
; End Terminated Employee Page 2

; Terminated Employee Page 3
$ter3Page1 = GUICtrlCreateTabItem("ter_employee_page3")
$terGroup2 = GUICtrlCreateGroup("Terminated Employee - [3/7]", 8, 10, 635, 645)
$ter3Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$ter3Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
GUICtrlCreateLabel("Terminated Employee Page 3", 100, 200)
; End Terminated Employee Page 3

; Terminated Employee Page 4
$ter4Page1 = GUICtrlCreateTabItem("ter_employee_page4")
$terGroup2 = GUICtrlCreateGroup("Terminated Employee - [4/7]", 8, 10, 635, 645)
$ter4Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$ter4Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
GUICtrlCreateLabel("Terminated Employee Page 4", 100, 200)
; End Terminated Employee Page 4

; Terminated Employee Page 5
$ter5Page1 = GUICtrlCreateTabItem("ter_employee_page5")
$terGroup2 = GUICtrlCreateGroup("Terminated Employee - [5/7]", 8, 10, 635, 645)
$ter5Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$ter5Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
GUICtrlCreateLabel("Terminated Employee Page 5", 100, 200)
; End Terminated Employee Page 5

; Terminated Employee Page 6
$ter6Page1 = GUICtrlCreateTabItem("ter_employee_page6")
$terGroup2 = GUICtrlCreateGroup("Terminated Employee - [6/7]", 8, 10, 635, 645)
$ter6Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$ter6Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
GUICtrlCreateLabel("Terminated Employee Page 6", 100, 200)
; End Terminated Employee Page 6

; Terminated Employee Page 7
$ter7Page1 = GUICtrlCreateTabItem("ter_employee_page7")
$terGroup2 = GUICtrlCreateGroup("Terminated Employee - [7/7]", 8, 10, 635, 645)
$ter7Back1 = GUICtrlCreateButton("< Back", 400, 660, 75, 25)
$ter7Next1 = GUICtrlCreateButton("Next >", 475, 660, 75, 25)
$ter7Finish1 = GUICtrlCreateButton("Finish", 260, 195, 75, 25)
GUICtrlCreateLabel("Terminated Employee Page 7", 100, 200)
; End Terminated Employee Page 7

;==================================================================

GUICtrlCreateTabitem ("")
$cancel = GUICtrlCreateButton("Cancel", 560, 660, 75, 25)
GUICtrlSetState($main1Page1, $GUI_SHOW)
GUICtrlSetState($new7Next1, $GUI_DISABLE)
GUICtrlSetState($ter7Next1, $GUI_DISABLE)
GUISetState()
Func _FileSaveDialog ($sTitle, $sInitDir, $sFilter = "Text Files (*.txt)|All Files (*.*)", $iOpt = 0, $sDefaultFile = "", $sDefaultExt = "", $mainGUI = 0)
   Local $iFileLen = 65536
   Local $iFlag = BitOR(BitShift(BitAND($iOpt, 2), -10), BitShift(BitAND($iOpt, 16), 3))
   Local $asFLines = StringSplit($sFilter, '|'), $asFilter[$asFLines[0] * 2 + 1]
   Local $i, $iStart, $iFinal, $suFilter = '', $ret

   $asFilter[0] = $asFLines[0] * 2
   For $i = 1 To $asFLines[0]
      $iStart = StringInStr($asFLines[$i], '(', 0, 1)
      $iFinal = StringInStr($asFLines[$i], ')', 0, -1)
      $asFilter[$i * 2 - 1] = $asFlines[$i]
      $asFilter[$i * 2] = StringStripWS(StringTrimRight(StringTrimLeft($asFLines[$i], $iStart), StringLen($asFLines[$i]) - $iFinal + 1), 3)
      $suFilter = $suFilter & 'byte[' & StringLen($asFilter[$i * 2 - 1]) + 1 & '];byte[' & StringLen($asFilter[$i * 2]) + 1 & '];'
   Next
   Local $uOFN = DllStructCreate('dword;int;int;ptr;ptr;dword;dword;ptr;dword' & ';ptr;int;ptr;ptr;dword;short;short;ptr;ptr;ptr;ptr;ptr;dword;dword')
   Local $usTitle = DllStructCreate('byte[' & StringLen($sTitle) + 1 & ']')
   Local $usInitDir = DllStructCreate('byte[' & StringLen($sInitDir) + 1 & ']')
   Local $usFilter = DllStructCreate($suFilter & 'byte')
   Local $usFile = DllStructCreate('char[' & $iFileLen & ']')
   Local $usExtn = DllStructCreate('byte[' & StringLen($sDefaultExt) + 1 & ']')
   For $i = 1 To $asFilter[0]
      DllStructSetData($usFilter, $i, $asFilter[$i])
   Next
   DllStructSetData($usTitle, 1, $sTitle)
   DllStructSetData($usInitDir, 1, $sInitDir)
   DllStructSetData($usFile, 1, $sDefaultFile)
   DllStructSetData($usExtn, 1, $sDefaultExt)
   DllStructSetData($uOFN, 1, DllStructGetSize($uOFN))
   DllStructSetData($uOFN, 2, $mainGUI)
   DllStructSetData($uOFN, 4, DllStructGetPtr($usFilter))
   DllStructSetData($uOFN, 7, 1)
   DllStructSetData($uOFN, 8, DllStructGetPtr($usFile))
   DllStructSetData($uOFN, 9, $iFileLen)
   DllStructSetData($uOFN, 12, DllStructGetPtr($usInitDir))
   DllStructSetData($uOFN, 13, DllStructGetPtr($usTitle))
   DllStructSetData($uOFN, 14, $iFlag)
   DllStructSetData($uOFN, 17, DllStructGetPtr($usExtn))
   DllStructSetData($uOFN, 23, BitShift(BitAND($iOpt, 32), 5))
   $ret = DllCall('comdlg32.dll', 'int', 'GetSaveFileName', 'ptr', DllStructGetPtr($uOFN))
      If $ret[0] Then
         Return StringStripWS(DllStructGetData($usFile, 1), 3)
      Else
         SetError(1)
         Return ""
      EndIf
EndFunc

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        case $new1Radio1
            GUICtrlSetState($new1Label1, $GUI_SHOW)
            GUICtrlSetState($new1Input1, $GUI_SHOW)
            GUICtrlSetState($new1Label2, $GUI_HIDE)
            GUICtrlSetState($new1Input2, $GUI_HIDE)
            $new1Output1 = "Yes"
        case $new1Radio2
            GUICtrlSetState($new1Label1, $GUI_HIDE)
            GUICtrlSetState($new1Input1, $GUI_HIDE)
            GUICtrlSetState($new1Label2, $GUI_SHOW)
            GUICtrlSetState($new1Input2, $GUI_SHOW)
            $new1Output1 = "No"
        case $new1Radio3
            $new1Output1 = "N/A"
        case $ter1Radio1
            GUICtrlSetState($ter1Label1, $GUI_SHOW)
            GUICtrlSetState($ter1Input1, $GUI_SHOW)
            GUICtrlSetState($ter1Label2, $GUI_HIDE)
            GUICtrlSetState($ter1Input2, $GUI_HIDE)
        case $ter1Radio2
            GUICtrlSetState($ter1Label1, $GUI_HIDE)
            GUICtrlSetState($ter1Input1, $GUI_HIDE)
            GUICtrlSetState($ter1Label2, $GUI_SHOW)
            GUICtrlSetState($ter1Input2, $GUI_SHOW)
        case $new1Input2
            If FileExists(@SystemDir & "\dsa.msc") Then
                Run("mmc " & @SystemDir & "\dsa.msc", '',@SW_MAXIMIZE)
            Else
                MsgBox(0x30, "Unable to Launch Program", "Active Directory Users and Computers" & @CRLF & @CRLF & "This program was not found on this computer, please install the" & @CRLF & "Windows Server Administration Tools Pack to be able to have this functionality.")
            EndIf
        case $ter1Input2
            If FileExists(@SystemDir & "\dsa.msc") Then
                Run("mmc " & @SystemDir & "\dsa.msc", '',@SW_MAXIMIZE)
            Else
                MsgBox(0x30, "Unable to Launch Program", "Active Directory Users and Computers" & @CRLF & @CRLF & "This program was not found on this computer, please install the" & @CRLF & "Windows Server Administration Tools Pack to be able to have this functionality.")
            EndIf
        Case - 3
            $answer = MsgBox(32 + 4, "Exit Program", "Are you sure you want to EXIT the program?" & @CRLF & "Any unsaved information will be lost.")
            Switch $answer
                Case 6; Yes
                    Exit
                Case 7; No
            EndSwitch
        Case $cancel
            $answer = MsgBox(32 + 4, "Exit Program", "Are you sure you want to EXIT the program?" & @CRLF & "Any unsaved information will be lost.")
            Switch $answer
                Case 6; Yes
                    Exit
                Case 7; No
            EndSwitch
        Case $final_exit
            $answer = MsgBox(32 + 4, "Exit Program", "Are you sure?")
            Switch $answer
                Case 6; Yes
                    Exit
                Case 7; No
            EndSwitch
        Case $browse
            $sFile = _FileSaveDialog("Browse for file location", @DesktopDir)
            GUICtrlSetData($savepath, $sFile)
;==================================================================

        Case $main1Btn1
            GUICtrlSetState($new1Page1, $GUI_SHOW)
        Case $main1Btn2
            GUICtrlSetState($ter1Page1, $GUI_SHOW)


        Case $new1Back1
            GUICtrlSetState($main1Page1, $GUI_SHOW)
        Case $new1Next1
            GUICtrlSetState($new2Page1, $GUI_SHOW)
        Case $new2Back1
            GUICtrlSetState($new1Page1, $GUI_SHOW)
        Case $new2Next1
            GUICtrlSetState($new3Page1, $GUI_SHOW)
        Case $new3Back1
            GUICtrlSetState($new2Page1, $GUI_SHOW)
        Case $new3Next1
            GUICtrlSetState($new4Page1, $GUI_SHOW)
        Case $new4Back1
            GUICtrlSetState($new3Page1, $GUI_SHOW)
        Case $new4Next1
            GUICtrlSetState($new5Page1, $GUI_SHOW)
        Case $new5Back1
            GUICtrlSetState($new4Page1, $GUI_SHOW)
        Case $new5Next1
            GUICtrlSetState($new6Page1, $GUI_SHOW)
        Case $new6Back1
            GUICtrlSetState($new5Page1, $GUI_SHOW)
        Case $new6Next1
            GUICtrlSetState($new7Page1, $GUI_SHOW)
        Case $new7Back1
            GUICtrlSetState($new6Page1, $GUI_SHOW)
        Case $new7Finish1
       GUICtrlSetState($main1Page1, $GUI_SHOW)
        $label1 = "Has the User been added to Active Directory?"
        $label2 = "Reported By?"
        $sep1 = "==================================================="
        $nFO = FileOpen($sFile, 2)  ; 1 appends, 2 will overwrite
        FileWriteLine($nFO, $sep1)
        FileWriteLine($nFO, $label1 & " = " & $new1Output1)
        FileWriteLine($nFO, $sep1)
        FileWriteLine($nFO, $label2 & " = " & $reported_by)
        FileWriteLine($nFO, $sep1)
        FileCLose($nFO)

        Case $ter1Back1
            GUICtrlSetState($main1Page1, $GUI_SHOW)
        Case $ter1Next1
            GUICtrlSetState($ter2Page1, $GUI_SHOW)
        Case $ter2Back1
            GUICtrlSetState($ter1Page1, $GUI_SHOW)
        Case $ter2Next1
            GUICtrlSetState($ter3Page1, $GUI_SHOW)
        Case $ter3Back1
            GUICtrlSetState($ter2Page1, $GUI_SHOW)
        Case $ter3Next1
            GUICtrlSetState($ter4Page1, $GUI_SHOW)
        Case $ter4Back1
            GUICtrlSetState($ter3Page1, $GUI_SHOW)
        Case $ter4Next1
            GUICtrlSetState($ter5Page1, $GUI_SHOW)
        Case $ter5Back1
            GUICtrlSetState($ter4Page1, $GUI_SHOW)
        Case $ter5Next1
            GUICtrlSetState($ter6Page1, $GUI_SHOW)
        Case $ter6Back1
            GUICtrlSetState($ter5Page1, $GUI_SHOW)
        Case $ter6Next1
            GUICtrlSetState($ter7Page1, $GUI_SHOW)
        Case $ter7Back1
            GUICtrlSetState($ter6Page1, $GUI_SHOW)
        Case $ter7Finish1
            GUICtrlSetState($main1Page1, $GUI_SHOW)
    EndSwitch
WEnd
Edited by 5t0n3r

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Script works for me. The output file shows 'Tech 1'. Bear in mind the way you've written this right now, $reported_by is always equal to 'Tech 1' and the combo box in not accessible outside your function. Could just be a work in progress part of the script, if so nevermind.

In the same way, this works for me as well:

$gui = GUICreate("test")
ConsoleWrite(_Combo() & @CRLF)

Func _Combo()
    $sName = GUICtrlCreateCombo("", 10, 10, 160, "", -1)
    GUICtrlSetData(-1, "Name 1|Name 2|Name 3|Name 4", "Name 1")
    Return GUICtrlRead($sName)
EndFunc
Edited by wraithdu

Share this post


Link to post
Share on other sites

Definately is a work in progress. Always looking for a better way to code...

How would you suggest I add in the combobox so it will output the selected technician name in the text file?

Share this post


Link to post
Share on other sites

Well as I said, your current posted script DID work, I got the tech name in the file. But to fix what I noted, just move the creation of the combo out of the function and make it part of the normal GUI build process (not sure why you decided to put it in a function to begin with). The real problem is that creating the combo in the function puts the $sName variable in Local scope (since you did not specify either Local or Global, vars in a function get Local if it's the first time they are used). This means it is not accessible to read from anywhere else in your script. After fixing that, forget assigning the value of the combo to a var ($reported_by currently), especially not immediately after creation. You'll just get the initial value (currently 'Tech 1') and it'll be stuck there. You should GuiCtrlRead($sName) at the time you output the result to the file.

Share this post


Link to post
Share on other sites

Yeah, I see what you mean. I was trying to be creative and keep the amount of code down so it could be re-used later.

Darn my OCD! :D

I'll try what you suggested wraithdu. Thanks again for the help.

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