Hi,
I have been away from building FiveWin applications for quite a while. What I need to do is depending on a user input in a form's field I need to disable certain fields and perhaps colour them differently.
In other cases again depending on the user input I need to populate multiple field automatically and display the updated form.
If any example exist of these requirement, I would appreciate seeing them.
Currently I am using FWH 2.7
Thanks,
Vytas
Input form
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Input form
To change color
oGet:setColor( nClrFore, nClrBack)
To fill with data:
oGet:varPut( uData )
oGet:setColor( nClrFore, nClrBack)
To fill with data:
oGet:varPut( uData )
Re: Input form
Hi Again,
What am I doing wrong? I have tried various variables in the two valid statements and cannot get anything to work. I searched the web without any luck in finding any sample code doing what I want to do.
Thanks again,
Vytas
...
DEFINE DIALOG oEdit RESOURCE "ATTRIBUTES"
REDEFINE SAY oPoly_Area VAR POLY_AREA ID 1007 OF oEdit UPDATE
REDEFINE GET oLand_Base VAR LAND_BASE ID 1008 OF oEdit UPDATE VALID Check(LAND_BASE,"V%N%M%S%") PICTURE "@!"
REDEFINE GET oLand_Cover VAR LAND_COVER ID 1009 OF oEdit UPDATE VALID oEdit:oLand_Pos:setColor(CLR_HGRAY, CLR_HGRAY)
REDEFINE GET oLand_Pos VAR LAND_POS ID 1010 OF oEdit UPDATE VALID (oEdit:oVeg_Type:varPut("X"))
REDEFINE GET oVeg_Type VAR VEG_TYPE ID 1011 OF oEdit UPDATE
REDEFINE GET oDensity_Cl VAR DENSITY_CL ID 1012 OF oEdit UPDATE
...
What am I doing wrong? I have tried various variables in the two valid statements and cannot get anything to work. I searched the web without any luck in finding any sample code doing what I want to do.
Thanks again,
Vytas
...
DEFINE DIALOG oEdit RESOURCE "ATTRIBUTES"
REDEFINE SAY oPoly_Area VAR POLY_AREA ID 1007 OF oEdit UPDATE
REDEFINE GET oLand_Base VAR LAND_BASE ID 1008 OF oEdit UPDATE VALID Check(LAND_BASE,"V%N%M%S%") PICTURE "@!"
REDEFINE GET oLand_Cover VAR LAND_COVER ID 1009 OF oEdit UPDATE VALID oEdit:oLand_Pos:setColor(CLR_HGRAY, CLR_HGRAY)
REDEFINE GET oLand_Pos VAR LAND_POS ID 1010 OF oEdit UPDATE VALID (oEdit:oVeg_Type:varPut("X"))
REDEFINE GET oVeg_Type VAR VEG_TYPE ID 1011 OF oEdit UPDATE
REDEFINE GET oDensity_Cl VAR DENSITY_CL ID 1012 OF oEdit UPDATE
...
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Input form
The VALID clause must return a logical value:
VALID ( oEdit:oLand_Pos:setColor( CLR_HGRAY, CLR_HGRAY ), .T. )
With the current FWH version, what you want to do is already implemented and it is as easy as:
SetGetColorFocus( CLR_YELLOW ) // or whatever color you may want to use for the focused GET
VALID ( oEdit:oLand_Pos:setColor( CLR_HGRAY, CLR_HGRAY ), .T. )
With the current FWH version, what you want to do is already implemented and it is as easy as:
SetGetColorFocus( CLR_YELLOW ) // or whatever color you may want to use for the focused GET
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Input form
Vytas,
This syntax is incorrect:
REDEFINE GET oLand_Cover VAR LAND_COVER ID 1009 OF oEdit UPDATE VALID oEdit:oLand_Pos:setColor(CLR_HGRAY, CLR_HGRAY)
It should be something like this:
REDEFINE GET oLand_Cover VAR LAND_COVER ID 1009 OF oEdit UPDATE ;
VALID (oLand_Pos:setColor(CLR_HGRAY, CLR_HGRAY), .t. )
Note that you have to return a logical from a VALID codeblock. Also note that you can't do oEdit:oLand_Pos, but rather just oLand_Pos. All the controls are stored in an array of the dialog object, so the dialog object doesn't have vars matching the names of the vars (such as oEdit:oLand_Pos).
If you want them disabled, you should just do:
REDEFINE GET oLand_Cover VAR LAND_COVER ID 1009 OF oEdit UPDATE ;
VALID (oLand_Pos:disable(), .t. )
Disabling also changes the colors to standard disabled colors, I believe.
However, this is going to get incredibly complex, because you have to also re-enable some GETs if the user goes back and changes the GET or GETs that the disable depends on. For example:
...if GET1=10 .and. GET3="cat" then disable GET5, GET8, and GET9
But if the user then changes either GET1 or GET3, then GET5, GET8, and GET9 have to be re-enabled, and perhaps other GETs have to disabled. Whew!
Just because something can be done, doesn't mean that it should be.
I don't know how complicated your logic plan is, but if it is more than 2 to 3 options, then perhaps you should rethink your design. You could do sequential dialogs like a "wizard." This would be easier to program and less likely to confuse the user.
Regards,
James
This syntax is incorrect:
REDEFINE GET oLand_Cover VAR LAND_COVER ID 1009 OF oEdit UPDATE VALID oEdit:oLand_Pos:setColor(CLR_HGRAY, CLR_HGRAY)
It should be something like this:
REDEFINE GET oLand_Cover VAR LAND_COVER ID 1009 OF oEdit UPDATE ;
VALID (oLand_Pos:setColor(CLR_HGRAY, CLR_HGRAY), .t. )
Note that you have to return a logical from a VALID codeblock. Also note that you can't do oEdit:oLand_Pos, but rather just oLand_Pos. All the controls are stored in an array of the dialog object, so the dialog object doesn't have vars matching the names of the vars (such as oEdit:oLand_Pos).
If you want them disabled, you should just do:
REDEFINE GET oLand_Cover VAR LAND_COVER ID 1009 OF oEdit UPDATE ;
VALID (oLand_Pos:disable(), .t. )
Disabling also changes the colors to standard disabled colors, I believe.
However, this is going to get incredibly complex, because you have to also re-enable some GETs if the user goes back and changes the GET or GETs that the disable depends on. For example:
...if GET1=10 .and. GET3="cat" then disable GET5, GET8, and GET9
But if the user then changes either GET1 or GET3, then GET5, GET8, and GET9 have to be re-enabled, and perhaps other GETs have to disabled. Whew!
Just because something can be done, doesn't mean that it should be.
I don't know how complicated your logic plan is, but if it is more than 2 to 3 options, then perhaps you should rethink your design. You could do sequential dialogs like a "wizard." This would be easier to program and less likely to confuse the user.
Regards,
James
Re: Input form
Thanks for the input you provide a lot of things I need to consider.
I still cannot get the color of a field to change. Am I missing a ch file or is something else causing it not to work?
REDEFINE GET oLand_Cover VAR LAND_COVER ID 1009 OF oEdit UPDATE VALID (oSOIL_MOIST:setColor(CLR_YELLOW, CLR_BLUE),oEdit:Update(),.t.)
If I populate the valid statement with values to autofill it works correctly. However, when I try to use a validation function it fails. What do I need to do to allow me to autofill from a function?
REDEFINE GET oVeg_Type VAR VEG_TYPE ID 1011 OF oEdit UPDATE VALID(Veg_Typ(oVeg_Type))
FUNCTION Veg_Typ(Typ)
DO CASE
CASE Typ = "WA"
oLand_Base:varPut("N")
oLand_Cov:varPut("W")
oLand_Pos:varPut("W")
....
return .t.
Thanks,
Vytas
I still cannot get the color of a field to change. Am I missing a ch file or is something else causing it not to work?
REDEFINE GET oLand_Cover VAR LAND_COVER ID 1009 OF oEdit UPDATE VALID (oSOIL_MOIST:setColor(CLR_YELLOW, CLR_BLUE),oEdit:Update(),.t.)
If I populate the valid statement with values to autofill it works correctly. However, when I try to use a validation function it fails. What do I need to do to allow me to autofill from a function?
REDEFINE GET oVeg_Type VAR VEG_TYPE ID 1011 OF oEdit UPDATE VALID(Veg_Typ(oVeg_Type))
FUNCTION Veg_Typ(Typ)
DO CASE
CASE Typ = "WA"
oLand_Base:varPut("N")
oLand_Cov:varPut("W")
oLand_Pos:varPut("W")
....
return .t.
Thanks,
Vytas
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Input form
Vytas,
You have to pass all the get objects that you need to deal with. And you have to pass the dialog object so you can refresh it ( refreshing redisplays the colors).
A better way would be to build a class. That way you wouldn't have to pass anything.
Like I said, this can get complicated.
Regards,
James
You have to pass all the get objects that you need to deal with. And you have to pass the dialog object so you can refresh it ( refreshing redisplays the colors).
A better way would be to build a class. That way you wouldn't have to pass anything.
Like I said, this can get complicated.
Regards,
James
Code: Select all
REDEFINE GET oVeg_Type VAR VEG_TYPE ID 1011 OF oEdit;
UPDATE VALID Veg_type(oVeg_Type, oLand_base, oLand_pos)
...
FUNCTION Veg_Typ(oVeg_type,oLand_base,oLand_pos, oDlg)
DO CASE
CASE oVeg_type:varGet() = "WA"
oLand_Base:varPut("N")
CASE oVeg_type:varGet() = ...
oLand_Cov:varPut("W")
CASE oVeg_type:varGet() = ...
oLand_Pos:varPut("W")
...
ENDCASE
// change the colors here...
oDlg:refresh()
Return .t.
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Input form
Vytas,
Here is a working example.
Regards,
James
Here is a working example.
Regards,
James
Code: Select all
/*
Purpose: Show how to change colors and contents of a GET
based on input of another GET
Author : James Bott
Date : 7/27/2015 3:55:35 PM
*/
#include "fivewin.ch"
Function main()
local oEdit, Veg_Type:=" " , land_base:=space(4), land_pos:=space(4)
define dialog oEdit SIZE 240,180
@ 1, 1 GET oVeg_Type VAR VEG_TYPE OF oEdit ;
PICTURE "@!A" ;
UPDATE VALID Veg_type(oVeg_Type, oLand_base, oLand_pos, oEdit)
@ 3, 1 GET oLand_Base var land_base of oEdit UPDATE
@ 5, 1 GET oLand_pos var land_pos of oEdit UPDATE
activate dialog oEdit centered
Return nil
FUNCTION Veg_Type(oVeg_type,oLand_base,oLand_pos,oEdit)
oLand_Base:enable()
DO CASE
CASE oVeg_Type:varGet() = "WA"
oLand_Base:varPut("N")
oLand_Base:disable()
CASE oVeg_Type:varGet() = "AA"
oLand_Base:varPut("W")
oLand_Base:setColor(CLR_BLUE,CLR_YELLOW)
CASE oVeg_Type:varGet() = "BB"
oLand_Pos:varPut("W")
oLand_Pos:setColor(CLR_BLUE,CLR_HCYAN)
//...
ENDCASE
oEdit:refresh()
Return .t.
// EOF
Re: Input form
Thanks James,
You have set me on the right path. However I still have two issues that are not working. Once I auto populate several fields I want the function to set focus to a field 4 spaces over. What I get is the focus going to the first field on the form. Also the color does not want to be set. What am I missing?
Thanks,
Vytas
FUNCTION Test_Chk(oSpec_Nu1_1,oGenus1_1,oSpecies1_1,oVariety1_1,oPercent1_1,oEdit,aLookup)
Sp := oSpec_Nu1_1:varGet()
Loc := ASCAN(aLookup, {|aVal| aVal[1] == Sp})
IF Loc > 0
oGenus1_1:VarPut(aLookup[Loc,2])
oSpecies1_1:VarPut(aLookup[Loc,3])
oVariety1_1:VarPut(aLookup[Loc,4])
oEdit:SETFOCUS(oPercent1_1)
oPercent1_1:setColor(CLR_BLUE,CLR_YELLOW)
oEdit:update()
ELSE
? "Species code not found in lookup"
ENDIF
...
You have set me on the right path. However I still have two issues that are not working. Once I auto populate several fields I want the function to set focus to a field 4 spaces over. What I get is the focus going to the first field on the form. Also the color does not want to be set. What am I missing?
Thanks,
Vytas
FUNCTION Test_Chk(oSpec_Nu1_1,oGenus1_1,oSpecies1_1,oVariety1_1,oPercent1_1,oEdit,aLookup)
Sp := oSpec_Nu1_1:varGet()
Loc := ASCAN(aLookup, {|aVal| aVal[1] == Sp})
IF Loc > 0
oGenus1_1:VarPut(aLookup[Loc,2])
oSpecies1_1:VarPut(aLookup[Loc,3])
oVariety1_1:VarPut(aLookup[Loc,4])
oEdit:SETFOCUS(oPercent1_1)
oPercent1_1:setColor(CLR_BLUE,CLR_YELLOW)
oEdit:update()
ELSE
? "Species code not found in lookup"
ENDIF
...