By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,574 Members | 1,205 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,574 IT Pros & Developers. It's quick & easy.

Problem adding currency in VB6

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.