Liberty BASIC Community Forum
« Reseting radio buttions inside group boxes »

Welcome Guest. Please Login or Register.
Sep 20th, 2017, 10:29pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Reseting radio buttions inside group boxes  (Read 452 times)
MKnarr
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 430
xx Reseting radio buttions inside group boxes
« Thread started on: Dec 9th, 2016, 4:29pm »

I have a program that has at least 13 windows with as many as 20 radio buttons inside group boxes. As we know, when selecting a radio button inside a group box, another radio button inside the same group box is reset.

I have discovered by trial and error that when defining a radio button, there must be a reset label, it can't be left blank. I have also discovered that I can use the same reset label for every radio button in every window where the buttons are inside a group box but I have also discovered that the the label for the reset doesn't actually have to exist. Here is some code to illustrate the point.

Code:
    nomainwin
    WindowWidth = 500
    WindowHeight = 410
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    groupbox #main.groupbox4, "GroupBox Caption", 155,  92, 115, 115
    radiobutton #main.rb1, "button 1", [rb1Set], [rb1Reset], 180, 117,  71,  25
    radiobutton #main.rb2, "button 2", [rb2Set], [rb1Reset], 180, 142,  71,  25
    radiobutton #main.rb3, "button 3", [rb3Set], [rb1Reset], 180, 167,  71,  25
    statictext #main.st1, "", 180,210,200, 20

    open "untitled" for window as #main
    #main, "trapclose [quit]"
    #main, "font ms_sans_serif 10 bold"
    #main.rb1, "set"
    #main.st1, "Button 1 set"
    wait

    [rb1Set]
    #main.st1, "Button 1 set"
    wait

    [rb2Set]
    #main.st1, "Button 2 set"
    wait

    [rb3Set]
    #main.st1, "Button 3 set"
    wait

    [quit]
    close #main
    end

 


It may have no practical value but when you have a lot of radio buttons inside group boxes it makes initial programming easier.
User IP Logged

alincon2001
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 494
xx Re: Reseting radio buttions inside group boxes
« Reply #1 on: Dec 10th, 2016, 09:53am »

Well, the help file does say that clicking on a set radiobutton does not do anything.
I'm wondering if there is a way to reset a set radiobutton w/o setting another one, if, say, you set a radiobutton and then realize that you want no radiobuttons set.

r.m.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Reseting radio buttons inside group boxes
« Reply #2 on: Dec 10th, 2016, 1:09pm »

It is quite easy to do but your user might find it unusual because there should always be one radiobutton checked. So I would not suggest this code is used.

Perhaps you are thinking of checkboxes.

Code:
nomainwin
    WindowWidth = 500
    WindowHeight = 410
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    groupbox #main.groupbox4, "GroupBox Caption", 155,  92, 115, 140
    radiobutton #main.rb1, "button 1", [rb1Set], [rb1Reset], 180, 117,  71,  25
    radiobutton #main.rb2, "button 2", [rb2Set], [rb1Reset], 180, 142,  71,  25
    radiobutton #main.rb3, "button 3", [rb3Set], [rb1Reset], 180, 167,  71,  25
    radiobutton #main.rb4, "Reset", [rb4Set], [rb1Reset], 180, 195,  71,  25
    statictext #main.st1, "", 180,235,200, 20

    open "untitled" for window as #main
    #main, "trapclose [quit]"
    #main, "font ms_sans_serif 10 bold"
    #main.rb1, "set"
    #main.st1, "Button 1 set"
    wait

    [rb1Set]
    #main.st1, "Button 1 set"
    wait

    [rb2Set]
    #main.st1, "Button 2 set"
    wait

    [rb3Set]
    #main.st1, "Button 3 set"
    wait

    [rb4Set]
    #main.st1, "Reset    All"
    #main.rb1, "reset"
    #main.rb2, "reset"
    #main.rb3, "reset"
    #main.rb4, "reset"
    wait

    [quit]
    close #main
    end
 
User IP Logged

alincon2001
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 494
xx Re: Reseting radio buttions inside group boxes
« Reply #3 on: Dec 10th, 2016, 4:06pm »

You're right, it's easy for the programmer to issue a reset command, but I was asking from the user's point of view. How does he back out without causing any harm, after clicking on one radiobutton?

r.m.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Reseting radio buttions inside group boxes
« Reply #4 on: Dec 10th, 2016, 5:38pm »

As I said, the user will not be expecting to back out a radiobox choice they must choose one. Anything else breaks Windows protocol for the GUI control.
User IP Logged

robmcal
Senior Member
ImageImageImageImage


member is online

Avatar




PM

Gender: Male
Posts: 399
xx Re: Reseting radio buttions inside group boxes
« Reply #5 on: Dec 10th, 2016, 6:44pm »

on Dec 10th, 2016, 4:06pm, alincon2001 wrote:
You're right, it's easy for the programmer to issue a reset command, but I was asking from the user's point of view. How does he back out without causing any harm, after clicking on one radiobutton?

r.m.

You could add a 'Reset' and/or 'Cancel' button to the window with the groupbox. Reset would put every control back to it's original state and Cancel would close the window with applying any changes.
« Last Edit: Dec 10th, 2016, 6:45pm by robmcal » User IP Logged

Definition of an Upgrade: Take old bugs out, put new ones in.
MKnarr
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 430
xx Re: Reseting radio buttions inside group boxes
« Reply #6 on: Dec 19th, 2016, 2:18pm »

In my 17000 line+ program I use #var$ many times. It occurred to me that it might also be used with radio buttons inside a group box. It's useful if setting a button is a somewhat repetitive code. It's not useful if each radio button set does a lot of different things. Anyway here is the code from the first post to illustrate using the #Var$ to set something.

Code:
    nomainwin
    WindowWidth = 500
    WindowHeight = 500
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    groupbox #main.groupbox4, "GroupBox Caption", 155,  40, 115, 360
    radiobutton #main.rb1, "button 1", [rb3Set], [rb1Reset], 180, 60,  80,  25
    radiobutton #main.rb2, "button 2", [rb3Set], [rb1Reset], 180, 90,  80,  25
    radiobutton #main.rb3, "button 3", [rb3Set], [rb1Reset], 180, 120,  80,  25
    radiobutton #main.rb4, "button 4", [rb3Set], [rb1Reset], 180, 150,  80,  25
    radiobutton #main.rb5, "button 5", [rb3Set], [rb1Reset], 180, 180,  80,  25
    radiobutton #main.rb6, "button 6", [rb3Set], [rb1Reset], 180, 210,  80,  25
    radiobutton #main.rb7, "button 7", [rb3Set], [rb1Reset], 180, 240,  80,  25
    radiobutton #main.rb8, "button 8", [rb3Set], [rb1Reset], 180, 270,  80,  25
    radiobutton #main.rb9, "button 9", [rb3Set], [rb1Reset], 180, 300,  80,  25
    radiobutton #main.rb10, "button 10", [rb3Set], [rb1Reset], 180, 330,  80,  25
    statictext #main.st1, "Button 1",180,400,250, 20

    open "untitled" for window as #main
    #main, "trapclose [quit]"
    #main, "font ms_sans_serif 10 bold"
    #main.st1, "!font Arial 16 bold"
    #main.rb1, "set"
    wait

    [rb3Set]
    for hv=1 to 10
        var$="#main.rb"+str$(hv)
        #var$ "value? result$"
        if result$="set" then
            #main.st1, "Button "+str$(hv)+" set"
            exit for
        end if
    next
    wait

    [quit]
    close #main
    end
 


It saved almost 400 lines of code in my program. I have many windows that have up to 20 radio buttons.

Here is some actual code where there are 20 check boxes in which the user can select multiple check boxes.

Code:
    [pm1Set] 
    for hv = 1 to 20
        var$ = "#printmail.cb"+str$(hv)
        #var$ "value? result$"
        if result$="set" then
            ColorBox$(hv)="1" 'Print this club.
        else
            ColorBox$(hv)=""
        end if
    next
 


The uses can select one or more clubs to print information. Those where the array is set to 1 will be printed, the others will not. Of course, it depends on how many radio buttons you have versus how many lines of code you needed in the set code.
« Last Edit: Dec 19th, 2016, 2:21pm by MKnarr » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls