Jump to content

Create inputbox based on ComboBox contents with modification


Go to solution Solved by jeepjep,

Recommended Posts

Posted

Long time stalker first time poster!  I have been struggling with this for a while and finally caved and have to ask for help.  I have a combobox that I am reading data from successfully and getting the total items just fine.  What I am trying to do is add a number in front of each of the items  from the combobox inside my inputbox for the user to select from numerically.  

meat of the code that accomplishes this along with a screen shot showing the results and what I want it to look like.  At the top of the image you can see that I have 1-5 (the 5 is the $count) to get the total items.  I wrote on the image showing what I would like those lines to look like.  Thanks for any insight, I searched but could not find what I was looking for :(

autoitwhatIwantittolooklike.jpg.7e0a2927b30aeca2a45aba82458c3067.jpg

$var = ControlGetHandle("Student Transportation Information", "&To School Of Attendance", "ComboBox2")
        $count = _GUICtrlComboBox_GetCount($var)


        $choose = InputBox("Bell", "Choose Bell time: Type number based on line number: (1-" & $count & ")" & @LF & @LF & _GUICtrlComboBox_GetList($var)

Posted (edited)
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; Assumming that you are loading data from an array or something
Local $aItems[] = ['9:20 AM, MTWUF', '1:00 AM, MTWUF', '4:00 AM, MTWUF', '8:20 AM, MTWUF', '10:00 PM, MTWUF']

Global $hMain = GUICreate('Example')
Global $cCombo = GUICtrlCreateCombo('', 100, 100, 200, 20)
Global $hCombo = GUICtrlGetHandle($cCombo)
Global $cButton = GUICtrlCreateButton('Read combo', 150, 200, 100, 30)
For $Index = 0 To UBound($aItems) - 1
    GUICtrlSetData($cCombo, ($Index + 1) & ' - ' & $aItems[$Index])
Next
GUISetState(@SW_SHOW, $hMain)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            $sComboValue = StringRegExpReplace(GUICtrlRead($cCombo), '\d+ \- (.*)', '$1')
            MsgBox(0, '', $sComboValue)
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
        #forceref $hWnd, $iMsg
        If $lParam = $hCombo And BitShift($wParam, 16) = $CBN_EDITCHANGE Then
            _GUICtrlComboBox_AutoComplete($hCombo)
        EndIf
        Return $GUI_RUNDEFMSG
EndFunc

What I don't understand it's if you want this from a ComboBox or an InputBox.

Edited by Andreik
Posted

Thanks Nine and Andreik.  Nine, sorry yes that would have been probably more helpful.  My project is at work and will post tomorrow, but it is reading from a combobox in our work environment, so that may be difficult.

 

Just basically trying to read a combobox, and then take the combobox items and put them into an inputbox but put a number in front of them.  The combobox will have different data and qty of items depending on what the user is looking at.  I was looking at an array, but could not figure out how to incorporate that into an inputbox.

I could be explaining this all wrong too :/

  • Solution
Posted

I managed to get it working.  It was not pretty code, but it works.  I created an array of the combobox, then concatenated my numeric variable to the beginning of each item and stored it in my concatenated variable.

not runnable code but the meat and potatoes of the section.  I was not creating a combobox, I was reading from an existing combobox and trying to display that information in an inputbox.

still probably not clear to someone I am trying to explain to, but I got it working.  I appreciated the input and will try to be more clear on my issue next time!

        $var = ControlGetHandle("Student Information", "&To School Of Attendance", "ComboBox2") ;handle to combobox
        $count = _GUICtrlComboBox_GetCount($var) ;get the count in the combobox


        Local $array[$count + 1 ] 
        $test = _GUICtrlComboBox_GetListArray($var) ; testing

        Local $Concatenated = ""



        $x = 1
        $i = 0
            For $loop = 1 To $count ;5
                $array[$i] = $x & ": " & $test[$x]
                $Concatenated &= $array[$i] & @CRLF  ;testing stringing together appended number and combobox item
                $x = $x + 1 ; not pretty but works
                $i = $i + 1 ; not pretty but works
           Next


        $choose = InputBox("Bell", "Choose Bell time: Type number based on line number: (1-" & $count & ")" & @LF & @LF & $Concatenated & @LF & @LF & "________________________________________________________" & @LF & "Informational Section Only, Number input based on times ABOVE line" & @LF & @LF & $program, $default, "", 525, 375)
        If @error = 1 Then
            $cancelpressed = 1
            Return
        EndIf

 

Posted (edited)

This

$x = 1
$i = 0
For $loop = 1 To $count ;5
    $array[$i] = $x & ": " & $test[$x]
    $Concatenated &= $array[$i] & @CRLF  ;testing stringing together appended number and combobox item
    $x = $x + 1 ; not pretty but works
    $i = $i + 1 ; not pretty but works
Next

can be this

For $loop = 1 To $count ;5
    $array[$loop - 1] = $loop & ": " & $test[$loop]
    $Concatenated &= $array[$loop - 1] & @CRLF 
Next

 

Edited by Andreik
Posted

This

For $loop = 1 To $count ;5
    $array[$loop - 1] = $loop & ": " & $test[$loop]
    $Concatenated &= $array[$loop - 1] & @CRLF 
Next

can be this

For $loop = 1 To $count ;5
    $Concatenated &= $loop & ": " & $test[$loop] & @CRLF 
Next

 

Some guy's script + some other guy's script = my script!

Posted (edited)

Doesnt seem to, he creates it here...

Local $array[$count + 1 ]

Looks like he created it just for this, which isnt needed. Though he may ofcourse use it later, dunno. 😛

Edited by Werty

Some guy's script + some other guy's script = my script!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...