I am writing my first program using VB 2005 Express. Using text toxes in a Form I have created a place where a user can input data that will be manipulated. I have used a Text Box in the form that displays the output data. In this case it is a number.

When I defined the variable that is displayed in the output text box I tried Double and got an error message. I found that I can only define as Integer for the code to be accepted. While the program does run I need to have more accuracy, at least to one decimal, in that text box.

An associate who uses VB 6 showed me that he can define the type of number and how many decimal places for the text box, but I'm not finding any way to do that in VB 2005.

Is there a better solution than using the text box to output data, or is there a way to accomplish this with the text box??

Thanks,

Jim

Update

After working at it some more I found that I can set the definition for the variable I want to display as Decimal. That works, but the data displayed has too many decimal places. I don't find a direct method in the properties for the textbox to format the data to limit the number of decimal places displayed.

Any help??

but the data displayed has too many decimal places

I'm sure there's a better way to do it, but you can round to a decimal place. If your number doesn't have to be exactly accurate.
Try this:

YourValue = Math.Round(5.3492, 2)

It should round to 5.35.

Textboxes only use strings. So, 123 in a textbox is "123". To convert this to a single use Csng(Textbox1.Text).
You souldn't rely on vb to make the right conversion so to put a nubmer into a textbox use Cstr(Var), where Var is a variable (single, double, etc)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.