×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Mistakes incomprehensible reason

Mistakes incomprehensible reason

Mistakes incomprehensible reason

(OP)
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


RE: Mistakes incomprehensible reason

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

RE: Mistakes incomprehensible reason

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
https://www.doschke.name

RE: Mistakes incomprehensible reason

(OP)
Is there a way to get the combination correctly and at the same time store the results in the table?

RE: Mistakes incomprehensible reason

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
https://www.doschke.name

RE: Mistakes incomprehensible reason

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
https://www.doschke.name

RE: Mistakes incomprehensible reason

(OP)

Quote (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.)

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

RE: Mistakes incomprehensible reason

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
https://www.doschke.name

RE: Mistakes incomprehensible reason

(OP)
thank you very much..

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close