Tech Support Guy banner
Status
Not open for further replies.

VB: convert text to numbers

2K views 1 reply 2 participants last post by  Rollin_Again 
#1 ·
Im atempting to learn VB through doing.

How do i convert a text sting (eg: "Hello world") an equivilant numeric value? what function should i use?
 
#2 ·
firestormer said:
Im atempting to learn VB through doing.

How do i convert a text sting (eg: "Hello world") an equivilant numeric value? what function should i use?
I'm not exactly sure what you are trying to accomplish. You can't convert a phrase like "Hello World" to a numeric value or you will get a "Type Mismatch" error.

You can only convert a text string to a number if the text string is comprised of digits.

For example....Let's say you have a textbox on a form and you enter a number into it. Even though what you entered into the textbox looks numerical is will still be a text string because texboxes hold text not numbers. If you debug your code and check the value of the textobx you will see that the number has double quote marks around it because it is text. You can convert a text string such as "1234" into a number 1234 by using any of the following commands. Just replace what is inside the parentheses to your variable or value to convert .

CInt (converts to Integer)

CDbl (converts to double)

CSng (converts to single)

CLng (converts to long)

Regards,
Rollin
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top