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

numerical data in a text box 1

Status
Not open for further replies.

HebieBug

Programmer
Jan 8, 2001
354
JP
Have alreay setup a program which takes many details majority of them are or only numberical entry.
Have got tp the area of "how silly can a user be"
The tex boxes data get added to a variable, calculations are made and a message will come up dependent on the data they have entered. But what if they ad text to the textboxes? Then the program will bomb when it trys to put the data into the variable(Integer). If I set the variable to a variant then the calculations can't be made.
Could use the masked edit but the lenght of the numerical data will not be set.
Anyone hae some ideas on how to get around this either setting the text box to only acept numerical data or other
 
Couple of methods depending on how you want to go:

1. simple use of Isnumeric function in VB

2. Only allow certain keystrokes within textbox

simple class module below

Private WithEvents m_txttextbox As TextBox

Public Property Set box(txttextbox As TextBox)
Set m_txttextbox = txttextbox
End Property

Public Property Get box() As TextBox
Set box = m_txttextbox
End Property

Private Sub m_txttextbox_keyPress(KeyAscii As Integer)

If KeyAscii > 47 And KeyAscii < 58 Or KeyAscii = 8 Or KeyAscii = 13 Then
If KeyAscii = 13 Then
' this bit also makes the enter key work as a tab

SendKeys &quot;{tab}&quot;
KeyAscii = 0
End If


Else

KeyAscii = 0
End If
End Sub

::)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top