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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forecolor change

Status
Not open for further replies.

DanNorris2000

Technical User
Nov 10, 2000
186
0
0
US
I cant seem to find a good example of this in the VFP 6.0 manuals. I have a field called ledger.netdue, if negative I would like the field to be displayed in a red font.
IF ledger.expbrkg < 0 ,
ledger.expbrkg.ForeColor[255,0,0]
endif ?
 
Are you talking about a control in a grid or browse? or a control in a form?
-Pete
 
it is a text box on a form. Actually it is a text box on a page frame
 
Or a report?
Use an Immediate If in whatever context you are using it for.
[tt]
#DEFINE RED 255
#DEFINE BLACK 0
This.ForeColor = IIF(ledger.expbrkg < 0, RED, BLACK)[/tt]
John Durbin
john@johndurbin.com
MCP Visual FoxPro
ICQ VFP ActiveList #73897253
 
Oh ok you mean IFF

do I place this code in the valid procedure of the textbox or form load?
 
Dan,

Refer to IIF() function in the VFP help.

PROCEDURE MyTextBox.Refresh()
THIS.Forecolor = IIF(THIS.Value<0,RED,BLACK)
ENDPROC Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
In attempting to follow this thread, I am having difficulty combining my instructions for the field:

=nz([ActualPeriod6])-nz([BudgetPeriod6])

with the Procedure:

PROCEDURE MyTextBox.Refresh()
THIS.Forecolor = IIF(THIS.Value<0,RED,BLACK)
ENDPROC

Where does my field instruction go in this code. Exactly what should the expression state in the control source?
 
Well,

=nz([ActualPeriod6])-nz([BudgetPeriod6])

would be the value of the text box or whatever you're displaying the number in. Then you'd issue the

MyTextBox.Refresh()

immediately afterwords. But where you use this code depends on when you're wanting to do the calculation. If you press a button to make the calculation, then put it in the click event of the button. If you're doing a more complicated thing, like calculating a budget, it might be in a separate program, even in a custom class method. Or it could be in the validate event of some text event where you want to show that the most recent entry results in a negative figure. You might even have it in the Init or Load events of a form if they need to pull up some figures, make calculation and then display the current situation.


 
Unfortunately, I am a notice VBA user so I apologize if my questions are basic, but when I try and place the procedure right after the text value statement in the expression builder I get a syntax error. I think I may not understand how the expression is to be exactly typed into the builder...I want this calculation to be made whenever the report is run so I assumed I would apply it to the specific fields. I have two calculated fields in the report that I want to appear in red if the calculation is less than zero.
 
Hi
Method 1...
-----------
Select the textBox (the textbox in the grid controlling your values) and add the code in Refresh event of that text box...
This.ForeColor = ;
IIF(This.Value < 0, RGB(255,0,0), RGB(0,0,255))


The above will get fired when ever there is a refresh of this text box, or of the form, or of the pageframe. The result will be, the amount will get displayed in Blue else it will be red.

Method 2:
---------
To achieve the same, you can put in the...
init event of the form.... the following code..

With ThisForm.MyPageFrame.myTextBox
.DynamicForeColor=IIF(.Value<0,RGB(255,0,0),RGB(0,0,255))
ENDWITH

Hope these help you
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
You can put in the InteractiveChange event of the object (textbox)...
the following code..

*!* ---------------------------------------
*!* InteractiveChange event
*!* ---------------------------------------
this.forecolor=IIF(this.value<0,RGB(255,0,0),RGB(0,0,0))

Hope these help you
 
I tried pasting the &quot;This.ForeColor = ;
IIF(This.Value < 0, RGB(255,0,0), RGB(0,0,255))&quot; in my text box control source property field right after my formula but get a syntax error message. Is there a join character that I need to place in there also? The event tab of my text box properties is blank so I am not able to try the other two suggestions.
 
I don't think you can change such things within a property. You need to have some method or event set both the forecolor value and the control source to be what you want.

As for accessing the events, you need to double click on the textbox to pull up the box which lets you write code in the events or methods. Just paste what you need in the appropriate event. --DAVE
 
When I double click on the text box the event tab shows up blank with no options. What am I doing wrong?
 
I don't know where you're finding this event tab. Are you using an earlier version of FoxPro? In FoxPro 6 if you modify a form in the Project Manager and double click on a control, you get a window with boxes showing the current object and procedure/event. The object you double clicked will show in the object box and an event or procedure will show in the procedure box. You need to pick whatever event you want to put code in and then add it. If you've got code to add to other events or objects you can do it without having to close the window and double click again. BTW, the code is compiled whenever you leave a given object or procedure, so if you make a syntax error you'll be notified and be able to correct it on the spot. --Dave
 
I right click on my text box in design mode (of a report). I click on properties. This brings up the properties box with tabs for format, data, event, other and all. When I click the event tab, there are no lines for me to enter an event.
 
Perhaps try right clicking near the top of the Property Sheet and uncheck the &quot;Non-Default Properties Only&quot; selection.

Rick
 
I'm sorry, I guess I read that you didn't have a Events/Methods to choose from. If you want to Add a new Method (you can't create new Events), then in the Form menu pad, choose New Method... or Edit Property/Method and choose New Method here.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top