Addition doesn't add, it appends

Posted on 2009-04-25
Last Modified: 2013-11-26
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):


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".

Question by:rayluvs
    LVL 142

    Accepted Solution

    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


    Author Comment

    Thanx Lots!  Worked!

    Author Closing Comment


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now