View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Chrissy[_5_] Chrissy[_5_] is offline
external usenet poster
 
Posts: 33
Default Text Box for Numeric Data

Any chance of sending me the class?

Chrissy.

Harald Staff wrote
No, correct, this code snippet is the small heart of a quite big class. Ctrl V is caught
in then KeyDown event; cancelled, clipboard content validated and inserted. Question is,
what to do with it if the clipboard contain more than numbers ? It's also a question
whether to allow decimal separators or not, if so restrict it to one only. Decimal
separators are also depending on regional settings so you can't hardcode the ascii for it.
And what if clipboard content contains another decimal separator when you paste next to
the existing, where does its decimals go ?

Other events are KeyUp for possible "live" calculation, Enter for "select all text",
optional backcolor change and left aligned text (if the box supports it), and finally Exit
for number formatting and optional right aligned text.

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Thomas" wrote in message ...
Not if the data is pasted into the textbox though.

Tom Ogilvy wrote:

Harald Staff often recommends the keypress event and I endorse that. Here
is recent code Harald posted:

Private Sub TxtBox_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
Select Case keyascii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
keyascii = 0
End Select
End Sub

--
Regards,
Tom Ogilvy

Chrissy wrote in message
...
Does anyone have some standard code they use to turn
a text box into a numeric data entry box?

If not, how do you handle data validation for entries you
want to restrict to numeric values?

Chrissy.