473,503 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem adding currency in VB6

Hi,

I'm trying to write a simple program to print invoices for people I do work
for. I've got a form with textboxes for descriptions and amounts for items,
and some code for printing the invoices. It all works except for the one
line that adds all of the item amounts. At run time, a "type mismatch"
error is thrown. I've tried a couple of different things, but the code
won't work. Is there something special about adding currency I'm missing?
I've also tried making everything a string, and when I add amounts, it will
just concatenate the strings. Also, this method won't let me subtract
discounts.

Any help or code snippets would be greatly appreciated.

Thanks,
Steven Smith
May 15 '06 #1
5 1191
I should probably show you the code in question.....
Dim AmountDue As Currency
AmountDue = Item1Amt.Text + Item2Amt.Text + Item3Amt.Text +
Item4Amt.Text + Item5Amt.Text + Item6Amt.Text + Item7Amt.Text +
Item8Amt.Text - Item9Amt.Text - ItemAAmt.Text


Thanks again...
Steven Smith <sl****@webbox.com> wrote in
news:l7*****************@twister.nyroc.rr.com:
Hi,

I'm trying to write a simple program to print invoices for people I do
work for. I've got a form with textboxes for descriptions and amounts
for items, and some code for printing the invoices. It all works
except for the one line that adds all of the item amounts. At run
time, a "type mismatch" error is thrown. I've tried a couple of
different things, but the code won't work. Is there something special
about adding currency I'm missing? I've also tried making everything a
string, and when I add amounts, it will just concatenate the strings.
Also, this method won't let me subtract discounts.

Any help or code snippets would be greatly appreciated.

Thanks,
Steven Smith


May 15 '06 #2
"Steven Smith" <sl****@webbox.com> schrieb:
[VB6-related question]


Note that the group "microsoft.public.dotnet.languages.vb" is related to
VB.NET. VB6 groups can be found in the "microsoft.public.vb.*" hierarchy.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 15 '06 #3
Try converting the text values to numbers before adding them.

AmountDue = val(Item1Amt.Text) + val(Item2Amt.Text) +
val(Item3Amt.Text) + val(Item4Amt.Text) + val(Item5Amt.Text) +
val(Item6Amt.Text) + VItem7Amt.Text) + val(Item8Amt.Text) -
val(Item9Amt.Text) - val(ItemAAmt.Text)

On Mon, 15 May 2006 19:05:42 GMT, Steven Smith <sl****@webbox.com>
wrote:
I should probably show you the code in question.....
Dim AmountDue As Currency
AmountDue = Item1Amt.Text + Item2Amt.Text + Item3Amt.Text +
Item4Amt.Text + Item5Amt.Text + Item6Amt.Text + Item7Amt.Text +
Item8Amt.Text - Item9Amt.Text - ItemAAmt.Text


Thanks again...
Steven Smith <sl****@webbox.com> wrote in
news:l7*****************@twister.nyroc.rr.com:
Hi,

I'm trying to write a simple program to print invoices for people I do
work for. I've got a form with textboxes for descriptions and amounts
for items, and some code for printing the invoices. It all works
except for the one line that adds all of the item amounts. At run
time, a "type mismatch" error is thrown. I've tried a couple of
different things, but the code won't work. Is there something special
about adding currency I'm missing? I've also tried making everything a
string, and when I add amounts, it will just concatenate the strings.
Also, this method won't let me subtract discounts.

Any help or code snippets would be greatly appreciated.

Thanks,
Steven Smith


May 15 '06 #4
Thanks John.... that worked perfectly.

Ah, the joys of being a newbie!

Steve
John <lo**@sig.net> wrote in news:2qnh62tgjmp4j2v2rgoe3li1g89ogdh014@
4ax.com:
Try converting the text values to numbers before adding them.

AmountDue = val(Item1Amt.Text) + val(Item2Amt.Text) +
val(Item3Amt.Text) + val(Item4Amt.Text) + val(Item5Amt.Text) +
val(Item6Amt.Text) + VItem7Amt.Text) + val(Item8Amt.Text) -
val(Item9Amt.Text) - val(ItemAAmt.Text)

On Mon, 15 May 2006 19:05:42 GMT, Steven Smith <sl****@webbox.com>
wrote:
I should probably show you the code in question.....
Dim AmountDue As Currency
AmountDue = Item1Amt.Text + Item2Amt.Text + Item3Amt.Text +
Item4Amt.Text + Item5Amt.Text + Item6Amt.Text + Item7Amt.Text +
Item8Amt.Text - Item9Amt.Text - ItemAAmt.Text


Thanks again...
Steven Smith <sl****@webbox.com> wrote in
news:l7*****************@twister.nyroc.rr.com:
Hi,

I'm trying to write a simple program to print invoices for people I do work for. I've got a form with textboxes for descriptions and amounts
for items, and some code for printing the invoices. It all works
except for the one line that adds all of the item amounts. At run
time, a "type mismatch" error is thrown. I've tried a couple of
different things, but the code won't work. Is there something special
about adding currency I'm missing? I've also tried making everything a string, and when I add amounts, it will just concatenate the strings.
Also, this method won't let me subtract discounts.

Any help or code snippets would be greatly appreciated.

Thanks,
Steven Smith



May 15 '06 #5
A better solution would be:

Dim AmountDue as Currency
AmountDue = 0
if isnumeric(item1Amt.text) then amountDue = AmountDue + ccur(item1amt.text)
if isnumeric(item2Amt.text) then amountDue = AmountDue + ccur(item2amt.text)
if isnumeric(item3Amt.text) then amountDue = AmountDue + ccur(item3amt.text)
if isnumeric(item4Amt.text) then amountDue = AmountDue + ccur(item4amt.text)
if isnumeric(item5Amt.text) then amountDue = AmountDue + ccur(item5amt.text)
if isnumeric(item6Amt.text) then amountDue = AmountDue + ccur(item6amt.text)
if isnumeric(item7Amt.text) then amountDue = AmountDue + ccur(item7amt.text)
if isnumeric(item8Amt.text) then amountDue = AmountDue + ccur(item8amt.text)
if isnumeric(item9Amt.text) then amountDue = AmountDue - ccur(item9amt.text)
if isnumeric(itemAAmt.text) then amountDue = AmountDue - ccur(itemAamt.text)

Also, use the CCur function to convert from the text box string values to
currency - you'll avoid rounding errors that the Val function can introduce.
Also note that VB 6 implictely uses the .TEXT property if you don't, but VB
2002 and later require it. It makes your code more specific so it's a
decent habit to be in anyway.

Mike Ober.

"John" <lo**@sig.net> wrote in message
news:2q********************************@4ax.com...
Try converting the text values to numbers before adding them.

AmountDue = val(Item1Amt.Text) + val(Item2Amt.Text) +
val(Item3Amt.Text) + val(Item4Amt.Text) + val(Item5Amt.Text) +
val(Item6Amt.Text) + VItem7Amt.Text) + val(Item8Amt.Text) -
val(Item9Amt.Text) - val(ItemAAmt.Text)

On Mon, 15 May 2006 19:05:42 GMT, Steven Smith <sl****@webbox.com>
wrote:
I should probably show you the code in question.....
Dim AmountDue As Currency
AmountDue = Item1Amt.Text + Item2Amt.Text + Item3Amt.Text +
Item4Amt.Text + Item5Amt.Text + Item6Amt.Text + Item7Amt.Text +
Item8Amt.Text - Item9Amt.Text - ItemAAmt.Text


Thanks again...
Steven Smith <sl****@webbox.com> wrote in
news:l7*****************@twister.nyroc.rr.com:
Hi,

I'm trying to write a simple program to print invoices for people I do
work for. I've got a form with textboxes for descriptions and amounts
for items, and some code for printing the invoices. It all works
except for the one line that adds all of the item amounts. At run
time, a "type mismatch" error is thrown. I've tried a couple of
different things, but the code won't work. Is there something special
about adding currency I'm missing? I've also tried making everything a
string, and when I add amounts, it will just concatenate the strings.
Also, this method won't let me subtract discounts.

Any help or code snippets would be greatly appreciated.

Thanks,
Steven Smith



May 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1868
by: Ed | last post by:
Hoping someone an assist me urgently. I would truly appreciate and help. I have a form and prices are based on 'price break'. 1.The price break fields work fine, but I cannot for the life of me...
4
1904
by: MrTang001 | last post by:
How I can fix this problem? I don't know why it alway prompted (first use this function). I have use newDollars, newCents... to access the base class member variable. And the member functions for...
1
1889
by: Dave56 | last post by:
I am trying to create an class (in vb.net) that will serialize to produce xml as follows: ------------------------------------------ <?xml version="1.0" encoding="utf-8"?> <TotalCostData> <Ship...
13
2169
by: Redduck | last post by:
Hello everyone. I am frustrated, I have written the simple program below for a class and I am having problems with the DO-WHILE loop. On the first run through the loop, everything works well, the...
5
9612
by: Steven Smith | last post by:
Hi, I'm trying to write a simple program to print invoices for people I do work for. I've got a form with textboxes for descriptions and amounts for items, and some code for printing the...
3
1820
by: luis.c.torres | last post by:
Hello. I have and unbound form with a subform. The form has 4 controls (a combo, two txt boxes and a button). The combo has the filter criteria (Equal to, newer than, older than and between)...
2
2101
by: =?Utf-8?B?UmljaGFyZCBUb2NjaQ==?= | last post by:
I'm learning Visual Basic using the .Net Framework 2.0. I have been playing with consuming web services in applications. I am using a free web service that gives me information for currency...
1
4378
by: favor08 | last post by:
I'm have automated the creation of an email from Access; whic works fine, but the new email doesn't have the user's default signature on it. Is there any way to either have it find the user's...
10
2474
by: Guillermo_Lopez | last post by:
Hello All, I am using VBA in access to perform some calculations. There is a particular sumation that is wrong (barely). this code is withing a loop. TDist = TDist + TempDist Both TDist...
0
7205
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
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
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
7353
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
7468
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...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.