jeepjep Posted February 22, 2024 Posted February 22, 2024 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 :( $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)
Nine Posted February 22, 2024 Posted February 22, 2024 Please provide a runable script that show the problem. It will greatly help us to help you... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Andreik Posted February 22, 2024 Posted February 22, 2024 (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 February 22, 2024 by Andreik
nnps Posted February 23, 2024 Posted February 23, 2024 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 :/
Andreik Posted February 23, 2024 Posted February 23, 2024 Now I am even more confused. We really need to see your code.
Solution jeepjep Posted February 23, 2024 Author Solution Posted February 23, 2024 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
Andreik Posted February 23, 2024 Posted February 23, 2024 (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 February 23, 2024 by Andreik
Werty Posted February 23, 2024 Posted February 23, 2024 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!
Werty Posted February 23, 2024 Posted February 23, 2024 (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 February 23, 2024 by Werty Some guy's script + some other guy's script = my script!
Andreik Posted February 23, 2024 Posted February 23, 2024 It's an incomplete function, assume the worst or he will come back saying that something doesn't work.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now