Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sting /text conversion

Status
Not open for further replies.

ranshe

Programmer
Oct 5, 2004
27
0
0
US
At the risk of sounding dumb:
I need to know how to paint a numeric field on a form or convert a text field that receives a numeric value into a number so I can us it in a math calculation.

Thanks!
 
Hi!

I don't understand your question exactly,but I guess that you want to convert a text to a numeric value.Try this;


data_numeric=Val(text1.text)

I hope this helps you...
 
VB uses implicit conversions when possible, whereas many languages require explicit casting. To "paint a numeric field on a form", either put it in a text box or label, or use the print statement, which will put the result directly on the form.

Selimsl's response is recommended but not required. You can use a string value directly in a math calculation, and VB will implicitly cast your string. One of the problems: "10" - "5" evaluates to 5, an integer. "10" + "5" evaluates to "105", a string. This is because + is overloaded in vb both as a string concatenation operator and an addition operator. Since VB doesn't have to recast the operands to make sense of the operation, it doesn't.

This is why it's a good idea to do as selimsl suggests.

If you want to avoid implicit casting altogether, use the conversion functions. CStr will convert to a string.

HTH

Bob

If you want to convert the input value to a string
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top