Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Calculating

Posted on 2002-03-26
2
Medium Priority
?
266 Views
Last Modified: 2010-05-02
I would like to know how i can calculate the total for each product.
i have 4 textboxes that are control arrays

txtUnitPrice(Index)
txtQuantity(Index)
txtDiscount(Index)
txtTotal(Index)

i tried this

txtTotal(Index) = CDbl(txtUnitPrice(Index)) * CDbl(txtQuantity(Index)) / CDbl(txtDiscount(Index))

it doesn't seem to work

where would be the best place to put this code so that the total is
automatically calculated?
0
Comment
Question by:digitaldestruction66
2 Comments
 
LVL 22

Accepted Solution

by:
rspahitz earned 200 total points
ID: 6897827
I'd put it into a subroutine that's called by the Change event (or maybe the LostFocus event) of each of the textboxes:

private sub txtUnitPrice_Change(Index as integer)
   UpdateTotal Index
end sub

private sub txtQuantity_Change(Index as integer)
   UpdateTotal Index
end sub

...

private sub UpdateTotal(Index as integer)
  ' note that ".text" was added to each to make it .Net-compliant...it's also good practice
  txtTotal(Index).text = CDbl(txtUnitPrice(Index).text) * CDbl(txtQuantity(Index).text) / CDbl(txtDiscount(Index).text)
end sub
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 6898143
Dear digitaldestruction66,

You can put this code in either Change event, LostFocus event or in Validate event of the text box. In the Change event your value will be calculated if you cange anything in the textbox where as in LostFocus event the calculation will be done when the focus is lost from any of the textbox. In case of Validate event, which fires just before the LostFocus event, you can calculate your value too. The difference between LostFocus and Validate event is that in Validate event you can perform some validations and if the entered values are valid then only calculate the value and permit the cursor to move to the next textbox other restrict the cursor to the same textbox by setting the Cancel=True (The LostFocus event does not have the Cancel parameter!!).

I hope this will help you.

Thanks,
KarcOrigin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month20 days, 18 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question