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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox number formatting?

Status
Not open for further replies.

VBDotNetProgrammer

Programmer
Jul 9, 2003
50
GB
Hi,

Does anyone know how to apply a formatting rule to a text box.

I want some to enter say 10000 and it must be displayed automatically as 10,000.

Any ideas? Am i right in thinking i have to set some sort of mask?
 
When you set the textbox's text property, use the Format function. You use it like this:

Dim myTextBox as TextBox
myTextBox.text = Format(#,###)

This will display a number with a comma if needed, and no comma if not needed.

P.S. If you need it to display a zero as a digit no matter what the number (i.e. 0.0), replace the # with a 0 (i.e. Format(0,000.0) instead of Format(#,###.#)

Hope this helps.
 
Hi,

Thanks for that, i have just tried it and it doesnt format the number as i enter it for some reason.

What do you think the reason for that could be?
 
Try putting that same formatting code in the textbox's textChanged event handler.
 
You can use old but very good MaskedEdit control from VB 6.0.
 
there are already .net variants out there that are in managed code, thus smaller then the vb6 variant.

try the website that is where i found my version

Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
Thanks guys but im not in the position to use custom controls in this project.

It looks like if there isnt a way of doing it using the controls or function sthat come with the .Net environment im going to have to leave this one out for a while.

Thanks anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top