473,322 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Convert text to double

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
Jul 17 '05 #1
3 19213
B
Erwin Bormans schreef:
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


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.
Jul 17 '05 #2
val(text1.text)
- I believe it returns zero if empty or not a number

"Erwin Bormans" <er***********@verwijderdit.telenet.be> wrote in message
news:42***********************@news.skynet.be...
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

Jul 17 '05 #3
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" <er***********@verwijderdit.telenet.be> wrote in message
news:42***********************@news.skynet.be...
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

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
2
by: name | last post by:
The piece of code is for a Web Form Page. Who can tell me why? Thanks a lot! ------------------------------------------------ VB.Net Code: Protected Overrides Sub AddParsedSubObject(ByVal obj As...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
3
by: PeterK | last post by:
I am trying to set Public overridable CreditlimitS() as System.Data.SqlTypes.SqlMoney to Creditlimit as Double like CreditLimitS=creditlimit and get this error "Value of type double cannot be...
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
1
by: help1267 | last post by:
I'm trying to convert an entry from a form text box to a double and am always getting "Input string was not in the correct format". This is my code: dblAmount =...
3
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; ...
22
by: xiao | last post by:
Can I fullfill this task? Using fred and fwrite?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.