Accumulating and Counting / Complete Example
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
We now have a complete example of accumulating and counting, as well as some other techniques that have been discussed. Let's take a look at the complete program. When the project is executed, the user is allowed to enter some numeric data and then you can click the Calculate Button. That causes calculations to occur and the subtotal, sales tax and grand total are calculated. You then also have a grand total, accumulated total, accumulated sales tax and average sale. So as each transaction occurs, we're getting new data. I've added a reset button, which is clearing the contents of the text box, which simply allows us to enter data into a clean box. So I can enter new data once again and calculate and as you can see, all figures and calculations are updating correctly and once again I can reset and enter data. If the user chooses to enter bad data or accidentally enters bad data, there is a try-catch in the program which is preventing the run time error from occurring and the user could then realize their mistake and enter some good data and does not affect the calculations. And finally, there's an exit button, which is causing the program simply to terminate. Of course, you can always allow the user to use the X, but it's a good idea to use an exit button as well. It just makes it a little bit more user-friendly for the user. Taking one more look at the code, you will recall that we have a set of module-level variables that are accumulating both our accumulated totals as well as counting the number of transactions. We have local variables in our calculate button and we also have a local constant for the sales tax, which is .05. We're making use of the try-catch block by placing our data, our instructions within the try statement. It is making this possible for the message box to appear rather than letting the run time error occur. We, of course, need to convert the input data to the proper data type and into the appropriately named variables by using the parse statements. We then are performing simply calculations. Note that the calculations are being performed with the variables themselves, not with the text boxes or labels. We then are displaying the results in those labels and in the process we're converting that to a currency format to allow the dollar signs and rounding to two places. We're then also performing our accumulating statements to accumulate the grand totals and we also are counting the number of transactions and calculating the average by using our total transaction plus equal one. And here we have our very simple message box that could be enhanced to perform the function of the catch for the try-catch. The reset button is clearing the contents of the text boxes by using the clear method for both the quantity text box and the price text box and finally, to exit the program, all we need is simply our me.close statement. Me refers to the currently active form. The only form that would be open at this point in time would be that form that we've been working with. So that will close the program. This project is available on your disks and you would be able to download this and review this and make changes to it.
Tutorial Information
| Course: | Microsoft Visual Basic 2005 |
| Author: | Arthur Lee |
| SKU: | 33940 |
| ISBN: | 1-935320-10-6 |
| Release Date: | 2008-11-19 |
| Duration: | 7.5 hrs / 97 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 