Connecting Tech Pros Worldwide Forums | Help | Site Map

Convert text to double

Erwin Bormans
Guest
 
Posts: n/a
#1: Jul 17 '05
Hello

I want to convert a value in a text propertie to a double.

I can use CDbl(grid1.text) for this, but the problem is that some text
properties are empty and when they are the code give errors.

Is there a way to convert text to double, but if the text is empty he just
returns zero?

Kind Regards
Erwin


B
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Convert text to double


Erwin Bormans schreef:[color=blue]
> Hello
>
> I want to convert a value in a text propertie to a double.
>
> I can use CDbl(grid1.text) for this, but the problem is that some text
> properties are empty and when they are the code give errors.
>
> Is there a way to convert text to double, but if the text is empty he just
> returns zero?
>
> Kind Regards
> Erwin
>
>[/color]

Cdbl(Val(grid1.text)), but watch out it will give zero for an empty
string. Otherwise use if ..then

if lenb(grid1.text) <> 0 then
CDbl(grid1.text)
end if

B.
Hal Rosser
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Convert text to double


val(text1.text)
- I believe it returns zero if empty or not a number

"Erwin Bormans" <erwin.bormans@verwijderdit.telenet.be> wrote in message
news:427735c9$0$12978$ba620e4c@news.skynet.be...[color=blue]
> Hello
>
> I want to convert a value in a text propertie to a double.
>
> I can use CDbl(grid1.text) for this, but the problem is that some text
> properties are empty and when they are the code give errors.
>
> Is there a way to convert text to double, but if the text is empty he just
> returns zero?
>
> Kind Regards
> Erwin
>
>[/color]


Jon Smyth
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Convert text to double


The best way would be to handle the error in the code. Use the 'On Local
Error' trap to handle it within the subroutine. If you get the conversion
error you can do whatever makes sense to your application.

"Erwin Bormans" <erwin.bormans@verwijderdit.telenet.be> wrote in message
news:427735c9$0$12978$ba620e4c@news.skynet.be...[color=blue]
> Hello
>
> I want to convert a value in a text propertie to a double.
>
> I can use CDbl(grid1.text) for this, but the problem is that some text
> properties are empty and when they are the code give errors.
>
> Is there a way to convert text to double, but if the text is empty he just
> returns zero?
>
> Kind Regards
> Erwin
>
>[/color]


Closed Thread


Similar Visual Basic 4 / 5 / 6 bytes