473,396 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

getting a total?

lee123
556 512MB
hey all, i have made a order form with all the works. in vb 6 and in this form i have been trying to get a total of the items that a customer would have ordered. to make things make sense i have in my order form ( qty, product,unit price, and a total) there are 12 rows of these text boxes (1-44) i believe, any way on the bottom of the order form there is a (subtotal,salestax,final total.) now the question is.....(and it probably a simple one i have over looked) is how do you add all the text boxes (meaning totals which are numbered textboxes 4,8,12 and so on..) to get the subtotal which is (text45) and the salestax which is (text46) and the grand total.(final total) which is (text45) together to get the right grand total.
Jul 24 '07 #1
7 1817
Killer42
8,435 Expert 8TB
hey all, i have made a order form with all the works. in vb 6 and in this form i have been trying to get a total of the items that a customer would have ordered. to make things make sense i have in my order form ( qty, product,unit price, and a total) there are 12 rows of these text boxes (1-44) i believe, any way on the bottom of the order form there is a (subtotal,salestax,final total.) now the question is.....(and it probably a simple one i have over looked) is how do you add all the text boxes (meaning totals which are numbered textboxes 4,8,12 and so on..) to get the subtotal which is (text45) and the salestax which is (text46) and the grand total.(final total) which is (text45) together to get the right grand total.
Easy - use a loop with the Step clause to grab every fourth one.

As for how you access them, well, you would have made things much easier on yourself if you set them up as a control array. In fact, a separate control array for each column would be even better. That way, you could just loop through and grab the values from, say, txtQty(1) to txQty(12).

It would probably be a good idea to delete your textboxes and replace them with one or more arrays of textboxes. However, that may be more work than you want to put in at this point. So, here's a workaround.

Using the same loop idea, inside the loop you can access your texboxes like this...
Me.Controls("text" & format(loopcounter))
Jul 24 '07 #2
lee123
556 512MB
im a little confused is the code suppose to be:

Expand|Select|Wrap|Line Numbers
  1. me.controls("text 4" + "text8" + "text12" & format(loopcounter))
because it says that vb doesn't support this.
or then again i could be doing it wrong. right?

or

Expand|Select|Wrap|Line Numbers
  1. me.controls("text4" & format(loopcounter))
  2. me.controls("text8" & format(loopcounter))
or you mentioned control arrays how would that be done, if you don't mind telling me. or explaining to me because you said it might be alot easier ( or something along them lines) to do.

lee123
Jul 24 '07 #3
lee123
556 512MB
you know what (killer42) i was so caught up with getting the grand total i forgot to mention that all of the totals are controlled by a button which calculates the totals so when im done entering the (qty),(Product) and the (Unitprice) i press the calculate button and it calculates the totals, but not the grand total... this is where im having trouble getting it to display i don't know how to tie this in the button with the rest of the codes.....sorry about not getting it all out to you.

lee123
Jul 24 '07 #4
Killer42
8,435 Expert 8TB
im a little confused is the code suppose to be:

Expand|Select|Wrap|Line Numbers
  1. me.controls("text 4" + "text8" + "text12" & format(loopcounter))
...
No, the way it works is that you supply the name of the control, such as Controls("Text1"), to access the control. The business with sticking together "text" and a variable is just to build the name. This has nothing to do with adding up the values, it's just a way of accessing the control to get what's in it, without having to write individual chunks of code for each one. I wouldn't worry about this, though. It's just a way of simulating a control array. You won't need it in VB6.

... or you mentioned control arrays how would that be done, if you don't mind telling me. or explaining to me because you said it might be alot easier ( or something along them lines) to do.
Yes, a control array will make your life much easier. The quick and simple way to create a control array is this...
  • Place an ordinary control on the form (in your case, let's use a textbox).
  • Set the name to what you want to use - for example, textQty (or whatever).
  • Copy the control (select it and hit Ctrl-C, or whatever you prefer).
  • Paste it back onto the same form.
  • VB will ask you whether you want to create a control array - say "yes".
That's it, you now have a control array containing two textboxes. The textboxes still work exactly the same, of course. The only difference is that any code which refers to them has to specify which one, using an index. In other words, rather than txQty.Text you use the syntax txQty(n).Text. Any event procedures are shared by all the controls in the array. In other words, there is one txQty_Click event procedure, which is called when you click any of the textboxes in that array. The event procedures will now include an extra Index parameter, to indicate which one actually triggered the event.

In case you need it, each control also has an Index property, indicating which place it holds in the array.

Sorry if this all sounds complicated. It's actually very simple to do. Just remember that when writing code to use these controls, the differences are just the same as when using an ordinary variable array instead of a plain variable.
Jul 25 '07 #5
lee123
556 512MB
thanks for the info i'll try it

lee123
Jul 25 '07 #6
lee123
556 512MB
hey (killer42) i had a visual basic cdrom and i watched it finally, and in this video they did a calculator. well to make a long story short they had three textboxes 1 was named (number1), and the other was named (number2) and the third one was named (answer) and they had a button named (calculate) behind the button they wrote code for the two textboxes to add them together the code they used was like this:

Expand|Select|Wrap|Line Numbers
  1. answer = val(number1) + val(number2)
anyway i used this code for the total naming the text boxes that i used for the total in my form which i named

Expand|Select|Wrap|Line Numbers
  1. total = val(total1) + val(total2) etc.
but this works the same i have had a chance to use the code you displayed... yea your right it looks complicated but i'll have to give it a try

thanks for all your help.....

lee123
Jul 25 '07 #7
Killer42
8,435 Expert 8TB
...
Expand|Select|Wrap|Line Numbers
  1. total = val(total1) + val(total2) etc.
but this works the same i have had a chance to use the code you displayed... yea your right it looks complicated but i'll have to give it a try
Glad to see you got it working.

Writing that piece of code to work with a control array isn't complicated. It would be something like...
Expand|Select|Wrap|Line Numbers
  1. MyTotal = val(total(1)) + val(total(2)) etc.
In a case like this there's not much difference. But let's say you had 100 textboxes to add up. You'd end up with a mighty long statement!. If they're in an array, you can use a loop, like this...
Expand|Select|Wrap|Line Numbers
  1. Dim I As Long, GrandTotal As Long
  2. For I = 1 To 100
  3.   GrandTotal = GrandTotal + Val(total(I))
  4. Next
Control arrays just sound complicated to explain. They really are simple to use.
Jul 25 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Paul MG | last post by:
Hi Is there a simple general way of getting the keys out of a map? Or a vector of pairs? My problem seems to be that the pair<> type returned by iterating through either has no methods to...
4
by: Sondra Wilson | last post by:
I have created a sorted query. The total(records) I get in the query is correct. My problem lies with getting that total into my report. I use count to insert the total number of records in my...
36
by: Lindie | last post by:
The more I read the more confused I get. Too much on dates calulations in the groups. I need to know how often a book has been loaned out over the past year- 52 weeks. My table has Book...
4
by: Sean Shanny | last post by:
To all, Running into an out of memory error on our data warehouse server. This occurs only with our data from the 'September' section of a large fact table. The exact same query running over...
5
by: noLoveLusT | last post by:
hi everyone i am very very new to the sql server (2 days actually and ) so far i learned creating SPs etc but couldnt workout how to get return value from my prodecure my sp as follows...
1
by: lawton | last post by:
Source: this is an access 2003 question My knowledge level: reading books, internet, and trial & error; no formal training I'm trying to get a running sum of what's filtered in a subform which is...
12
by: miguelguerin | last post by:
Im having trouble getting the input from one file to another. Main file: package assigment3; /** * * @author mguer017 */ public class Main {
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
5
by: qwert7465 | last post by:
any help would be appreciated. here is my code: // Final Project #include <iostream.h> #include <iomanip.h> void checkout();
1
by: qwert7465 | last post by:
here is my code. i am only getting one error: // Final Project #include <iostream.h> #include <iomanip.h> void checkout(); void start_or_startover();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.