Page 1 of 1

Radio

Posted: Wed Apr 07, 2010 12:47 pm
by MarcoBoschi
Hi,
when I click button oButton I set nRadio value to -1 then I perform a refresh of oRadio but nothing changes.

I expect to find the radio button in the initial state
Is there a solution?
Thanks
Marco

#include "fivewin.ch"

FUNCTION MAIN

LOCAL oDlg
LOCAL oRadio , nRadio := -1
LOCAL oButton
LOCAL oSay, cSay := STR(nRadio,3)
DEFINE DIALOG oDlg

@ 2 , 10 BUTTON oButton ;
ACTION ( nRadio := -1 , ;
oRadio:Refresh() , ;
cSay := STR(nRadio,4) )

@ 1 , 1 RADIO oRadio VAR nRadio PROMPT "One " , "Two " OF oDlg ;
ON CHANGE ( cSay := STR(nRadio,3) , ;
oSay:refresh() )


@ 3 , 1 SAY oSay PROMPT cSay OF oDlg

ACTIVATE DIALOG oDlg

RETURN NIL

Re: Radio

Posted: Wed Apr 07, 2010 1:10 pm
by James Bott
Marco,

I don't understand what you are trying to do.

You can't use a negative value. Try setting the initial value to 2, then set the value to 1 with the ACTION clause, and it works as expected.

James

Re: Radio

Posted: Wed Apr 07, 2010 1:26 pm
by MarcoBoschi
Hi James,
thanks!

I need three state: 1 , 2 and another state that means empty
In the field of a dbf table these values become
IF nRadio = 1 cField := "YES"
IF nRadio = 2 cField := "NO"
IF nRadio = -1 cField := " "
-1 or another value
all here

Re: Radio

Posted: Wed Apr 07, 2010 1:49 pm
by James Bott
Marco,

Radio's are designed to have default answer.

You could do what you want by adding a third option "Unknown" and then the radios would be 1, 2, and 3. You can then change the 3 to -1 when saving to the DBF.

I do agree with your philosophy of providing an unknown, blank, or unanswered option. Radios and checkboxes have a default answer which may not be valid if the user doesn't know the answer. This leads to bad information in the database and there is no way to know it is bad.

Providing an "Unknown" option and using it as the default is a good solution.

James

Re: Radio

Posted: Wed Apr 07, 2010 1:52 pm
by MarcoBoschi
Ok,
thank you James

Marco

Re: Radio

Posted: Wed Apr 07, 2010 2:39 pm
by MarcoBoschi
James,

in this way only "Yes" and "No" option are visible.

RADIOBUTTON "Yes", 1541, 348, 67, 20, 12
RADIOBUTTON "No", 1542, 370, 67, 22, 12
RADIOBUTTON "" , 1543, 396, 67, 22, 12, BS_RADIOBUTTON | NOT WS_VISIBLE

When I set oRadio:noption to 3 visually I obtain the initial state
Bye

Re: Radio

Posted: Wed Apr 07, 2010 2:49 pm
by James Bott
Marco,

I advise against that. Once the user clicks on Yes or No, they cannot change their mind and then click on Unknown. This will still lead to some bad data in the database. Why not just leave it visible?

James

Re: Radio

Posted: Wed Apr 07, 2010 3:56 pm
by MarcoBoschi
James,
when a empty another field o set the value of radio to 3
in this way


oTVla:nCod_pro := 3
oTVla:oRadCod_pro:refresh()

...
...
REDEFINE RADIO oTVla:oRadCod_pro VAR oTVla:nCod_pro ;
ID 1541, 1542, 1543 OF oFld:aDialogs[ 5 ] ;
ON CHANGE oTVla:cCod_pro := IFM( oTVla:nCod_pro, { 3 , 1 , 2 } , {" " , "Yes" , "No" } )

...
...

FUNCTION IFM( xValore , aCondiz, aValori )
LOCAL i , xRitorna := NIL
FOR i := 1 TO LEN(aCondiz)
IF xValore = aCondiz[i]
xRitorna = aValori[i]
EXIT
ENDIF
NEXT i
RETURN xRitorna


It works
Bye