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