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