|
Post by perfinit on Mar 13, 2020 18:55:23 GMT -5
I'd like to be able to display 4 choices on a screen - each one is tied to a specific function (as an example: add, subtract, multiply, divide) - and have the user select one of the four after which I can have my program perform the instructions related to that function (choice). I was thinking that something like a "radio button" would be a nice way to display next to the the choices for the user to choose one - not sure if this is possible, just based on something I've seen. Any help would be appreciated. Thank you.
|
|
|
Post by metro on Mar 14, 2020 3:32:12 GMT -5
Just one of many options, try searching for groupbox buttons and combobox or listbox may also be of use
'insert code here nomainwin global status$
radiobutton #win.yes, "Yes", doRadio, dummy,10,45,130,20 radiobutton #win.no, "No", doRadio,dummy,10,70,130,20 radiobutton #win.maybe, "May be", doRadio,dummy,10,105,130,20 radiobutton #win.notsure, "Not sure", doRadio,dummy,10,135,130,20
open "Make a Choice" for window as #win print #win, "trapclose Quit" print #win.yes, "set" wait
sub doRadio handle$ notice "You selected ";handle$ if handle$ = "#win.yes" then status$="yes" if handle$ = "#win.no" then status$="no" if handle$ = "#win.maybe" then status$="maybe" if handle$ = "#win.notsure" then status$="notsure" end sub
sub Quit handle$ close #handle$ end end sub
|
|
|
Post by Rod on Mar 14, 2020 3:51:53 GMT -5
There is a radio button example that ships with Liberty. But do people not expect to click a button rather than set a checkbox and click a button?
nomainwin WindowWidth = 400 WindowHeight = 400 UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2) textbox #1.tb1 100,40,200,20 textbox #1.tb2 100,70,200,20
button #1.ad, "Add", [add], UL, 100, 100, 200,20 button #1.su, "Subtract", [subtract], UL, 100, 130,200, 20 button #1.mu, "Multiply", [multiply], UL, 100, 160, 200,20 button #1.di, "Divide ", [divide], UL, 100, 190,200, 20 textbox #1.tb3 100,220,200,20 open "Buttons" for window as #1 print #1, "trapclose [quit]" wait
[add] #1.tb1 "!contents? a$" #1.tb2 "!contents? b$" #1.tb3 val(a$)+val(b$)
wait
[subtract] #1.tb1 "!contents? a$" #1.tb2 "!contents? b$" #1.tb3 val(a$)-val(b$) wait
[multiply] #1.tb1 "!contents? a$" #1.tb2 "!contents? b$" #1.tb3 val(a$)*val(b$) wait
[divide] #1.tb1 "!contents? a$" #1.tb2 "!contents? b$" #1.tb3 val(a$)/val(b$) wait
[quit] close #1 end
|
|
|
Post by tsh73 on Mar 14, 2020 16:10:47 GMT -5
it quite might be that I did not the thing OP wanted but I made a dialog modal window with (up to four - could be increased) radio buttons (so it works like PROMPT) which is called from a function doSelect(prompt$, list$) and returns number selected, 0 on Cancel and selection is printed to a mainwin in a form of, well, radiobuttons like this
Please select direction [*] north [ ] south [ ] east [ ] west
Chose a color, please [ ] Red [ ] Green [*] Blue
or this (first time, Cancel is pressed)
Please select direction Selection cancelled
Chose a color, please [ ] Red [*] Green [ ] Blue
Code follows.
'doSelect is programmed with up to 4 choices list$="north south east west" prompt$="Please select direction" res = doSelect(prompt$, list$) print prompt$ if res then call showSelection list$, res else print "Selection cancelled" end if
print
'but could work with less (2 or 3) list2$="Red Green Blue" 'list2$="Red Green" prompt2$="Chose a color, please" res2 = doSelect(prompt2$, list2$) print prompt2$ if res2 then call showSelection list2$, res2 else print "Selection cancelled" end if
end
sub showSelection list$, res while 1 i=i+1 w$=word$(list$,i) if w$="" then exit sub if i=res then print "[*] "; else print "[ ] "; print w$ wend end sub
function doSelect(prompt$, list$) global askSel.res
WindowWidth = 280 WindowHeight = 275
statictext #askSel.prompt, "prompt", 22, 16, 224, 55 button #askSel.default, "Ok", [OKClick], UL, 14, 201, 104, 25 button #askSel.Cancel, "Cancel", [CancelClick], UL, 150, 201, 104, 25
while 1 i=i+1 w$=word$(list$,i) if w$="" then exit while a1$(i)=w$ wend
radiobutton #askSel.rb1, a1$(1), rbSet, [radiobuttonReset], 22, 91, 168, 20 radiobutton #askSel.rb2, a1$(2), rbSet, [radiobuttonReset], 22, 116, 168, 20 radiobutton #askSel.rb3, a1$(3), rbSet, [radiobuttonReset], 22, 141, 168, 20 radiobutton #askSel.rb4, a1$(4), rbSet, [radiobuttonReset], 22, 166, 168, 20 open "Please do selection" for dialog_nf_modal as #askSel 'open "Please do selection" for window_modal as #askSel print #askSel, "trapclose [quit.askSel]" print #askSel, "font ms_sans_serif 10"
#askSel.prompt prompt$ #askSel.rb1 "set" askSel.res = 1
if i <=4 then #askSel.rb4 "hide" if i <=3 then #askSel.rb3 "hide"
wait
[quit.askSel] Close #askSel exit function
[OKClick] 'Perform action for the button named 'default' doSelect=askSel.res goto [quit.askSel]
[CancelClick] 'Perform action for the button named 'Cancel' askSel.res = 0 goto [quit.askSel]
[radiobuttonReset] 'do nothing wait
end function
sub rbSet handle$ askSel.res=val(right$(handle$, 1)) end sub
|
|
|
Post by perfinit on Mar 16, 2020 1:21:22 GMT -5
Thank you for the feedback - good options for me to pursue.
|
|