calculation in VB. Please help!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: calculation in VB. Please help!!

  1. #1
    john Guest

    calculation in VB. Please help!!


    Hi

    I have a textstring that holds a currency. How can I add , for example 1
    dollar to this amount??

    test="200.50"

    I thought that I could convert the string to a double or currency with function
    Cdbl or Ccur and after that perform the calculation..like this:
    msgbox(Cdbl(test)+1)

    The result of this operation is : 20051 ???

    Please help...how can I convert the textstring so that it's possible to handle
    this. I want to add a dollar so that the result equals to : 201.50

    /John

  2. #2
    Alan Gillott Guest

    Re: calculation in VB. Please help!!

    Either
    msgbox(CCur(test)+100)
    or
    msgbox(CCur(test)+CCur(1))


    john <jonasjohansson70@hotmail.com> wrote in message
    news:390edcc1$1@news.devx.com...
    >
    > Hi
    >
    > I have a textstring that holds a currency. How can I add , for example 1
    > dollar to this amount??
    >
    > test="200.50"
    >
    > I thought that I could convert the string to a double or currency with

    function
    > Cdbl or Ccur and after that perform the calculation..like this:
    > msgbox(Cdbl(test)+1)
    >
    > The result of this operation is : 20051 ???
    >
    > Please help...how can I convert the textstring so that it's possible to

    handle
    > this. I want to add a dollar so that the result equals to : 201.50
    >
    > /John




  3. #3
    Al Mowbray Guest

    Re: calculation in VB. Please help!!


    How about:

    if test = "200.50"

    CCur(test) + 1
    will give 201.5 which you can then format as you like.

    Al Mowbray

    "john" <jonasjohansson70@hotmail.com> wrote:
    >
    >Hi
    >
    >I have a textstring that holds a currency. How can I add , for example 1
    >dollar to this amount??
    >
    >test="200.50"
    >
    >I thought that I could convert the string to a double or currency with function
    >Cdbl or Ccur and after that perform the calculation..like this:
    >msgbox(Cdbl(test)+1)
    >
    >The result of this operation is : 20051 ???
    >
    >Please help...how can I convert the textstring so that it's possible to

    handle
    >this. I want to add a dollar so that the result equals to : 201.50
    >
    >/John



  4. #4
    Jim Edgar Guest

    Re: calculation in VB. Please help!!

    John --

    The code you included works fine on my system. The only way I could
    reproduce your problem was to change the "." to a comma:

    test = "200,50" ' note the comma instead of a period

    In this case I got 20051, when I changed the value to "200.50" I got 201.5


    You might try:

    debug.print test

    to see the value of test or check your regional settings to see if anythings
    up.

    Hope it helps

    Jim Edgar

    "john" <jonasjohansson70@hotmail.com> wrote in message
    news:390edcc1$1@news.devx.com...
    >
    > Hi
    >
    > I have a textstring that holds a currency. How can I add , for example 1
    > dollar to this amount??
    >
    > test="200.50"
    >
    > I thought that I could convert the string to a double or currency with

    function
    > Cdbl or Ccur and after that perform the calculation..like this:
    > msgbox(Cdbl(test)+1)
    >
    > The result of this operation is : 20051 ???
    >
    > Please help...how can I convert the textstring so that it's possible to

    handle
    > this. I want to add a dollar so that the result equals to : 201.50
    >
    > /John




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center