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

Hi, I need to print only "true" marked records 2

Status
Not open for further replies.

Paul77fox

Technical User
Feb 6, 2013
14
0
0
IT
Hello guys. I'm very new in visual foxpro and I need help for a simple project.
I have one table, one form, one grid in that form and I need to know three things:

1. How do I program the DblClick procedure of my logical field's header, to change all values in "true" and viceversa (if they are all "true" to make them all "false")
2. How do I program my report command button to print only the records marked with "true"
3. In case that they are all "false" and I hit the report button, avoid an error and eventually pop up a message with the text "Invalid print selection" (I placed check boxes in the logical field)

Am I asking for too much? [smile] I will really appreciate your help. Thank you!
 
Am I asking for too much?

Based on the difference between the 3 questions, you should have posted each one as a separate question.
In that way others looking for similar answers can find specifically responses to that question on its own,

So I'll address only question #1.

A Grid has numerous Columns and each Column has its own Header.
Each separate Header has both Click and DoubleClick Methods into which code can be placed.

Good Luck,
JRB-Bldr

 
1. Update table Set field=.T.
Without any further WHERE clause changees all fields
I hope it's clear you can also set all fields .F. in the same way.
What I wouldn't do is make that depend on what fields are set to right now. No matter how each field is set, you should toggle between .T. and .F. and know what you want to set next, set a property, eg the Header.TAG to "T" or "F" and toggle that to decide what next to put into the table field.

2. REPORT FORM... FOR logicalfield=.T. will only print selected
3. COUNT FOR logicalfield=.T. TO lnCount / If lnCount=0 warn about it.

Instead of the logical expression logicalfield=.T. you can also simply use the logicalfield alone, it's already the logical value itself. I tend to make this abbreviation of expressions, but explicitly writing logicalfield=.T. makes it clearer.

Bye, Olaf.
 
Hi Paul,

Welcome to the forum.

I interpret your first question to mean that, if the field is currently false, you want it to be true; if it's currently true, you want it to be false; and you want to do that for all fields at the samem time with one double-click.

If that's correct, then this is the code you need in the DblClick event of the grid's column's header:

Code:
UPDATE MyTable SET MyLogicalField = NOT MyLogicalField

where MyTable is the name (or, more precicely, the alias) of the table in question, and MyLogicalField is the name of the logical field.

In short, the NOT operator simply reverses the value of a logical field.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike has understood that differently than I have, but that's of course also an option. It would reverse any state, though. And not toggle all checkboxes to checked/unchecked. Typically you make a header click, or a seperate buttons, or two seperate buttons set all fields .t. or .f., no matter how hte're set, because a user eihter wants to set all .f. and then pick some, or set all .t. and then uncheck some records. That's a typicall well working workflow. While inversing the current selection often is not what you need and not even close to what you need.

But it surely is a good example on the NOT operator and on how to make the code easy. You can also use the dblclick, click and right click to do all three things.

Bye, Olaf.
 
Yes Olaf, it's true. It's just like a generic invert selection. In fact I wanted to make manual selection of records to print and use the header doubleclick to at first deselect them all and then, at the next doubleclick, select all and so on.
But I think this is not so easy. For me at least :)
 
In fact I wanted to make manual selection of records to print and use the header doubleclick to at first deselect them all and then, at the next doubleclick, select all and so on.

Since you would be doing this to ALL records, you could certainly put code into the appropriate Column Header Method (Click or DoubleClick) to test the first record to determine the Current setting and then set ALL record's value to the opposite.

But instead of doing this via the Column's Header Method's I typically put one or more CheckBox, OptionGroup, or Buttons somewhere on the form (Beside or Below the Grid) and use it to make similar specific or general record selections.

If I want to give my users more than a single ON/OFF option, I use either a CheckBox.
If I want to allow my users multiple, but single ON/OFF choices I generally use an OptionGroup.
But if I only want them to have a single ON/OFF, I use a Button.

Good Luck,
JRB-Bldr

 
Another reason to do what JRB-Bldr suggests is that, in some grids, clicking or double-clicking on a column header has the effect of sorting the grid on that column. That's not native VFP behaviour, but it is nevertheless a common interface, and it's something that many users expect. You don't want them to think they are sorting the grid, only to see the values changing within the grid.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Well, I told how you could use the same event, eg the dblclick, to toggle. Mikes idea would also work, make it dependant on the first record only. But you can use the header TAG property or add a user defined, just to store, what you last set:

dblclick event

Code:
Local llNextValue
Do Case
   Case This.TAG = "F" && next value should be .F.
        llNextValue = .F. && make it so
        This.Tag = "T" && and toggle the TAG for the next dblclick
   Case This.Tag = "T" && next value should be .T.
        llNextValue = .T. && make it so
        This.Tag = "F" && and toggle the TAG for the next dblclick
   Otherwise
       * This only happens, if you forget to init the Tag to either "T" or "F", so do that.
       * Either in the Init do This.Tag = "T" or in the property window set the header.TAG value to T.
EndCase        

update table set field = llNextValue

Via such a case statement you can go through as many states as you want, not just two.

It would be more ideal to have a separate user defined header property, but the TAG is intended for simple use in cases you don't want to go for subclassing the native classes. And in the case of the header this is double as complicated as normally, as it's taken some steps to put another header class into a grid. But the TAG property is already there. It has no meaning, it's there for whatver purpose you want to use it. Just don't overdo it, you can only have one use for it at a time, but it can be used as a temporary storage for states or anyhting you like. You could also misuse the COMMENT property. It just has to be string type, what you put in there.

Bye, Olaf.

 
You don't want them to think they are sorting the grid, only to see the values changing within the grid.
That's also very treu, and indeed even though a logical field column only sorts two groups of records, it's a practical usage to sort all selected records up. And so this kind of user interface more often is done via an additional checkbox at the top or bottom of the column. That would simply toggle it's value without any code and in it's interactivechange you could do Update table set field = this.value.

Bye, Olaf.
 
Olaf you make me think that everything is possible in programming if you have the right knowledge. Even a stupid reqest like mine above. And I say stupid because I just realised that I will never print all the records of my tabel. Not all at once at least :) The idea was to easily check all the boxes if I need to print everything and then of course to uncheck them all without interfering with manual check. I tryed the code you gave me but it doesn't work. It only uncheck all and the next doubleclick has no effect. But again it's ok, I don't need it. I will only use the line "UPDATE table SET field = .F." to uncheck all after the printing session.

Thanks a lot everyone!
 
Olaf you make me think that everything is possible in programming if you have the right knowledge.

I haven't seen it for some time now, but a while ago someone else had a signature 'tag' line - I am most likely not remembering it EXACTLY correct, but it was something like ...

With VFP can do everything, except keep a woman happy.[/i]

Yes, that's politically incorrect and I apologize to those of us who are the fairer gender, but it seemed applicable to Paul's comment.

Good Luck,
JRB-Bldr

 
Paul, you just forgot to reqad what I gave you and follow instruction I gave in the comments of the code. Please init the TAG property. If you don't the variable llNextValue will always stay .F. and you only uncheck all.

Bye, Olaf.
 
Works like a charm Olaf. Sorry, I did't pay attention to the comments. I think I've just learn the most important programming lesson. Reading the comments carefully :) Thank you for everything!
 
Well, Paul.

We're all just humans, not processors. I could have put that essential instrucition into the text. I could have added an header.init code section merely doing This.TAG = "T", I could have used the Otherwise section to init the TAG to "T", so the next time it would have caused the first case.

In the end, one thing is true: Comprehend instead of copy. Or as it's more of a pun in the german language "kapieren statt kopieren".

I wasn't putting this up intentionally. But you should perhaps take a look at how it works and that it can't start working, if TAG isn't inited as either "T" or "F", because then you never execute one of the two cases toggling the TAG.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top