Hot Topic (More than 10 Replies) [Solved] Changing color of an element (Read 1594 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
[Solved] Changing color of an element
Oct 5th, 2007 at 11:54am
Print Post Print Post  
I have a money element, Breakout_Total, which is a combined total of 5 other money elements.  It is filled when any of the other elements changes, and its value should equal my Invoice_Total.  It needs to be filled if a particular text field, Coding2, contains more than one character and if its value does not equal Invoice_Total.  I want to alert this need to my users by changing its color to a light red if both conditions are met (its default color is a grayish yellow).

I have tried the following code in On Form Entry, On Form Reveal, and On Draw:
Code
Select All
// Sets the color of the Breakout Total element

IF @LEN(Coding2) > 1
THEN
	{
	IF NOT (Breakout_Total = Invoice_Total3)
	THEN RGBColor(Breakout_Total, 0, 0, 0, 255, 100, 40)
	}
ELSE RGBColor(Breakout_Total, 0, 0, 0, 223, 229, 146) 


In each event usage I get strange results.  One is that the element will not change color unless you actually click on the form.  Until you do it remains the same color as the previously viewed form.  (And once it has been colored, the next form retains that color even if the conditions are incorrect, until, again, you click on the form.)

I'm hoping to be able to allow my users to just F10 from form to form, watching for a red element, but if they have to click on each form for it to change color the effort is pointless (I realize I could just do a programmed search on the length of Coding2, but my users couldn't unless I set up a command button for them).

Clearly there's something I'm overlooking or unaware of when it comes to conditional coloring of elements.  Any help would be appreciated.
« Last Edit: Oct 5th, 2007 at 3:33pm by Hammer »  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Changing color of an element
Reply #1 - Oct 5th, 2007 at 12:16pm
Print Post Print Post  
Try adding ForceRedraw() after changing the color.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Changing color of an element
Reply #2 - Oct 5th, 2007 at 12:58pm
Print Post Print Post  
Thank you.  Which element should I put my code in?
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Changing color of an element
Reply #3 - Oct 5th, 2007 at 1:50pm
Print Post Print Post  
Based on what it's doing, probably On Form Entry and anything that changes Breakout_Total or Invoice_Total3 or Coding2. You might want to make it a subroutine and just call that, so you don't have to repeat the whole thing in each place it is needed.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Changing color of an element
Reply #4 - Oct 5th, 2007 at 1:53pm
Print Post Print Post  
Thanks again Erika!
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Changing color of an element
Reply #5 - Oct 5th, 2007 at 2:40pm
Print Post Print Post  
I'm still not sure what I'm doing wrong.  I have the following code in On-Form Entry, in On Element Change for each element that changes Breakout_Total, and in On Element Change for Coding and Invoice_Total3.  It works great for any change made to the elements, but not for entering the form or F10-ing to a new form.  In that case it retains the color of the previous form even if the conditionals are not met.  By that I mean, if I change an element in a record coded "RT" (the length of coding is 2) so that the color of Breakout_Total becomes red, and then F10 to the next form which is coded "R" (length of coding is 1), the color of Breakout_Coding remains red, and continues to stay red to the next form and the next and so on, no matter what the length of Breakout_Total.  It stays green as well, red or green, whatever the changed record became.  The default color of Breakout_Color is grayish-yellow.
Code
Select All
// Sets the color of the Breakout Total
Subroutine SetBreakoutTotalColor()
IF Breakout_Total = Invoice_Total3
THEN
	{
	RGBColor(Breakout_Total, 0, 0, 0, 111, 255, 0)  // Black text on light green
	ForceRedraw()
	}
ELSE
IF @LEN(Coding) > 1
THEN
	{
	IF NOT (Breakout_Total = Invoice_Total3)
	THEN RGBColor(Breakout_Total, 0, 0, 0, 255, 100, 40)  // Black text on light red
	ForceRedraw()
	}
ELSE
IF @LEN(Coding) < 2
THEN
	{
	RGBColor(Breakout_Total, 0, 0, 0, 223, 229, 146)  // Black text on grayish-yellow
	ForceRedraw()
	}
End Subroutine 


Breakout_Total and Invoice_Total3 are money fields.  Coding is text.  Am I using ForceRedraw() incorrectly?
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Changing color of an element
Reply #6 - Oct 5th, 2007 at 3:04pm
Print Post Print Post  
Hello Scott,

Since every conditonal needs to do a ForceRedraw there is no need to put it in three times when once will do. Other than that are you sure you are calling the code in the Form on Form Entry event? The Subroutine should appear in Global Code and just be called from everywhere else.

I would write the code as seen below. It will compile faster and run faster than the code that you have.

Code
Select All
Subroutine SetBreakoutTotalColor()

	If Breakout_Total = Invoice_Total3 Then
	{
		RGBColor(Breakout_Total, 0, 0, 0, 111, 255, 0)  // Black text on light green
	}
	Else If @Len(Coding) >= 2 Then
	{
		RGBColor(Breakout_Total, 0, 0, 0, 255, 100, 40)  // Black text on light red
	}
	Else
	{
		RGBColor(Breakout_Total, 0, 0, 0, 223, 229, 146)  // Black text on grayish-yellow
	}
	ForceRedraw()

End Subroutine 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Changing color of an element
Reply #7 - Oct 5th, 2007 at 3:25pm
Print Post Print Post  
Quote:
Since every conditonal needs to do a ForceRedraw there is no need to put it in three times when once will do. Other than that are you sure you are calling the code in the Form on Form Entry event?

Oh my god, I'm so embarrassed.  I was so intent on getting it into the elements I forgot to actually put it in On Form Entry.  Please slap me with a fish.
Quote:
I would write the code as seen below. It will compile faster and run faster than the code that you have.

Ah Ray, I hope I someday to learn to write code as elegantly as you.  Thanks so much, and to Erika as well; it's all working beautifully now.
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Changing color of an element
Reply #8 - Oct 5th, 2007 at 3:32pm
Print Post Print Post  
Infinity wrote on Oct 5th, 2007 at 3:25pm:
Please slap me with a fish.

Erm. OK.
*gets fish out of river*
*slaps Scott with fish*
*throws fish back in river*
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
NICEBERG
Full Member
Members
***
Offline


I came, I saw, I'm still
trying to figure it out!

Posts: 208
Location: Green Bay, WI
Joined: Dec 17th, 2003
Re: [Solved] Changing color of an element
Reply #9 - Oct 5th, 2007 at 5:11pm
Print Post Print Post  
You're lucky it's only with a fish -- I usually get an electric eel used on me. But that's what it takes. Tongue
  
Back to top
 
IP Logged
 
Alec
Lanticans
*****
Offline



Posts: 200
Location: Ascot, England, UK
Joined: Nov 22nd, 2002
Re: Changing color of an element
Reply #10 - Oct 5th, 2007 at 5:22pm
Print Post Print Post  
Hammer wrote on Oct 5th, 2007 at 3:32pm:
Infinity wrote on Oct 5th, 2007 at 3:25pm:
Please slap me with a fish.

Erm. OK.
*gets fish out of river*
*slaps Scott with fish*
*throws fish back in river*


I have to point out that recent federal environmental legislation outlaws throwing back into the river fish that have been used to slap wayward programmers.
  

Alec
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: [Solved] Changing color of an element
Reply #11 - Oct 5th, 2007 at 5:36pm
Print Post Print Post  
oh thanks Alec,

Way to go, tellling Erika that she can't throw away the fish and she has to keep it. She'll be hitting us upside the head with it.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged