curly
Full Member
Posts: 161
|
Post by curly on Jan 16, 2021 11:03:07 GMT -5
I'm using a mix of text boxes and combo boxes. Each combo box has an array with values to select from, but sometimes it is more convenient to type a value rather than select it from the list, but I then can't assign the visible content to a variable. Is it something to do with 'doubleclick' being part of the combo box description?
|
|
|
Post by Walt Decker on Jan 16, 2021 12:35:54 GMT -5
I think this should do it:
print #handle.ext, "contents? text$"
If I correctly understand the help, the above should retrieve the edit box portion of the combo box and place it into text$.
|
|
|
Post by Brandon Parker on Jan 16, 2021 15:57:21 GMT -5
Here is a brief example that allows you to add data from the TextBox portion of the ComboBox to the array associated with the ComboBox. All you have to do is type in something into the TextBox portion, hit the "Add New" button, and the program will add that text to the end of the array.
NoMainWin Global arrayUBound : arrayUBound = 4
For i = 0 To arrayUBound a$(i) = "Number ";i Next i
Button #win.btnAddNew, "Add New", btnPress, UL, 10, 40 ComboBox #win.combo, a$(), doCombo, 10, 10, 120, 200 Open "Combobox Demo" For Window As #win #win "TrapClose Quit" #win.combo "SelectIndex 1" Wait
Sub Quit handle$ Close #handle$ End End Sub
Sub doCombo handle$ #handle$ "Selection? sel$" Notice "You chose ";sel$ End Sub
Sub btnPress handle$ ReDim temp$(arrayUBound) For i = 0 To arrayUBound temp$(i) = a$(i) Next i arrayUBound = (arrayUBound + 1) ReDim a$(arrayUBound) For i = 0 To (arrayUBound - 1) a$(i) = temp$(i) Next i #win.combo "Contents? newText$" a$(arrayUBound) = newText$ ReDim temp$(-1) #win.combo "Reload" End Sub[/codee]
{:0)
Brandon Parker
|
|
curly
Full Member
Posts: 161
|
Post by curly on Jan 18, 2021 6:07:50 GMT -5
Thank you both very much
|
|
curly
Full Member
Posts: 161
|
Post by curly on Jan 18, 2021 7:04:47 GMT -5
Hi guys, I'm afraid I'm still struggling with this one - I have an assortment of combo and text boxes and tab through them in order, typing into text boxes and selecting from fixed arrays in combo boxes. If the data to go into a combobox is something simple like a single letter, it is quicker to hit the letter on the keyboard rather then scroll down the list, but the combobox doesn't appear to see the letter? Is there a simple way to assign whatever is in the combobox to a string variable irrespective how it got there? Thank you for your efforts and sorry I'm so dumb.
|
|
|
Post by Rod on Jan 18, 2021 9:50:58 GMT -5
A combobox does not have that capability. It is designed to list an array and for the user to select an item by double click or optionally single click.
It is not really designed for text input, the main stumbling block is that there is no event created when text is entered. That is why we have shown you solutions using an additional button to create the read event.
The initial alpha selection is a listbox function, combobox does not have that capability either.
nomainwin a$(1) = "one" a$(2) = "two" a$(3) = "three" a$(4) = "four" listbox #win.list, a$(),[dolist],10,10,120,200 open "listbox Demo" for window as #win #win "trapclose [quit]" #win.list "selectindex 1" #win.list "setfocus" wait
[quit] close #win end
[dolist] #win.list "selection? sel$" notice "You chose ";sel$ wait
|
|
|
Post by tsh73 on Jan 18, 2021 10:56:12 GMT -5
Actually, textbox/texteditor has no such events either. We could check text entered in a timer event say once in 100 or 200 ms... But again, JB has no way to tell which control has focus. which would be very handy just for this.
So you have to craft your interface from tools language gives you. Or switch to language with bigger toolset.
|
|
|
Post by Walt Decker on Jan 18, 2021 12:08:43 GMT -5
Actually, textbox/texteditor has no such events either. We could check text entered in a timer event say once in 100 or 200 ms... But again, JB has no way to tell which control has focus. which would be very handy just for this. So you have to craft your interface from tools language gives you. Or switch to language with bigger toolset.
Actually there is a way to : 1. Find which control has the focus 2. Get the text but you have to use User32.dll to do it
CALLDLL #User32, "GetFocus", Focus AS ULONG
CALLDLL #User32, "SendMessageA", Focus AS ULONG, _WM_GETTEXTLENLENGTH, 0, 0, NumChars AS LONG
CALLDLL #User32, "SendMessageA", Focus AS ULONG, _WM_GETTEXT, NumChar AS LONG, TxtIn$ AS STRUCT, RetVal AS VOID
TxtIn$ must be sized at least as large as NumChars + 1
TxtIn$ must be sized large enough to accept the text.
|
|
curly
Full Member
Posts: 161
|
Post by curly on Jan 18, 2021 12:27:40 GMT -5
Thank you all so much, but it looks like entering free text is not a starter with so many comboboxes, therefore is it possible to stop text being entered directly into a combobox?
|
|
|
Post by Walt Decker on Jan 18, 2021 12:47:46 GMT -5
Not directly; however you might try: print #handle.ext, "contents? text$"
This retrieves the contents of the text field of the combobox into the variable called text$.
print #handle.ext, "!contents text$"
This command sets the contents of the field part of the combobox to the string after the !.
And set text$ to ""
However, you will have to continually query the combobox for input via a timer function. There is a problem. That approach eliminates all text from being inserted into the edit portion of the combobox. That means if a user selects an item from the combobox body it will not show up in the edit portion of the combobox.
A better way is to: 1. use CALLDLL #User32, "GetFocus", Focus AS ULONG 2. Check Focus to see if it matches the handle of the combobox 3. CALLDLL,#User32, Focus AS ULONG, _WM_GETTEXTLENGTH, 0, 0, NumChars AS LONG 4. Set TxtIn$ to NumChars + 1
5. CALLDLL #User32, Focus AS ULONG, _WM_GETTEXT, NumChars AS LONG, TxtIn$ AS STRUCT, R AS VOID
6. Scan the body of the combobox for a match or partial match 7. If match is found, set edit portion of combobox to the match
|
|
|
Post by Rod on Jan 18, 2021 13:19:32 GMT -5
I am not sure there is a need to stop users entering text. They are unlikely to do so and it would be ignored in any case.
I think that typing A is just as much trouble as clicking A. Making a mouse selection is normal.
However if you have a massive list and you want to show segments of that list for selection this is one way. The user should be instructed to key in a fragment of what they seek. But we don't really know what data you are collating so it may be of little interest.
dim array$(10) array$(1)="apple" array$(2)="car" array$(3)="cat" array$(4)="cement" array$(5)="dog" array$(6)="pavement" items=6 nomainwin WindowWidth = 500 WindowHeight = 400 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) statictext #main.search, "Enter your search", 80, 20, 244, 20 textbox #main.textbox, 80, 40, 300, 20 listbox #main.listbox, temparray$(), [update],80, 65, 300, 200 open "User Input" for window as #main #main "trapclose [quit]" #main "font ariel 10"
#main.textbox "!setfocus" #main.listbox "singleclickselect" #main.listbox "font ariel 10" timer 250, [search] wait
[search] timer 0 #main.textbox "!contents? text$" dim temparray$(items) found=1 for n= 1 to items if instr(array$(n),text$,1)>0 then temparray$(found)=array$(n) :found=found+1 next #main.listbox "reload" timer 250, [search] wait
[update] timer 0 #main.listbox "setfocus" #main.listbox "selectionindex? i" #main.listbox "selection? choice$" notice "You choose ";choice$
[quit] timer 0 close #main end
|
|