|
Post by davidk64 on Jun 12, 2022 4:13:35 GMT
dim clueNumbers$(6)
clueNumbers$(0) = "1"
clueNumbers$(1) = "2"
clueNumbers$(2) = "3"
clueNumbers$(3) = "4"
clueNumbers$(4) = "5"
clueNumbers$(5) = "6"
call openCluesWnd
sub openCluesWnd
radiobutton #clueWnd.rowRB, "Row", updatePreview, dummyHandler, 30, 56, 45, 20
combobox #clueWnd.clueNumbersCB, clueNumbers$(), updatePreview, 30, 126, 40, 25
open "Set Clues" for dialog_nf_modal as #clueWnd
#clueWnd.rowRB, "set"
#clueWnd.clueNumbersCB, "selectindex 1"
wait
close #clueWnd
end sub
sub dummyHandler buttonhandle$
notice "Running dummyHandler"
end sub
sub updatePreview buttonhandle$
#clueWnd.clueNumbersCB, "selection? selectedClueNo$"
print "Clue number is "; selectedClueNo$; "."
end sub
If I run the code the combobox doesn't get set to index 1 as expected.
If I comment out the line that sets the radiobutton and then run it goes into an infinite loop calling dummyHandler!
If I comment out the radiobutton declaration and line setting it the combobox index gets set as expected.
If I debug the code the combobox gets set okay but then when I select a new combobox value the dummyHandler sub runs which shouldn't happen since no radiobutton event is triggered when I interact with the combobox?
|
|
|
Post by Rod on Jun 13, 2022 11:00:49 GMT
Not sure if I understand what the radio button is to be used for but this code works, perhaps it will give us more to discuss.
dim clueNumbers$(6) clueNumbers$(0) = "1" clueNumbers$(1) = "2" clueNumbers$(2) = "3" clueNumbers$(3) = "4" clueNumbers$(4) = "5" clueNumbers$(5) = "6"
call openCluesWnd
'now wait else we will fall through to the sub wait
sub openCluesWnd 'open the window with the controls set to what we want radiobutton #clueWnd.rowRB, "Row", setradio, resetradio, 30, 56, 45, 20 radiobutton #clueWnd.colRB, "Col", setradio, resetradio, 30, 96, 45, 20 combobox #clueWnd.clueNumbersCB, clueNumbers$(), updatePreview, 30, 126, 40, 25 open "Set Clues" for dialog_nf_modal as #clueWnd #clueWnd "trapclose [quit]" #clueWnd.clueNumbersCB, "selectindex 1" #clueWnd.rowRB, "set"
'now wait for user input. How do they signal completion? wait
[quit] close #clueWnd end sub
sub setradio buttonhandle$ #buttonhandle$, "set" print "Radiobutton set handler called for ";buttonhandle$ end sub
sub resetradio buttonhandle$ #clueWnd.rowRB, "reset" print "Radiobutton reset handler called for ";buttonhandle$ end sub
sub updatePreview buttonhandle$ #clueWnd.clueNumbersCB, "selection? selectedClueNo$" print "Clue number is "; selectedClueNo$; "." end sub
|
|
|
Post by davidk64 on Jun 13, 2022 11:42:45 GMT
Here is image showing the context - if I have linked correctly. So I looked at your code that sets the clue number to 1 correctly and tried to see how it was different from my code. After some trial and error the issue I found was that I am using updatePreview as an event handler for both the combobox and the radiobuttons, in fact I want to use it for all the controls on the window. The idea being as the user changes components of a clue the preview textbox automatically updates to reflect this. I'm not sure why this is causing a problem as the user is only interacting with one control at a time. It's not a big deal if the clue number doesn't initialise to something but I was curious why it wasn't working. Are you aware of a different way I could achieve my goal? Many thanks for taking a look.
|
|
|
Post by Rod on Jun 13, 2022 13:20:34 GMT
Ok, I now recall a quirk or bug with the combo box not displaying changes made in some circumstances. It is about getting the two events shown. I think it is something to do with events queuing, wait waits till the next event, but scan mops up any outstanding events. However an easy fix is just to add a scan statement ahead of the wait. Having one event handler is possible but you will need logic in the handler to know what has fired and what to do.
dim clueNumbers$(6) clueNumbers$(0) = "1" clueNumbers$(1) = "2" clueNumbers$(2) = "3" clueNumbers$(3) = "4" clueNumbers$(4) = "5" clueNumbers$(5) = "6"
call openCluesWnd wait
sub openCluesWnd
radiobutton #clueWnd.rowRB, "Row", handler, handler, 30, 56, 45, 20 radiobutton #clueWnd.colRB, "Col", handler, handler, 30, 96, 45, 20
combobox #clueWnd.clueNumbersCB, clueNumbers$(), handler, 30, 126, 40, 25
open "Set Clues" for dialog_nf_modal as #clueWnd
#clueWnd.clueNumbersCB "selectindex 1" #clueWnd.rowRB "set" scan
wait
close #clueWnd
end sub
sub handler buttonhandle$ print "Button Handle is ";buttonhandle$
#clueWnd.clueNumbersCB, "selection? selectedClueNo$" print "Clue number is "; selectedClueNo$; "."
end sub
|
|
|
Post by davidk64 on Jun 14, 2022 22:24:52 GMT
Yes that did the trick! Thanks Rod
|
|
|
Post by Rod on Jun 16, 2022 7:21:37 GMT
Walt over on Liberty forum provides a different solution. It is probably better suited to your project. What he does in the handler is ensures only one event is handled at a time and this ensures the combobox displays the change. You would have needed this logic anyway to make your handler work.
'NOMAINWIN dim clueNumbers$(6) clueNumbers$(0) = "1" clueNumbers$(1) = "2" clueNumbers$(2) = "3" clueNumbers$(3) = "4" clueNumbers$(4) = "5" clueNumbers$(5) = "6"
call openCluesWnd wait
sub openCluesWnd
radiobutton #clueWnd.rowRB, "Row", handler, handler, 30, 56, 45, 20 radiobutton #clueWnd.colRB, "Col", handler, handler, 30, 96, 45, 20 combobox #clueWnd.clueNumbersCB, clueNumbers$(), handler, 30, 126, 40, 25 open "Set Clues" for dialog_nf as #clueWnd #clueWnd "trapclose quitclue" #clueWnd.rowRB "set" #clueWnd.clueNumbersCB "selectindex 1" end sub
'---------------------------------------------- '----------------------------------------------
SUB quitclue DlgHndl$ CLOSE #DlgHndl$ END END SUB
sub handler buttonhandle$
result$ = "" SELECT CASE buttonhandle$ CASE "#clueWnd.rowRB" , "#clueWnd.colRB" PRINT #buttonhandle$, "value? result$" IF result$ = "set" THEN PRINT "Button Handle is ";buttonhandle$ END IF
CASE "#clueWnd.clueNumbersCB" PRINT #buttonhandle$, "selection? selectedClueNo$" PRINT "Clue number is "; selectedClueNo$; "." END SELECT END SUB '
|
|