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!

Mistakes incomprehensible reason

Status
Not open for further replies.

ameedoo3000

IS-IT--Management
Sep 20, 2016
233
EG
Hi all
I have a small project that contains a student's name and grades in the exam.
When I set a score, I want to collect the grades automatically in the form without having to query or view.
This has already been implemented and in the interactivechange event of the column where the grade has been collected in the column of the total as shown in the attached form. But the total is illogical and wrong
Please explain why
a3_whsj14.png

a4_ukqnc5.png

a1_s2q8ol.png
 
You can't set the Value property of the textbox like that. The value that you see in a textbox within a column within a grid depends on the column's ControlSource property, not the textbox's Value property. You need to set the ControlSoruce to the expression that you want.

Alternatively, add a field to the underlying cursor. Before you populate the grid, fill that field with the required values. Then set the ControlSource of the corresponding column to point to that field.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike, there is the total field in the underlying cursor.

It's unclear in which textbox you do this interactivechange, all columns teextboxes are names Text1, there is Column1.Text1, Column2.Text1 and Column3.Text1. Column3 should be readonly as it only should dispaly the sum, when you want to change that the code has to be in both Column1.Text1.InteractiveChange AND in Column2.Text1.InteractiveChange.
You could still have a lag time between the sum updating. Especially if InteractiveChange happens before the value changes, the sum will be still the sum of the previous values.

To have a reliable sum you would not have a total field in your cursor at all but a third column that is bound to the expression (exam_1+exam_2), so you set the controlsource of the third grid column to that. And then you don't need any code, as soon as you leave a column the total is updated. It doesn't update while changing the value, but that's a luxury you can do without.

And you also don't store that total in the DBF, you always compute it for the grid that way or in a report or elsewhere. You don't store redundant data. That'll only lead to situations you have total <> exam_1 +exam_2 and not knowing which is wrong, exam_1, exam_2 or the total. Redundancy only would help, if it can indicate what value is erroneous, but in such a simple case you only store the single values and always only compute the total.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Is there a way to get the combination correctly and at the same time store the results in the table?
 
If you absolutely want, what hinders you? You'll bind the third column to the total field then, and your code in both columns should update that field, not Column3.text1.Value. You want this stored in that field, then go directly to that target.

Bye, Olaf.

Olaf Doschke Software Engineering
 
I strongly recommend to not store the total, though, you can always compute it. It's simply exam_1+exam_2. Even if that would extend. You don't store redundant data.

A bank stores a transaction log in the literal sense of all financial transactions done to an account. It shouldn't ever store account.amount, it should always compute that ideally from a series of cryptographically chained signed transactions. I'm not suggesting you go that far, but what good does it do to have that total stored?

Recomputing exam_1+exam_2 every time you need that sum to display it print it, whatever. That sum will take less time overall for all lifetime your software runs for as many users, who use it as many years it is active, less time than all that, than to discuss this issue here.

You don't store redundant information.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Excuse me
I would like to clarify more about achieving the combination of two fields and at the same time storing in the table.
and In which event the code is placed.
Greetings.
Ahmed

 
This isn't possible to do in just one place. You need to react to changes in Column1 and Column2. In both columns InteractiveChange you will do the same thing or at least call a third central method.

There is not one single way to do this, you're free to do it as you like, but of course, if you only had your code in one column InteractiveChange, this will not update the total, if you change the other column.

Why are you already overwhelmed by the task to sum two numbers? What's your difficulty? In the end, you don't need to, as said the single numbers are all you need and the total can always be computed from them.

Bye, Olaf.



Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top