473,545 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Format TextBox as number

Art
Hi,

I have a MyTextBox class that inherits from TextBox. How do I make it
display the information as, say 0.00. Sometimes the value will be typed by
the user. Other times the value will be filled in when a User makes a
selection elsewhere.

I'd appreciate any help.

Art
Nov 21 '05 #1
4 7975
Hi,

You might be better using a numericupdown control instead

Ken
--------------
"Art" <Ar*@discussion s.microsoft.com > wrote in message
news:8E******** *************** ***********@mic rosoft.com...
Hi,

I have a MyTextBox class that inherits from TextBox. How do I make it
display the information as, say 0.00. Sometimes the value will be typed by
the user. Other times the value will be filled in when a User makes a
selection elsewhere.

I'd appreciate any help.

Art
Nov 21 '05 #2
Art
Ken,

Thanks for the response, but unless there's more to the numericupdown I
don't think that will help. The specific numbers that will be entered will
be hourly rates for contractors. Possible values could be 65, 120, 190. The
text box will be an area to fill this in. However, if a contractor has a
"default" rate, then selecting that contractor from a ComboBox will
automatically put a number in the TextBox.

The rates will typically be multiples of 5. Will a numericupdown allow
that? Will it allow manual entry?

Thanks again,

Art

"Ken Tucker [MVP]" wrote:
Hi,

You might be better using a numericupdown control instead

Ken
--------------
"Art" <Ar*@discussion s.microsoft.com > wrote in message
news:8E******** *************** ***********@mic rosoft.com...
Hi,

I have a MyTextBox class that inherits from TextBox. How do I make it
display the information as, say 0.00. Sometimes the value will be typed by
the user. Other times the value will be filled in when a User makes a
selection elsewhere.

I'd appreciate any help.

Art

Nov 21 '05 #3
Since you've created a subclass from the textbox already, you can force
a format when you assign text to the box.

'---------- Overload the text assign value so that numeric / alpha
data may be formatted ---------
Overloads Property Text(ByVal FormatData As Boolean) As String
Get
Text = Me.Text
End Get
Set(ByVal Value As String)
Me.Text = Value
If FormatData Then FormatText()
End Set
End Property

You could also force a format of data when the textbox loses focus

Private Sub YourClass_Leave (ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Leave
FormatText() ' Format per mask
End Sub

'--------- Format the string ---------
Public Sub FormatText()
If m_MaskValue = "" Or m_MaskValue = Nothing Then Exit Sub ' No
check
Me.Text = YourFormatRouti ne(Me.Text, m_MaskValue)
End Sub

Nov 21 '05 #4
Art
Shane,

Thanks very much. I was wondering about a recursive problem, but I see your
boolean argument fixes that. I assume that in the format area I would set it
to false.

Art

"Shane" wrote:
Since you've created a subclass from the textbox already, you can force
a format when you assign text to the box.

'---------- Overload the text assign value so that numeric / alpha
data may be formatted ---------
Overloads Property Text(ByVal FormatData As Boolean) As String
Get
Text = Me.Text
End Get
Set(ByVal Value As String)
Me.Text = Value
If FormatData Then FormatText()
End Set
End Property

You could also force a format of data when the textbox loses focus

Private Sub YourClass_Leave (ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Leave
FormatText() ' Format per mask
End Sub

'--------- Format the string ---------
Public Sub FormatText()
If m_MaskValue = "" Or m_MaskValue = Nothing Then Exit Sub ' No
check
Me.Text = YourFormatRouti ne(Me.Text, m_MaskValue)
End Sub

Nov 21 '05 #5

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

Similar topics

2
9119
by: Eagle | last post by:
This seems to be a pretty basic question, but I can't find the answer. In VB I format a number by: format("1234", "#.00") (result: 1234.00) This doesn't work in asp, I get an error. How do I format numbers? Thanks.
3
1158
by: George Ter-Saakov | last post by:
I need to format a number so it will be at least 2 characters. Example: 10 --> 10 7 --> 07 How to do that? Thanks.
1
1337
by: Mohammed Shafiulla Khadri | last post by:
Hi, I have to display pound/ euro symbol, when i have to format a number into respective currency? I dont want to display the default "$" sysmbol? how can i do this? regards, MSK
2
18529
by: jeswin12 | last post by:
I used the following script to auto format the phone number field in my form. http://javascript.internet.com/forms/format-phone-number.html The problem with this code is im able to set the auto-format for only one field in the form. Please help me as to how can i make multiple phone fields have this format using this code. Thanks.
4
6058
by: Richard Kessler | last post by:
I am relatively new to Python. Love it, but I find things that I can do easily in .NET and cannot find a way to do in Python. I need to format a number as currency, for example 12343.56 to $12,343.56. In C# all I need to do is decimal x = 12343.56 then x.ToString("$###,###.00"); I cannot find a way to do this in Python. I must be missing...
0
1089
by: Clodoaldo | last post by:
I want to format a number with thousands separator to the 'pt_br' locale. I'm trying like this: 'pt_BR.ISO8859-1' '9876' '' '.'
4
1089
by: naveenkenexa | last post by:
Can any one please suggest me how to format a number in to 0000000.00 format
2
1104
by: gracepaul | last post by:
hi all, How to format a number in the following format if the number is 1123456789.20 then i want the result as follows 1,12,34,56,789.20 please reply as early as possible thanks in advance
4
2775
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is...
0
7465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7752
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5325
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.