| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi All I wish to allow a user to input numbers of up to a million or more. Simply displayed in a TextBox they're nearly incomprehensible, think 10000000 against 10,000,000. What I would like to achieve :- 1. If the user inputs numeric characters simply add them to the TextBox but display them in thousands comma format. 2. If non-numeric then a Beep and ignored 3. However, to allow the user to use CNTR+C, CNTRL+V and allow insertions and so on. Seems to me that would need oceans of code. Not posting code 'cos six or more attempts failed so badly, I wouldn't know which to post. Help appreciated, TIA .. -- Martin Trump |
|
#2
| |||
| |||
| "Martin Trump" <martin@wmeadow.demon.co.uk> wrote in message news:XuLFmGDAQVwIFwKV@wmeadow.demon.co.uk... > Hi All > > I wish to allow a user to input numbers of up to a million or more. > Simply displayed in a TextBox they're nearly incomprehensible, think > 10000000 against 10,000,000. > > What I would like to achieve :- > > 1. If the user inputs numeric characters simply add them to the TextBox > but display them in thousands comma format. > > 2. If non-numeric then a Beep and ignored > > 3. However, to allow the user to use CNTR+C, CNTRL+V and allow > insertions and so on. Seems to me that would need oceans of code. > > Not posting code 'cos six or more attempts failed so badly, I wouldn't > know which to post. > > Help appreciated, TIA > . A Masked Edit control should work for you. Don't use VB's Google about for a replacement. Here is a nice one... http://www.freevbcode.com/ShowCode.Asp?ID=2299 As for your last question, it sort of depends on what your 'default' is when copying. eg, whether you want a User to highlight and copy "10,000,000" or "10000000"? I have often simply provided a small clipboard button to the side which automatically copys the 'format' or the 'data', or brings up a small dialog allowing the user to chose. It depends really on how often copy 'n paste is done. [You might even want to define your own custom clipboard format. http://www.vbaccelerator.com/home/VB...se/article.asp ] -ralph |
|
#3
| |||
| |||
| Ralph >A Masked Edit control should work for you. Thanks for your posting. Since I posted I've found an adequate, but not perfect solution. There are Text1 and Text2, the former the comma formatted display, the latter the input . Using KeyPreview = True ============================== Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = 8 Then 'Back space Text1.Text = Format$(Left$(Text2.Text, Len(Text2.Text) - 1), "#,#") Text2.SelStart = 999 Exit Sub End If If (KeyAscii < 48) Or (KeyAscii > 59) Then KeyAscii = 0 Beep Else Text1.Text = Format$(Text2.Text & Chr$(KeyAscii), "#,#") End If End Sub ============================== Thanks again. Regards -- Martin Trump |
|
#4
| |||
| |||
| Martin Trump wrote: > Ralph > > Thanks for your posting. Since I posted I've found an adequate, but > not perfect solution. > Here is the sort of thing I like to do: Private Sub Form_Load() Text1.Text = "0" End Sub Private Sub Text1_GotFocus() If IsNumeric(Text1.Text) Then Text1.Text = Format(Text1.Text, "0") End If End Sub Private Sub Text1_LostFocus() If IsNumeric(Text1.Text) Then Text1.Text = Format(Text1.Text, "#,##0") End If End Sub Private Sub Text1_Change() If IsNumeric(Text1.Text) Then Text1.BackColor = vbWindowBackground Else Text1.BackColor = vbYellow End If End Sub |
|
#5
| |||
| |||
| In message <7YSdnXuxCMppK1_VnZ2dnUVZ_j2dnZ2d@comcast.com>, Steve Gerrard <mynamehere@comcast.net> writes >Here is the sort of thing I like to do: Thanks Steve. All in one TextBox. Wow! I'll give a whirl. Martin -- Martin Trump |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.