[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Addition doesn't add, it appends

I'm using Visual Basic 6 and my project is simple: Have the user enter 18 values in the screen, total what the user has enter and show it in the screen.  That's it.

However, I keep getting a "Run-Time error '13' , Mismatch'" message at some fvariables being added in the calculation and I don't know what it is.

I have the following screen fields (its a total of 18):

txtDiffinCoop.Text
txtDiffinOffers.Text
txtDIffinPrice.Text
txtDiffinWeight.Text

At each fields' LostFocus & GotFocus, the screen data is passed to Currency type variables:

DiffinCoop = txtDiffinCoop.Text
DiffinOffers = txtDiffinOffers.Text
DIffinPrice = txtDIffinPrice.Text
DiffinWeight = txtDiffinWeight.Text

At each fields' LostFocus & GotFocus, the variables are added to Currency tpe variable:

TotalDiscount = DiffinCoop
TotalDiscount = TotalDiscount + DiffinOffers
TotalDiscount = TotalDiscount + DIffinPrice
TotalDiscount = TotalDiscount + DiffinWeight

The problem:

The variable TotalDiscount  adds each time the user jumps to any specific field, and adds corretly.  But when TotalDiscount adds DiffinCoop, it gives me a "Run-Time error '13' , Mismatch'" message.

I have Debug it and if I enter to 2 fields, it works, to 3 it works, but when I enter values at txtDiffinCoop.Text, it gives me an error.

When seeing the value in TotalDiscount , it shows the data enter as Appended.  IF the user enter for each field 1.00, 23.00, 4.22, 34.09, when the routine for TotalDiscount  is run, the value in TotalDiscount is "1.0023.004.2234.09".

HELP
0
rayluvs
Asked:
rayluvs
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what is the data type of the variable TotalDiscount ?
Dim TotalDiscount as double
TotalDiscount = val(DiffinCoop.Text)
TotalDiscount = TotalDiscount + val(DiffinOffers.Text)
TotalDiscount = TotalDiscount + val(DIffinPrice.Text)
TotalDiscount = TotalDiscount + val(DiffinWeight.Text)

Open in new window

0
 
rayluvsAuthor Commented:
Thanx Lots!  Worked!
0
 
rayluvsAuthor Commented:
Thanx!!!!!!!!!!!!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now