AnsweredAssumed Answered

VRF-Radio_Buttons

Question asked by VRFuser on Jun 19, 1998
send q VRF-Radio_Buttons ww vrf Pollard@volpe.dot.gov

from: Greg Goebel / HP-MXD
      gvg@lvld.hp.com / 800-452-4844
      website:  ftp://fcext3.external.hp.com/dist/mxd/index.html
to:   John K. Pollard
date: Friday, 19 June 1998 1603 MDT

Sir:

There are certain VRF questions that I take one look at and shake my head,
knowing there is zero chance of anyone answering them.

This one, however, is one of those puzzles that no VEE hack can resist.  I
find them useful to add to my kit of examples so I can have more materials
to explain how to write reasonable VEE programs.

[%%] regards -- gvg

--------------------------------- cut here ----------------------------------



[VEE] A VEE Input Question

* A VEE user had a requirement for a pop-up panel that contained a list of
items in the form of Radio Buttons, one of which was set as the default.  The
operator needed to be able to select an item from the list, change the
selection if need be and as many times as necessary, and then click on an OK
button to exit the panel and return the list setting to the calling program.

That was easy enough.  The trick was that the OK button couldn't be enabled
until the user had changed the list setting from the default.

This could be done with the following sample UserFunction, named "NoOK()":

   +-----------------------------------------------------------------+
   | NoOK                                                            |
   +---------------------------------------------------------------+-+
   |                                                               | |
   |  +------------+          +---------------------------------+  | |
   |  |  Formula   |          |         Declare Variable        |  | |
   |  +------------+          +---------------------------------+  | |
   |  | Flag = 0   |          | Name:      [       Flag       ] |  | |
   |  +------+-----+          | Scope:     [ Local to Context ] |  | |
   |         |                | Type:      [       Int32      ] |  | |
   |     +---+---+            | Num Dims:  [         0        ] |  | |
   |     |       |            +---------------------------------+  | |
   |     |   +---+---+                                             | |
   |     |   | Until |                                             | |
   |     |   | Break +------------+                                | |
   |     |   +-------+            |                                | |
   |     |                +-------+-------+                        | |
   |     |                | Radio Buttons |                        | |
   |     |                +---------------+                        | |
   | +---+---+            | <*> Item 1    +----------------------->|X|
   | | Until |            | < > Item 2    |                        | |
   | | Break +--+         | < > Item 3    +--+   +-------------+   | |
   | +-------+  |         +---------------+  |   |   Formula   |   | |
   |            |                    ordinal |   +-+-----------+   | |
   |   +--------+--------+             value +-->|A| Flag = A  |   | |
   |   |   If/Then/Else  |                       +-+-----------+   | |
   |   +---------+-------+                                         | |
   |   | Flag!=0 | Then  +---------+                               | |
   |   +---------+-------+         |                               | |
   |                            +--+--+                            | |
   |                            | OK  +-----------+                | |
   |                            +-----+           |                | |
   |                                     +--------+--------+       | |
   |                                     | Exit UserObject |       | |
   |                                     +-----------------+       | |
   |                                                               | |
   +---------------------------------------------------------------+-+

The Radio Buttons and the OK button are put on the Panel View of this
UserFunction, and the UserFunction is set to "Show Panel On Execute". 

The scheme is simple:

% A local variable named "Flag" is declared, and set to the ordinal number
   of the default Radio Button -- in this case, 0.  The Radio Buttons have to
   be set to the corresponding initial value, and they have to be set to
   "initialize at activate" so that the same initial value comes up when the
   UserFunction is callled again.

   Setting the "Flag" variable has to be the first action in the
   UserFunction, since the rest of the UserFunction refers to it and will
   return an error if variable's value has not been initialized.

% Anyway, once the "Flag" variable is set, control flow propagates along two
   parallel paths.

   The first path simply loops on the value of the Radio Buttons.  The list
   item output is sent to the UserFunction's return value pin, while the
   ordinal number of that item is loaded into the "Flag" variable in a
   Formula box.

% The other path handles the OK Button to exit the UserFunction.  It loops
   on the value of "Flag" until it's not 0 any more, and then arms the OK
   Button.  When the OK Button is fired, it executes an Exit UserObject to
   get out of the UserFunction.

   Setting the value of "Flag" back to 0 will not disarm the OK button,
   since the loop has exited by that time.

This UserFunction implies that the default list item in the Radio Buttons
will always be the first ("zeroth", actually) item.  To make it some other
item will require changing the settings in various objects.

Making the default list item programmable as a parameter sent to the
UserFunction would make the code somewhat more complicated, and is left as an
exercise for the reader.  Note that you can bring out a "Default Value" pin
on the Radio Buttons, but it has to be given the string in the list item, not
the ordinal number, while the "Flag" variable stores an ordinal number.

There is an example program available on the MXD websites under the name
"xnook.vee".

[<>]

--------------------------------- cut here ----------------------------------
(saveFormat "2.3")
(date "Fri 19/Jun/1998 16:07:03 ")
(veerev "5.0")
(platform "PC")
(execMode ole)
(filterNAN 0)
(workspaceStackingOrder M)
(SaveCF no)
(device 0 ROOTCONTEXT
(properties
(trigMode deg)
(nextID 5)
(popupTitleText "Untitled")
(popupMoveable 1))
(deviceList
(UserFunctions
(nextID 1)
(context 0
(properties
(name "NoOK")
(trigMode deg)
(nextID 9)
(popupTitleText "UserFunction1")
(popupMoveable 1))
(interface
(output 1
(type data)
(name "X")
(lock constraints)
(optional yes)))
(deviceList
(device 0 ENUMCONSTANT
(properties
(name "Radio Buttons")
(initializeAtActivate 1))
(interface
(output 1
(name "Enum")
(lock name constraints))
(output 2
(name "Ordinal")
(lock name constraints)))
(implementation
(value Enum
(values
("Item 1" 0)
("Item 2" 1)
("Item 3" 2))
(data  "Item 3"))
(initValue Text
(data  "Item 1"))))
(device 1 DECLVAR
(properties
(name "Declare Flag")
(scope con)
(globalName "Flag"))
(implementation
(value Int32
(data  0))))
(device 2 FORMULA
(properties
(expr 1 "Flag = A"))
(interface
(input 1
(name "A")
(optional yes))
(output 1
(name "Result")
(tag "Result")
(lock name constraints)
(optional yes))))
(device 3 REPEATUNTILBREAK
(interface
(output 1
(name "Continuous")
(lock name constraints))))
(device 4 REPEATUNTILBREAK
(interface
(output 1
(name "Continuous")
(lock name constraints))))
(device 5 IFTHENELSE
(properties
(cases 1 "Flag!=0"))
(interface
(output 1
(name "Then")
(lock name constraints))
(output 2
(name "Else")
(lock name constraints))))
(device 6 CONFIRM25
(interface
(output 1
(name "Go")
(lock name constraints)))
(implementation))
(device 7 EXITCONTEXT)
(device 8 FORMULA
(properties
(expr 1 "Flag = 0"))
(interface
(output 1
(name "Result")
(tag "Result")
(lock name constraints)
(optional yes))))
(configuration
(connect D3:1 D0:0)
(connect D0:2 D2:1)
(connect D8:0 D3:0)
(connect D8:0 D4:0)
(connect D4:1 D5:0)
(connect D5:1 D6:0)
(connect D6:1 D7:0)
(connect D0:1 O1:1))
(ShowOnExecPanel
(relativeOrigin 763 368)))
(contextCarrier
(active detail)
(panel
(extent 179 191)
(widget 0 detail
(relativeOrigin 30 10)
(title on)
(borderStyle flat)
(extent 121 79)
(format buttons))
(widget 6 detail
(relativeOrigin 70 130)
(title off)
(borderStyle none)
(extent 47 22)))
(detail
(extent 599 539)
(anchorPt 1 -132)
(configuration
(devCarrierFor 0
(active open)
(icon)
(open
(extent 121 79)
(format buttons))
(pinCenter 220 420))
(devCarrierFor 1
(active open)
(icon
(extent 77 0))
(open
(extent 195 103))
(pinCenter 410 230))
(devCarrierFor 2
(active open)
(icon)
(open
(extent 74 35))
(terminals on)
(pinCenter 400 480))
(devCarrierFor 3
(active icon)
(icon
(extent 68 51)
(iconImage "loop.icn"))
(open)
(terminals on)
(pinCenter 170 300))
(devCarrierFor 4
(active icon)
(icon
(extent 68 51)
(iconImage "loop.icn"))
(open)
(terminals on)
(pinCenter 80 500))
(devCarrierFor 5
(active open)
(icon)
(open
(extent 67 51))
(terminals on)
(pinCenter 145 590))
(devCarrierFor 6
(active open)
(icon)
(open
(extent 47 22))
(title off)
(pinCenter 290 580))
(devCarrierFor 7
(active icon)
(icon
(extent 92 15))
(open)
(terminals on)
(pinCenter 330 620))
(devCarrierFor 8
(active open)
(icon)
(open
(extent 84 31))
(terminals on)
(pinCenter 130 210))
(connect D3:1 D0:0
(points 5 206 300 230 300 230 340 220 340 220 360))
(connect D0:2 D2:1
(points 4 283 440 300 440 300 480 330 480))
(connect D8:0 D3:0
(points 4 140 228 140 250 170 250 170 272))
(connect D8:0 D4:0
(points 4 140 228 140 250 80 250 80 472))
(connect D4:1 D5:0
(points 3 116 500 150 500 150 544))
(connect D5:1 D6:0
(points 5 221 580 240 580 240 550 290 550 290 566))
(connect D6:1 D7:0
(points 3 316 580 330 580 330 610))
(connect D0:1 O1:1
(points 4 283 400 300 400 300 401 597 401)))
(stackingOrder 4 5 6 7 3 8 0 2 1)))))
(device 1 TEXTDISPLAY
(interface
(input 1
(name "Data"))))
(device 4 CALL
(properties
(name "Call NoOK")
(callFunc "NoOK")
(parmMode rev30))
(interface
(output 1
(name "X")
(lock name constraints)
(optional yes))))
(configuration
(connect D1:1 D0:1)))
(contextCarrier
(wndOrigin 2 2)
(wndState res)
(active detail)
(detail
(extent 790 607)
(anchorPt 0 0)
(configuration
(devCarrierFor 1
(active open)
(icon)
(open
(extent 121 22))
(pinCenter 520 170))
(devCarrierFor 4
(active open)
(icon
(extent 63 0))
(open
(extent 176 51))
(terminals on)
(pinCenter 300 170))
(connect D1:1 D0:1
(points 2 420 170 457 170)))
(stackingOrder 0 1))
(numberFormats
(realFormat standard)
(realSigDigits 4)
(realRadixSpec 4)
(integerBase decimal))))
--------------------------------- cut here ----------------------------------

Outcomes