|
Post by alincon on Apr 7, 2020 15:12:56 GMT -5
I want to replace 6 check boxes with one multi-select list box. I have some code that worked in another instance, but does not work here. What am I doing wrong?
prefTbl$(1) = "Fem" : prefTbl$(2) ="Hcp" : prefTbl$(3) = "Dsb"
prefTbl$(4) = "Eld" : prefTbl$(5) ="Dpl" : prefTbl$(6) = "Adr"
WindowWidth = 200: WindowHeight = 200
UpperLeftX=Int((DisplayWidth-WindowWidth)/2)
listbox #tw.lbpref, prefTbl$(, [tntGetpref], 60,20,90,100
Stylebits #tb.lbpref, _LBS_MULTIPLESEL or _LBS_SORT, _LBS_DISABLENOSCROLL, 0, 0
button #tw.b1, "Accept", [tntAccept], UL, 340, 400, 70, 25
open "TENANT PROCESSING" for window as #tw
#tw, "trapclose [tntClose]"
hLB = hwnd(#tw.lbpref)
null = SendMessageA(hLB, _LB_SETSEL)', 1) ', m-1)
call itemsSelected, hLB
[tntLoop]
wait
sub itemsSelected hLB
itemsSel$ = ""
' isSel = SendMessageA(hLB, _LB_GETSEL, i - 1, nullParameter) 'i - 1 = Item Number (par1), no relevance (par2)
If isSel Then
itemsSel$ = itemsSel$ + "1"
else
itemsSel$ = itemsSel$ + "0"
End If
print hLB, itemsSel$, word$(matchNames$,m) 'not required; only for testing
x$ = x$ + itemsSel$ + "|"
end sub
sub clearAllItems hLB
allClear = SendMessageA(hLB, _LB_SETSEL, 0, -1) '0 (par1) = Flag to Clear, -1 (par2) = ALL
end sub
[tntClose]
call clearAllItems, hLB
close #tw
wait
insert code here
r.m.
|
|
|
Post by Brandon Parker on Apr 7, 2020 21:29:28 GMT -5
It looks like you need to send the third and fourth parameters to the SendMessageA() function when you want to select an item. LB_SETSELAssuming this is where you are attempting to select an item, you are missing the third and fourth parameters. null = SendMessageA(hLB, _LB_SETSEL)', 1) ', m-1) {:0) Brandon Parker
|
|
|
Post by alincon on Apr 9, 2020 9:42:39 GMT -5
When I try to run the pgm, I get this message: "array SendmessageA() is one dimensional" Can you get it to execute at all? r.m.
|
|
|
Post by Chris Iverson on Apr 9, 2020 11:01:09 GMT -5
SendMessageA is not a built-in LB function. It's a function provided as additional code somewhere. You have to make sure to include that function in your own code if you want to use it.
If that is based on code that previously worked, then it likely has a working copy of SendMessageA() you can use. Find it and copy it over.
|
|
|
Post by Rod on Apr 9, 2020 11:02:46 GMT -5
What does your SendmessageA( function look like? Is it named sendMessageA( SendMessageA( it clearly does not exist as SendmessageA( because liberty thinks you are accessing an undefined array where there should be a matching function name.
|
|
|
Post by alincon on Apr 9, 2020 19:18:03 GMT -5
Of course I did copy the code from the old program, but that program had 12(!) list boxes so I had to make loops Maybe my problem is cutting down the looping code for just one listbox I found these two calls: SendMessageA(hLB, _LB_SETSEL, 0, -1) '0 (par1) = Flag to Clear, -1 (par2) = ALL SendMessageA(hLB, _LB_GETSEL, i - 1, nullParameter)
nullParameter is defined in the program as zero r.m.
|
|
|
Post by Brandon Parker on Apr 9, 2020 19:33:49 GMT -5
I would assume that the SendMessageA() function is actually in the code. If it is not, then that needs to be added obviously.
That being said, LB will bark at the following code if the SendMessageA() function in his code is set up properly with the four variables. Notice the comment marker after "_LB_SETSEL)" ...
null = SendMessageA(hLB, _LB_SETSEL)', 1) ', m-1)
LB will see the above "function call" as an undimensioned two-dimensional array if there is no declared function that matches the function signature.
The code above should be changed to the following to select the first item in the ListBox.
null = SendMessageA(hLB, _LB_SETSEL), 1, 0)
Like I said if you do not have the SendMessageA() function then that is the issue, but otherwise you are calling the function incorrectly in the spot where you are trying to select an item.
{:0)
Brandon Parker
|
|
|
Post by metro on Apr 9, 2020 22:31:10 GMT -5
'Setting Multiple Selections and Getting Multiple Selections 'with SendMessageA API calls 'A special Thank You to Bill Beasley for getting this code started Dim itemArray$(20) For i = 1 to 20 itemArray$(i) = "Item Number ";Space$(i < 10);Str$(i) Next i nullParameter = 0 'Used as filler when parameter irrelevant Nomainwin WindowWidth = 400 WindowHeight = 360 UpperLeftX = Int((DisplayWidth - WindowWidth)/2) UpperLeftY = Int((DisplayHeight - WindowHeight)/2) Listbox #main.lb, itemArray$(), [selectItem], 20, 20, 140, 200 '_LBS_MULTIPLESEL = Multiple Single Selections using Left Click Stylebits #main.lb, _LBS_MULTIPLESEL, 0, 0, 0 '_LBS_EXTENDEDSEL = Multiple Single Selections using Ctrl - Left Click as well as 'selection of a range of items using Shift - Left Click 'Stylebits #main.lb, _LBS_EXTENDEDSEL, 0, 0, 0 Statictext #main.st, "", 20, 230, 350, 100 Button #main.b1, "Count Items Selected", [nItemsSelected], UL, 190, 40, 170, 32 Button #main.b2, "List Items Selected", [listItemsSelected], UL, 190, 85, 170, 32 Button #main.b3, "Select All Items", [selectAllItems], UL, 190, 130, 170, 32 Button #main.b4, "Clear All Items", [clearAllItems], UL, 190, 175, 170, 32 Open "Listbox Multi Select" for Window as #main #main "Trapclose [endDemo]" #main "Font Times_New_Roman 12 Bold" hLB = hwnd(#main.lb) 'Select some items For i = 1 to 20 step 3 null = SendMessageA(hLB, _LB_SETSEL, 1, i) Next i #main.st "Every 3rd Item is Selected" Wait [selectItem] 'No action necessary Wait [nItemsSelected] nItemsSelected = SendMessageA(hLB, _LB_GETSELCOUNT, nullParameter, nullParameter) 'no relevance (par1), (par2) #main.st "There are ";nItemsSelected;" items selected." Wait
[listItemsSelected] itemsSel$ = "" For i = 1 to 20 isSel = SendMessageA(hLB, _LB_GETSEL, i - 1, nullParameter) 'i - 1 = Item Number (par1), no relevance (par2) If isSel Then itemsSel$ = itemsSel$;itemArray$(i);", " End If Next i itemsSel$ = Left$(itemsSel$, Len(itemsSel$) - 2) #main.st itemsSel$ Wait
[selectAllItems] allSel = SendMessageA(hLB, _LB_SETSEL, 1, -1) ' 1 (par1) = Flag to Set, -1 (par2) = ALL Wait
[clearAllItems] allClear = SendMessageA(hLB, _LB_SETSEL, 0, -1) '0 (par1) = Flag to Clear, -1 (par2) = ALL Wait
[endDemo] Close #main End
Function SendMessageA(hW, msg, par1, par2) CallDLL #user32, "SendMessageA",_ hW as Ulong, _ 'Handle of the control (listbox) msg as Long, _ 'Stylebits (Windows Constant) par1 as Long, _ 'Parameter 1 (sometimes irrelevant) par2 as Long, _ 'Parameter 2 (sometimes irrelevant) SendMessageA as long 'Return Value, 1 = success End Function
|
|
|
Post by alincon on Apr 10, 2020 10:02:47 GMT -5
Metro seems to have what I need. It will take me some time to work my way thru the code and apply it to my situation. Thanks to the others who have contributed. r.m.
|
|
|
Post by alincon on Apr 10, 2020 10:52:16 GMT -5
Metro's code works fine. But I need to record which items were selected and store that data to a file, say as ones and zeros. Then, later, I need recall the stored data and select the corresponding items in the listbox. I hope there is another call to do that.
r.m.
|
|
|
Post by metro on Apr 10, 2020 20:09:50 GMT -5
Metro's code works fine. But I need to record which items were selected and store that data to a file, say as ones and zeros. Then, later, I need recall the stored data and select the corresponding items in the listbox. I hope there is another call to do that. r.m. a couple of changes to your code, see stylebits for for original problem wrong handle for the stylebits (and the missing function). I also started the prefTbl$() array from zero ..................HTH prefTbl$(0) = "Fem" : prefTbl$(1) ="Hcp" : prefTbl$(2) = "Dsb" prefTbl$(3) = "Eld" : prefTbl$(4) ="Dpl" : prefTbl$(5) = "Adr" nullParameter = 0 'Used as filler when parameter irrelevant WindowWidth = 200: WindowHeight = 200 UpperLeftX=Int((DisplayWidth-WindowWidth)/2)
listbox #tw.lbpref, prefTbl$(), [tntGetpref], 60,20,90,100 ' Stylebits #tb.lbpref, _LBS_MULTIPLESEL or _LBS_SORT, _LBS_DISABLENOSCROLL, 0, 0 Stylebits #tw.lbpref, _LBS_MULTIPLESEL,0,0,0
button #tw.b1, "Accept", [tntLoop], UL, 65, 130, 70, 25 open "TENANT PROCESSING" for window as #tw #tw, "trapclose [tntClose]" ' #tw.lbpref, "singleclickselect" hLB = hwnd(#tw.lbpref) 'null = SendMessageA(hLB, _LB_SETSEL, 1 , 2) ' call itemsSelected, hLB ' #main.st "Every 3rd Item is Selected" wait [tntGetpref] notice "Please only single click items" ' YOU COULD JUST WAIT, no action [tntLoop] call itemsSelected hLB wait sub selectitem hLB
end sub
sub itemsSelected hLB itemsSel$ = "" for i= 0 to 5 isSel = SendMessageA(hLB, _LB_GETSEL, i , nullParameter) 'i - 1 = Item Number (par1), no relevance (par2) If isSel Then itemsSel$ = itemsSel$ + "1" else itemsSel$ = itemsSel$ + "0"
End If
next print "Tenant_01_Pref ,"; itemsSel$ ', word$(matchNames$,m) 'not required; only for testing ' x$ = x$ + itemsSel$ + "|"
end sub
sub clearAllItems hLB ' allClear = SendMessageA(hLB, _LB_SETSEL, 0, -1) '0 (par1) = Flag to Clear, -1 (par2) = ALL end sub
[tntClose] ' call clearAllItems, hLB close #tw wait
Function SendMessageA(hW, msg, par1, par2) CallDLL #user32, "SendMessageA",_ hW as Ulong, _ 'Handle of the control (listbox) msg as Long, _ 'Stylebits (Windows Constant) par1 as Long, _ 'Parameter 1 (sometimes irrelevant) par2 as Long, _ 'Parameter 2 (sometimes irrelevant) SendMessageA as long 'Return Value, 1 = success End Function
|
|