Radio Buttons - How to

General development discussion.

Moderators: Susan Smith, admin, Gabriel

Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Radio Buttons - How to

Post by Susan Smith »

Hi all,

Has anyone out there used radio buttons a lot? I'm trying my first group and I'm stuck. I want to create a two-button group that is part of a larger RINPUT MAT statement with two other fields and a button.

Before a report runs, I want to ask 3 things in one rinput statement:

Include Accounting Funds (use a checkbox to answer this)
Sort by: Fund No or Fund Name (2 piece radio button group)
Print Maintenance Fee (use a checkbox)

Then I'd add an "OK" button

Can someone help me? I can't seem to get this to work. Thanks

-- Susan
gordon
Posts: 358
Joined: Fri Apr 24, 2009 6:02 pm

Post by gordon »

For help of this type, it is most efficient if you attach the code that fails and indicate what the erroneous results are.
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

i would have done that, except I don't know HOW to use radio buttons in combination with other fields. I don't really even have a place to start from. Sorry. The wiki doesn't have very extension information regarding the use of radio buttons and check boxes in combination with other controls in the same input statement.

I'll go look to see if George has one of those magic little test programs on the 2009 conference flash drive that might demonstrate this.

-- Susan
gordon
Posts: 358
Joined: Fri Apr 24, 2009 6:02 pm

Post by gordon »

On the FTP site in Dll_Distr there is an examples.zip file with an example. This was distributed with the original New Console documentation which was placed on the wiki.
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

Gordon,

I looked at examples.zip, which contains (as you mentioned) the same examples that are up on the Wiki (which weren't of help to me in my situation).

I'm trying to incorporate check boxes, radio buttons and regular textbox-type files in the same RINPUT MAT statement and then loop back through the construct, validating fields by checking the curfld to determine which field the user has just "finished" - like I normally do on compound RINPUT statements.

i.e.

INPUTLOOP: RINPUT MAT FIELDS...:lot of data
if fkey=exitkey then goto exitloop
if curfld=1 then
validate field 1
end if
if curfld=2 then
validate field 2
end if

...etc..

goto inputloop

exitloop: do something else


I can't figure out how to do this when some of the fields are check boxes or radio buttons.

Is anyone else doing this? Or is anyone using radio buttons and checkboxes at all in BR GUI?

-- Susan
Gabriel
Posts: 412
Joined: Sun Aug 10, 2008 7:37 am
Location: Arlington, TX
Contact:

Post by Gabriel »

Susan,

We have checkboxes working under ScreenIO but we haven't done Radio Buttons yet.



Anyway, in Standard New GUI BR, you should be able to do it the same way you do it for ANY Rinput Fields statement. Simple combine all your different specs (the ones for the Radio buttons, the ones for the Check Boxes, and the ones for the text boxes) All into one big MAT SPEC$ array, and do your Rinput Fields from the whole Spec$ array, just like you normally do in Full Screen Processing.


At that point, voila, you have an example combining both Checkboxes and Radio buttons in one Rinput Fields statement.


If you try that and it fails, post the results here. It is much easier for us to help you with a concrete example to start from.

Good luck,
Gabriel
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

Thanks for jumping in Gabriel. I think what I'm missing is the big picture. First of all, what kind of data do radio buttons return? I can see that it returns an Fkey and the caption that is chosen has a carot(^) appended as a prefix to the caption. So if I have a set of radio buttons on my screen to represent "Male" or "Female" (let's assume that those are mutually exclusive and appropriate for radio buttons <s>):

My input statement (without using variables for the specs) might look something like this:
00010 DIM SEX$(2)*8
00020 LET SEX$(1)="Male" : LET SEX$(2)="Female"
00030 RINPUT FIELDS "10,25,radio 8,1,10;11,25,radio 8,1,11": MAT SEX$
00040 LET Q=FKEY
00050 PAUSE

If I chose Female, sex$(2) is returned as "^Female". (I have to be careful to dimension my caption fields large enough to contain the carot.)

Now if I have a 1-byte field 'MaleFemale$" in my data file which normally could contain "M" or "F", then do I convert the data back and forth before and after the radio button? In other words, after I get a result of sex$(2)="^Female" and Fkey=11, then do I add code to my program to evaluate that and do:
if sex$(1)(1:1)="^" then let MaleFemale$="M" else let MaleFemale$="F" ? (or something less hardcoded of course)

And when I read MaleFemale$ from my data file, then I have to do the opposite and assign the carot to the appropriate caption before I display the radio buttons on the screen? And is that what I do - assign the carot to the caption to indicate the current state of the radio buttons?

Is it possible to have no buttons selected in a radio button set by just tabbing past them in the RINPUT MAT fields? I thought that the buttons would get focus when I tabbed through them so I could see which button I was on, but that doesn't appear to be the case as far as I can tell. (You know how - in other programs - you can tab through radio buttons and when focus lands on the one you want, you can select it by pressing the space bar?)

Secondly, how can I tell what "field" I was just in (ala "curfld") when the RINPUT MAT statement contains radio buttons? If I have to "do something" in response to their selection, I need to know when they just looped through that radio button set, no? Or do I have to ONLY check for Flkeys now and not curfld as I do with RINPUT STATEMENTS with only "Text" entry fields?

If I have the following scenario with TWO sets of radio buttons, no matter what I do, curfld is always 1.

00010 DIM W(15),Y(15)
00020 DIM TEMP$(2)*8,SEX$(2)*8
00030 LET TEMP$(1)="Hot" : LET TEMP$(2)="Cold"
00040 LET SEX$(1)="Male" : LET SEX$(2)="Female"
00050 !
00060 LOOPTOP: RINPUT FIELDS "10,10,radio 8,1,21;11,10,radio 8,1,22;10,25,radio 8,2,10;11,25,radio 8,2,11": MAT TEMP$,MAT SEX$
00070 IF FKEY=99 THEN GOTO ENDPRGM
00080 LET Q=FKEY
00090 LET W(X+=1)=FKEY !:
LET Y(P+=1)=CURFLD
00100 GOTO LOOPTOP
00110 !
00120 ENDPRGM: PRINT MAT W
00130 PRINT MAT Y
00140 PAUSE

It seems like I'm missing something. This can't be as hard as I'm making it. Once I get these basics down, I can move forward to handling more complex statements with several types of controls on them.

-- Susan
gordon
Posts: 358
Joined: Fri Apr 24, 2009 6:02 pm

Post by gordon »

As followup on Gabriel's comment..

Note that you can test the settings by checking for the presence of the carrot (^) in front of the caption that is read, or an easier way is to assign a unique fkey value tp each button and test for that. It should also work for radio buttons to assign fkeys (which returns control to the program upon clicking a radio button) and then simply testing curfld.

If you don't need to validate the button settings you can either avoid assigning fkeys or do a CURFLD(CURFLD) and loop.
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

Hi Gordon,

CURFLD is one of my sources of confusion. In my example of two sets of radio buttons on one RINPUT stmt, no matter which set or which button IN the sets I click on, CURFLD stays at 1. I have a sample program where I load an array with the current CURFLD and FKEY each time I click on one of the radio buttons so I can easily examine it later:

00010 DIM W(15),Y(15)
00020 DIM TEMP$(2)*8,SEX$(2)*8
00030 LET TEMP$(1)="Hot" : LET TEMP$(2)="Cold"
00040 LET SEX$(1)="Male" : LET SEX$(2)="Female"
00050 !
00060 LOOPTOP: RINPUT FIELDS "10,10,radio 8,1,21;11,10,radio 8,1,22;10,25,radio 8,2,10;11,25,radio 8,2,11": MAT TEMP$,MAT SEX$
00070 IF FKEY=99 THEN GOTO ENDPRGM
00080 LET W(X+=1)=FKEY !:
LET Y(P+=1)=CURFLD
00090 GOTO LOOPTOP
00100 !
00110 ENDPRGM: PAUSE


The results are the CURFLD is ALWAYS 1 no matter which set of radio buttons I click on. Is that expected behavior?

-- Susan
gtisdale
Posts: 218
Joined: Sun Jun 07, 2009 7:54 am
Location: Concord, Massachusetts
Contact:

Post by gtisdale »

Radio dots are fairly easy to use. The trick is to group the radio dots by using a sequence or grouping number in the leading attribute section of the FIElDS statement so that you can have more than one group of radio dots in the same RINPUT FIELDS statement.

In addition, the description displayed next to the radio dot must be a oart of your RINPUT statement. The variable that is the RINOUT variable will change depending upon whether the dot is selected or not. The "^" charcter will either be the first character of the variable if selected or not if not selected.

You can not use the SEACH fubnction to determine if the item is selected becasue the SEARCH funciton uses the "^" to indicate a case insensitve search. So, you must check pos(1:1) to see if it is a "^".

There is a simple program in the TESTS directory TESTRAD, however this may be misleading because its purpose was to try different formatting forms for the text of the RADIO dot.

The best presentation for a radio dot selction is the normal grey BR background with a simple RINPUT statement on top of it.

00006 START: !
00010 ! Test radio buttons
00020 ! replace testrad.br
00030 EXECUTE "config attribute [RADIO]n/#ff0000:#00ffff,font=arial:medium"
00040 EXECUTE "config attribute [Rtrans]n/W:T,font=arial:medium"
00050 DIM INWRK$(6)*40,INFLD$(6)*40,DATA$(6)*100
00060 LET INWRK$(1)="3,5,radio 40,1[radio]" !:
LET INWRK$(2)="5,5,radio 40,1[radio]" !:
LET INWRK$(3)="7,5,radio 40,1[radio]"
00070 LET INWRK$(4)="9,5,1/radio 40,2[rtrans]" !:
LET INWRK$(5)="11,5,1/radio 40,2[rtrans]" !:
LET INWRK$(6)="13,5,1/radio 40,2[rtrans]"
00080 LET INFLD$(1)="9,5,c 40,[Rtrans]" !:
LET INFLD$(2)="11,5,c 40,[Rtrans]" !:
LET INFLD$(3)="13,5,c 40,[Rtrans]"
00090 PRINT NEWPAGE
00100 LET DATA$(1)="Option one" !:
LET DATA$(2)="^Option two" !:
LET DATA$(3)="Option three"
00110 LET DATA$(4)=" Option one sub-two " !:
LET DATA$(5)=" Option two sub-two" !:
LET DATA$(6)=" Option three sub-two "
00120 PRINT FIELDS MAT INFLD$: MAT DATA$(4:6)
00130 LET DATA$(5)(1:0)="^"
00140 RINPUT FIELDS MAT INWRK$: MAT DATA$
00150 IF DATA$(1)(1:1)="^" THEN !:
LET OPT=1 ELSE IF DATA$(2)(1:1)="^" THEN !:
LET OPT=2 ELSE !:
LET OPT=3
00160 IF FKEY=99 THEN GOTO EOJ
00170 GOTO 140
00180 GOTO EOJ
19950 EOJ: STOP
19990 STOP: STOP
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

Thank you George! That example shines more light on things. The part that I'm still fuzzy about is dealing with these two sets of radio buttons in conjunction with OTHER types of fields/controls in the same RINPUT statement. Let's say I also have a checkbox and some other text-box fields on the same screen in that same RINPUT statement. Normally my RINPUT statement would be the beginning of a loop. After the RINPUT, I'd examine CURFLD to see which field in the loop that the user just went through and I'd do the data validation at that point and then loop back to the RINPUT statement until the user hits and Fkey that takes them out of that loop (like clicking on an OK button or something). But CURFLD doesn't seem to work with the RADIO BUTTON sets. It's always CURFLD. I'm sure I'm just not getting something.

I'll play around with it some more and see if I can figure it out. I can get the radio buttons working by themselves, but not as part of a RINPUT statement with other controls (text entry fields or checkboxes).

Sorry for the continued brick wall. Maybe I need a margarita :)

-- Susan
gtisdale
Posts: 218
Joined: Sun Jun 07, 2009 7:54 am
Location: Concord, Massachusetts
Contact:

Post by gtisdale »

cHANGE YOUR PROGRAM TO BE AS FOLLOWS:

00010 DIM W(15),Y(15)
00020 DIM TEMP$(2)*8,SEX$(2)*8
00030 LET TEMP$(1)="^Hot" : LET TEMP$(2)="Cold"
00040 LET SEX$(1)="Male" : LET SEX$(2)="^Female"
00050 !
00060 LOOPTOP: RINPUT FIELDS "10,10,radio 8,1,21;11,10,radio 8,1,22;10,25,radio 8,2,10;11,25,radio 8,2,11": MAT TEMP$,MAT SEX$
00080 FOR A=1 TO UDIM(TEMP$)
00081 IF TEMP$(A)(1:1)="^" THEN LET X=A : GOTO 85
00082 NEXT A
00085 FOR B=1 TO UDIM(SEX$)
00086 IF SEX$(B)(1:1)="^" THEN LET Y=B : GOTO 90
00087 NEXT B
00090 IF FKEY=99 THEN GOTO ENDPRGM
00095 GOTO LOOPTOP
00100 !
00110 ENDPRGM: PRINT X,Y : PAUSE
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

George,

This is no way (is there?) to tell which radio button set that the user just responded to? And if there were also textboxes in that loop, can you distinguish between an entry in one of those vs. a radio button click?

I understand the example you just posted where you respond to the radio buttons, but it seems that the user would be going through that process even if they didn't click on the buttons. Is there a way (via CURFLD) to stop ONLY when they actually clicked a radio button?

Below is a modified example - with a textbox, then the two sets of radio buttons followed by another textbox. I can't figure out how to tell (after the loop) that I have just left the radio buttons because CURFLD remains set at 1 no matter what. It's interesting to me that the last field (text box) DOES show up as CURFLD 6. I really don't get this at all.

I understand what to do with the results of the radio buttons now (thanks to you). But I don't understand how to tell what the user just clicked on. With "normal" RINPUT statements, I just check CURFLD after the top of the loop and "do something" based on the CURFLD result. Then I keep sending the program back to the loop until they hit the exit button or Fkey.

But it doesn't work this way with radio buttons. I don't want to process the radio buttons with EVERY pass through the loop UNLESS the user has actually changed one of the radio buttons. Try my example and examine mat W at the end - that array saves CURFLD with each pass through the loop (well, up to the 1st 20 times anyway). When you press tab, the focus only switches between the two text box fields and never stops at the radio buttons. Perhaps there is some other attribute that I need to use on the radio button specs? (hmm..maybe that's what's missing...)

-- Susan

00010 PRINT NEWPAGE
00020 DIM W(15),Y(15)
00030 DIM TEMP$(2)*8,SEX$(2)*8,MISC1$*20,MISC2$*20
00040 LET TEMP$(1)="^Hot" : LET TEMP$(2)="Cold"
00050 LET SEX$(1)="Male" : LET SEX$(2)="^Female"
00060 !
00070 LOOPTOP: RINPUT FIELDS "7,10,c 20,stae;10,10,radio 8,1,21;11,10,radio 8,1,22;10,25,radio 8,2,10;11,25,radio 8,2,11;13,10,c 20,stae": MISC1$,MAT TEMP$,MAT SEX$,MISC2$
00080 IF FKEY=99 THEN GOTO ENDPRGM
00085 LET W(T+=1)=CURFLD : ! save a snapshot of the curfld value
00090 GOTO LOOPTOP
00180 !
00190 ENDPRGM: PAUSE
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

George,

I was playing with some of the test programs in your folder on the conference flash drive and I ran across one called TESTTEXT where you are putting a text box in the middle of some other input fields. I noticed when I TAB through those fields, it doesn't stop at the text box JUST LIKE it doesn't stop at my radio buttons in my other example. So is that just normal behavior? In other words, when you combine different controls on one RINPUT statement, is it a given that you can't TAB to each and every control AND that not every control nets a CURFLD value because of that? So the only way to navigate to text boxes and radio buttons in mixed RINPUT statements is to click there with the mouse?

I don't like that behavior, but it does explain some things. Perhaps I'm just missing some attribute, as I mentioned before. I think I'll forget about this for tonight. I'm feeling more stupid as the hours pass! The fireworks at the Rose Bowl will be starting soon and I can see them from my house.

-- Susan
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

Update: I made a LITTLE progress. Using the "T" attribute on the tabs, I can technically tab among all 6 fields now (the radio buttons AND the text fields), but I can't SEE the focus change when I go through the radio buttons. What I'm EXPECTING to happen is for them to receive focus like they do when you mouse over them. Perhaps that's just the need for different attributes. I'll have to work on it some more late this afternoon when I get back home.

-- Susan

This is the current test I was using:

00010 PRINT NEWPAGE
00020 DIM W(15),Y(15)
00030 DIM TEMP$(2)*8,SEX$(2)*8,MISC1$*20,MISC2$*20
00040 LET TEMP$(1)="^Hot" : LET TEMP$(2)="Cold"
00050 LET SEX$(1)="Male" : LET SEX$(2)="^Female"
00060 !
00070 LOOPTOP: RINPUT FIELDS "7,10,c 20,stae;10,10,radio 8,1T,21;11,10,radio 8,1T,22;10,25,radio 8,2T,10;11,25,radio 8,2T,11;13,10,c 20,stae": MISC1$,MAT TEMP$,MAT SEX$,MISC2$
00080 IF FKEY=99 THEN GOTO ENDPRGM
00085 LET W(T+=1)=CURFLD : ! save a snapshot of the curfld value
00090 GOTO LOOPTOP
00180 !
00190 ENDPRGM: PAUSE
Post Reply