[SOLVED] How to start a conditional radio

Post Reply
User avatar
Ross_ValuSoft
Posts: 87
Joined: Thu Dec 18, 2008 11:27 am
Location: Melbourne, Australia

[SOLVED] How to start a conditional radio

Post by Ross_ValuSoft »

SOLVED

Sweating on a Saturday night seems to work. I removed the ON CHANGE codeblocks and substituted separate functions and revised the form of the conditional tests. And ... it works. Lesson learned.

Cheers,

Ross
************
Hi everyone,

Below is a self contained extract from one of my applications. It has 3 radio menus that are interrelated by some conditional "on change" definitions.

The code works correctly if each of the radio menus starts in the first position, but crashes if any other position is initiated. I need to be able to start sometimes with a non-first position and cannot see how I should establish the three radio menus to achieve this.

Could someone help please?

Thanks,

Ross

Code: Select all

#include "FWCE.ch"
#INCLUDE "winapi.CH"

Function Main()

   local oWnd8, oRad1, oRad2, oRad3
    local oGrp, oGrp1, oGrp2
    local nOffset := 2

    /*
      this code works correctly if started with these values.
      it fails with the "no method export" error if either of the first two
      is not "1". Why? And how to avoid it?
    */
    local   nEditVis  := 1
    local   nEditElec := 1
    local   nEditRes  := 1


   DEFINE WINDOW oWnd8 TITLE "Change results"


        @ 0, 30 BUTTON "Exit"  OF oWnd8 ;
               ACTION ( oWnd8:End() )  SIZE 30, 30 PIXEL


        @ 0, 180 BUTTON "Info" SIZE 30, 30 PIXEL OF oWnd8 ;
                  ACTION ( MsgInfo( "Visual = " + alltrim( str( nEditVis)) + CRLF +;
                                            "Electrical = " + alltrim( str(nEditElec)) + CRLF +;
                                            "Result = " + alltrim( str(nEditRes ))) )

        /*
          must define the oRad3 before declaring anything that alters its settings
          to avoid the dreaded "no method export" error
        */

        @ 5.5 + nOffset, 1 GROUP oGrp2 to 11.5, 32 PROMPT "Results"

       @ 0.75, 2 RADIO oRad3 VAR nEditRes ;
          ITEMS "Visual + Electrical OK","Refitted lead", "Replaced plug", ;
            "Replaced socket", "Withdrawn from service", "Visual only";
            SIZE 140, 12 of oGrp2


        @ 0 + nOffset, 16 GROUP oGrp1 to 5.5, 17 PROMPT "Electrical"

       @ 0.75, 2 RADIO oRad2 VAR nEditElec ;
          ITEMS "Pass","Fail", "No test" ;
            ON CHANGE {|| ( IIF( (nEditVis == 2) , ( oRad2:Setoption(3), oRad3:Setoption( 5 )) , ) ,;
                                 IIF( (nEditElec == 2 ), oRad3:Setoption( 5 ) , ) , ;
                                 IIF( (nEditVis == 1) .AND. ( nEditElec == 1 ) , oRad3:Setoption(1), ),;
                                 IIF( (nEditVis == 1) .AND. ( nEditElec == 3 ) , oRad3:Setoption(6), ) )  } ;
            SIZE 42, 9 of oGrp1

        @ 1.5 + nOffset, 1 GROUP oGrp to 4, 14 PROMPT "Visual"

        @ 0.75, 2 RADIO oRad1 VAR nEditVis ;
          ITEMS "Pass","Fail" ;
            ON CHANGE {|| ( IIF( (nEditVis == 2) , ( oRad2:Setoption(3), oRad3:Setoption( 5 )) , ) ,;
                                 IIF( (nEditElec == 2 ), oRad3:Setoption( 5 ) , ) , ;
                                 IIF( (nEditVis == 1) .AND. ( nEditElec == 1 ) , oRad3:Setoption(1), ),;
                                 IIF( (nEditVis == 1) .AND. ( nEditElec == 3 ) , oRad3:Setoption(6), ) )  } ;
            SIZE 40, 9 of oGrp


   ACTIVATE WINDOW oWnd8 ;
      ON CLICK MsgInfo( "Missed !" )

Return NIL
 
Post Reply