473,408 Members | 1,744 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,408 software developers and data experts.

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 9609
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
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
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
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
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
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...
2
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
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
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
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...

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.