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

Conditional Display of Text / Background Colour

Status
Not open for further replies.

David Higgs

Programmer
May 6, 2012
392
GB
Hi,

On my Form I have drawn a "shape" in the form of a square. I have made a grid of 10 x 10 Squares and each square contains a "text box" (containing the number of the square). I would like to conditionally display the contents of the "text box" and also the "backcolor" of each "shape". I have tried "thisform.textbox.text56.Visible =.F." but this produces an error "unknown member TEXTBOX".

Any help would be most appreciated.



Regards,
David
 
The contents of the 10 x 10 "Squares" is simply either "a two digit number" (00 to 99) or "blank". The Backcolor will be either Green or white.

So for instance, assuming for now in our example all of the 100 small squares are valid, the contents of the squares will be populated with "00 to 99" with a white background. e.g. sm_sq_00 = "00" to sm_sq_99 = "99" (If the square is not valid e.g. sm_sq_05 =" ")

So just prior to running the form the database will provide information as to whether:-
(a) the square is valid e.g. sm_sq_05 = "05" or not sm_sq_05 =" "
(b) a contact has been made in any or all of the squares. If yes the backcolor is changed to green.

e.g Station worked in square 56 then variable sq_56_worked = .T. change backcolor to green.

So all that's being fed to the form is:-
(a) square valid or not?
(b) square worked or not.
and from this information we know if to display the square number and the backcolor.

Maybe a better explanation is available here:- Link

Mike I will give some thought on your suggestion.

Regards,
David
 
As a sidenote: if I where to setup a form with 100 elements, I would put ONE textbox/label there with all the right properties and then open the SCX as a dbf (e.g. USE FORM.SCX), then locate the appropriate record and programatically insert the other 99 after the first, while changing the objects name accordingly.
 
You better have an array smallsquare[x,y] with x and y ranging from 1 to 10 each. As you display either a number or not, it would be sufficient to have .T. or .F. as values The value would either be (x-1)*10+y-1 or (y-1)*10+x-1, you don't need to store it. And for .F. values you display .NULL. with SET NULLDISPLAY TO "" you display nothing. You can do equally for the valid and worked values.

Bye, Olaf.



 
I think the whole task will be easier if you create a container class that represents a single one of these squares, so contains a shape and a label (or textbox). Then, you can add as many of these as you need to the form, or to another container that will go on the form.

You can do a surprising amount of graphics with just the standard VFP controls. Check out the pictures on page 5 of this document:
All built with native controls.

Tamar
 
Dr Dolittle said:
if I where to setup a form with 100 elements, I would put ONE textbox/label there with all the right properties and then open the SCX as a dbf (e.g. USE FORM.SCX), then locate the appropriate record and programatically insert the other 99 after the first, while changing the objects name accordingly.

I couldn't agree less. Hacking a DBF should be a last resort. It is completely unnecessary here. Much better to use the facilities provided by VFP to do the job.

In this case, you could achieve the same goal in about about five seconds, and without any risk of mucking up your SCX file: place one of the controls on a temporary form; Ctrl+A to select it; Ctrl+C to copy it: Ctrl+V to paste it. Repeat six times. You now have 128 copies; delete 28 of them. Finally drag the entire contents of the temporary form to your actual form. Not only is this quick and easy, but it has the advantage that all the controls will be named consecutively (eg. Mylabel1, Mylabel2).

I'd also second Tamar's suggestion of making a class of the control in question, and giving it the appearance and behaviour you need. I was going to suggest this myself, but it seemed so obvious that I didn't bother.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Many thanks for all of the help and suggestions, much appreciated. Quite a bit of it is over my head, so you will have to forgive me if I don't immediately follow your advice.

Ok, just to update you all.

Mike said:
I suggest you use a label for each of the small squares.
As the Information displayed is fixed I have decided to take Mike's advice. So we now have 10 x 10 Squares each with a Number from 00 to 99.

It is my intention to provide the form with two 10x10 Arrays. Each array will contain a number between 00 & 99 plus a logic Y/N. One array is for "Has Square nn been worked" Y/N and the other is for "is square nn valid" Y/N. Leaving aside for now how I get that info from the DBF to the Array, I have carried some tests with the following codes:-

Code:
&&	
&&		Sqaure Worked Y/N ?	
&&

*sq_83_worked = .T.

sq_83_worked = .F.

Thisform.shape_sq_83.BackColor = ;
	IIF(sq_83_worked = .T. , Rgb(0,204,0), Rgb(0, 128, 128))

Code:
&&	
&&		Is Sqaure Valid Y/N ?	
&&

THISFORM.sm_sq_77.Visible =.F.

*sq_77_valid = .T.	&& Valid

sq_77_valid = .F.	&& Not Valid

THISFORM.sm_sq_77.Visible = ;
	IIF(sq_77_valid = .T. , .T., .F.)

A couple of you have suggested designing a "Class" this is something I've not done before and haven't dismissed it but will require a lot more help to achieve this. So for the time being I hope I have a pragmatic solution which won't win any awards but will achieve what I set out to do.

So the next task is to produce a "FOR...ENDFOR LOOP".

[inden[/indent]

Regards,
David
 
David,

Good to see you are making progress. Now that you have got the basic structure in place, especially the arrays, it should be easy to work out how to do it in a loop.

Just one small point:

Instead of this:

THISFORM.sm_sq_77.Visible = ;
IIF(sq_77_valid = .T. , .T., .F.)

it would be slighly neater to do this:

THISFORM.sm_sq_77.Visible = sq_77_valid

The result is exactly the same, but with a little less code. If you don't understand why this should be so, don't worry. It's not essential.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello Mike,

Yes, we are making progress, once I got across what I was trying to achieve.

Thank you for the "quick tip" on the code; my code was a simple modification of the "backcolor" code, your code is much neater!

Just brushing up on the ARRAY and FOR..ENDFOR LOOP side of things.

Then I need to look at the code to interrogate the DBF for the ARRAY. Something along the lines of "SELECT FOR LARGE SQUARE = required square" which will list all of the small squares valid for display. There are 63 Large Squares containing up-to 100 Small Squares.

The DBF Fields of interest are along the lines of "AREA" and "date_worked". e.g. AREA = "SP83" SP is the Large Square and 83 is the Small Square. So from the DBF we pass on "Square Worked" valid y/n and "is square valid" y/n i.e is square in the DBF. If date_worked is not blank then "square_worked" is valid.


Regards,
David
 
I did not read the whole question/answers properly, but following may help.

Create new form and create a label or textbox (as Mike') with the proper size as you desire name it lblReference.

then in the init of the form insert the following

local t_LabelLength, t_LabelHeight, t_LabelLeft, t_LabelTop, ii, jj, t_label

t_LabelTop = thisform.lblReference.Top
t_LabelHeight = thisform.lblReference.Height
t_LabelWidth = thisform.lblReference.Width
t_LabelLeft = thisform.lblReference.Left

use mytable in 0 && open the database assuming you have only 100 records

* you may choose the grid size as 50x2, 20x5, 10x10, etc
for ii = 1 to 10
for jj = 1 to 10
ic=alltrim(str(ii))
jc = alltrim(str(jj))
t_label = "lbl_" + ic + '_' + jc
thisform.addobject(t_label,"label")
thisform.&t_label..visible = .t. && Pickup the valie from the table
thisform.&t_label..left = t_LabelLeft + (ii -1) * t_LabelWidth
thisform.&t_label..top = t_LabelTop = (jj -1) * t_LabelTop
thisform.&t_label..height = t_LabelHeight
thisform.&t_label..width = t_LabelWidth
thisform.&t_lable..caption = t_label && May be you hve this in the table so assign it here

* Setup other properties
thisform.&t_label..backcolor = rgb(0,240,100) && ~green or assign from the table

* skip && for testing purposes you may comment this out.

endfor
endfor

thisform.lblReference.visible = .f. && do not show the reference label


 
Just brushing up on the ARRAY and FOR..ENDFOR LOOP side of things.
Ok, so I'm nearly there, just need to sort this issue.

The following line works ok
Code:
THISFORM.sm_sq_77.Visible = sq_77_valid

I've replace the "sq_77" with a variable "&sq_valid" which appears to be working.

Code:
THISFORM.sm_sq_77.Visible =&sq_valid

I'm struggling with how to replace "sm_sq_77" with a variable, for instance with "this_square = sm_sq_77" the following produces an "unknown member" error.

Code:
THISFORM.this_square.Visible =&sq_valid

Is it possible to have "thisform.variable.visible = &sq_valid" ??


Regards,
David
 
Look at NasibKalsis code, how he uses & macro substitution in thisform.&t_label

Bye, Olaf.
 
NasibKalsi,

Thank you very much for your assistance, very much appreciated. Although my Form is reasonably complete now, your procedure will help me progress my understanding of VFP and will no doubt prove very useful on future forms.

Regards,
David
 
OlafDoschke said:
Look at NasibKalsis code, how he uses & macro substitution in thisform.&t_label
I looked through NasibKalsi's Listing and also read up on VFP Macro Substitution and I'm pleased to advise that the Form is now working as I set out to achieve.

Many thanks to all who have contributed to this thread, I have learned a a great deal. I shall have a further read on how I to improve my VFP knowledge.

Regards,
David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top