+ Reply to Thread
Results 1 to 4 of 4

VBA - losing a decimal point in equation

  1. #1
    Registered User
    Join Date
    01-20-2014
    Location
    Slovenija
    MS-Off Ver
    Excel 2013
    Posts
    12

    VBA - losing a decimal point in equation

    Hi

    On UserFrame I have several TextBoxes in which a user inputs a value. The names of these textboxes begins with "tbtt". As you can see I have some equations here and there. The result of those must be seen in TextBoxes tbttUg1 and tbttHg1. The question is - why I lose my decimal point???

    E.g. if a usser inputs in tbttA a value 10,52 and tbttUg1.value=25,12, the tbttHg1.value=2642624. Why do I lose my decimal point???

    Furhemore, does anyone know any more elegant way to show the result of an equation somewhere that is not a textbox?

    Thanks for any kind of help!



    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,272

    Re: VBA - losing a decimal point in equation

    I don't think VBA likes commas as decimals....

    tbttHg1.Value = CDbl(Replace(tbttA.Value, ",", ".")) * CDbl(Replace(tbttUg1.Value, ",", "."))
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    01-20-2014
    Location
    Slovenija
    MS-Off Ver
    Excel 2013
    Posts
    12

    Re: VBA - losing a decimal point in equation

    Hi, still doesn't work. It works only, if copy the input value from textbox to another textbox. But if I try to multiply it with some other, the problem doesn't go away. Don't know why is that happening.

    An input value from combobox is e.g. "1.5", input value from textbox is "1,5", if i multiply this in another textbox where I used CDbl and Replace command for textbox, the result is 22.5.
    Strange.

    Do you have any other suggestions?

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,373

    Re: VBA - losing a decimal point in equation

    I think Bernie was on the right track. Since you have not posted a sample, I put together the following bare bones simple code:
    Please Login or Register  to view this content.
    With my standard US number settings (in Windows control panel) of "." for decimal separator and "," for thousands separator, the output of this code is 1.5 -- 15 -- 22.5. If I change my Windows settings to use "," for decimal and "." for thousands separators, the output changes to 15 -- 1,5 -- 22,5. It appears, as Bernie suggested, that VBA is not correctly interpreting the comma as a decimal separator. If you are going to allow both "." and "," to be used as decimal separators, you are going to need to somehow code the procedure to recognize both formats. Easiest approach might be to pick one character for the decimal separator (either "." or "," consistent with your Windows settings) and consistently use that character.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 06-29-2012, 07:52 PM
  2. Replies: 4
    Last Post: 06-10-2009, 12:50 PM
  3. Format display decimal values but no decimal point
    By BecParko in forum Excel General
    Replies: 1
    Last Post: 10-18-2007, 04:42 AM
  4. Replies: 3
    Last Post: 03-18-2006, 02:25 PM
  5. Replies: 3
    Last Post: 07-06-2005, 09:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1