Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a Dynamic Forecolor 2

Status
Not open for further replies.

David Higgs

Programmer
May 6, 2012
392
GB
I have the following code in my GRID :-

Code:
this.SetAll("DynamicforeColor", "IIF(net_list.UserStatus = [A], RGB(255,0,0), RGB(0,0,255))", "Column")

I would like to add another option :-

Code:
"IIF(net_list.UserStatus = [X], RGB(255,0,0), RGB(0,0,255))"

how would I go about this to achieve one color for [A] & [X] and another color for the rest?

Regards,
David
 
Please try
Code:
this.SetAll("DynamicforeColor", "IIF(net_list.UserStatus = [A] OR net_list.UserStatus = [X], RGB(255,0,0), RGB(0,0,255))", "Column")

or
Code:
this.SetAll("DynamicforeColor", "IIF(INLIST(net_list.UserStatus, [A], [X]), RGB(255,0,0), RGB(0,0,255))", "Column")

if you choose to use more than two colors, then:
Code:
this.SetAll("DynamicforeColor", "ICASE(net_list.UserStatus = [A], RGB(255,0,0), net_list.UserStatus = [X], RGB(0,255,0), RGB(0,0,255))", "Column")
or
Code:
this.SetAll("DynamicforeColor", "IIF(net_list.UserStatus = [A], RGB(255,0,0), IIF(net_list.UserStatus = [X], RGB(0,255,0), RGB(0,0,255)))", "Column")

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
I would just change = [A] to $ [AX]:
Code:
this.SetAll("DynamicforeColor", "IIF(net_list.UserStatus $ [AX], RGB(255,0,0), RGB(0,0,255))", "Column")

You should know all operators, not only =, David, take an hour and look at the possibilities beyond = < and >, there also are #, !=, and $ as direct operators and the INLIST() and LIKE() functions are giving you sql like operators for any normal code, besides IIF() being accompanied by ICASE. Most of this already shown by Vilhelm-Ion.

If you don't learn the few basic bricks of development you will always need much time to discover a way, though OR should also be among your knowledge and Vilhelm-Ion also showed that as first way to extend your code.

If all else fails create a new form method and call it to be able to write verbose multi line code IF or case statements:
Code:
this.SetAll("DynamicforeColor", "Thisform.UserStatusColor(net_list.UserStatus)", "Column")

Then you can have code as verbose as you need in Thisform.ImportantUserStatus(), you just need to return the wanted color:
Code:
LPARAMETERS tcUserStatusLetter
Local lnReturnColor
DO CASE
   CASE tcUserStatusLetter = [A]
      lnReturnColor = RGB(255,0,0)
   CASE tcUserStatusLetter = [X]
      lnReturnColor = RGB(255,0,0)
   OTHERWISE
      lnReturnColor = RGB(0,0,255)
ENDIF
Return lnReturnColor

That method structure should be easy to extend as needed. You can still also use IF and $ to shorten code, eg:
Code:
LPARAMETERS tcUserStatusLetter
Local lnReturnColor
DO CASE
   CASE tcUserStatusLetter $ [AX]
      lnReturnColor = RGB(255,0,0)
   OTHERWISE
      lnReturnColor = RGB(0,0,255)
ENDIF
RETURN lnReturnColor

Code:
LPARAMETERS tcUserStatusLetter
Local lnReturnColor
IF tcUserStatusLetter $ [AX]
   lnReturnColor = RGB(255,0,0)
ELSE
   lnReturnColor = RGB(0,0,255)
ENDIF
RETURN lnReturnColor

Code:
LPARAMETERS tcUserStatusLetter
RETURN IIF(tcUserStatusLetter $ [AX], RGB(255,0,0), RGB(0,0,255))

But the more verbose code may be easier to maintain and extend for you.

Bye, Olaf.
 
You might also document the meaning of the code, even for yourself after several years:

Code:
LPARAMETERS tcUserStatusLetter
#DEFINE ccUserStatusAlerted [A]
#DEFINE ccUSerStatusExcited [X]
#DEFINE cnStatusColorAlertedOReXcited RGB(255,0,0)
#DEFINE cnStatusColorDefault RGB(0,0,255)

Local lnReturnColor
DO CASE
   CASE tcUserStatusLetter = ccUserStatusAlerted OR tcUserStatusLetter = ccUSerStatusExcited 
      lnReturnColor = cnStatusColorAlertedORExcited 
   OTHERWISE
      lnReturnColor = cnStatusColorDefault 
ENDIF
Return lnReturnColor

Whatever A and X really mean.

Bye, Olaf.

 
Vilhelm-Ion / Olaf

Thank you both for your replies and Example Codes, it was very much appreciated.

I knew when I started this thread that I was asking a basic question that I should
have known the answer to. I did check the help files and did a Google Search which
provided the information that I required. However when re-typing the Code in my project
I kept getting syntax errors. Maybe just a case of having a " . " in the wrong place?

Although I started playing with Databases from around dBASE III + era, I've only
really scratched the surface with VFP. It was not until finding Tek-Tips around the time
I was made redundant (at the age of 62) from Service Sector of the Steel Industry
that I've had the time look further into my applications. Although my applications
do exactly what I want, they are definitely not efficient code. It is talking with
you guys that gives me the help that I need to improve and progress these applications.

Once again, thank you for helping me out with such a basic question.


Regards,
David
 
vgulielmus said:
this.SetAll("DynamicforeColor", "IIF(net_list.UserStatus = [A], RGB(255,0,0), IIF(net_list.UserStatus = [X], RGB(0,255,0), RGB(0,0,255)))", "Column")

Vilhelm-Ion,

This was very similar to the code that I was trying to but couldn't get it to work, as I said above, I must of had " , " or something in the wrong place!!

Needless to say, your Code worked perfectly.

Regards,
David
 
Well, no need to start another nested IIF within in an IIF, if you don't need a third result value. It asks for getting the nesting wrong.
If you type a closing bracket, the editor will shortly highlight the opening bracket you close with it. That's also something you only experience, when you write code.

Bye, Olaf.
 
Olaf said:
Well, no need to start another nested IIF within in an IIF, if you don't need a third result value.

As the application evolves I will be adding other "Result Values" for FORECOLOR and BACKCOLOR , but hopefully I have enough information now to proceed.

Regards,
David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top