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!

Numeric value check

Status
Not open for further replies.

zahid999

Technical User
Feb 25, 2005
11
CA
Dear Friends,

I would like user to enter numeric value only in textbox.
Could some guide how to check.

Also in a combobox i want to appear value like 2001, 2002, up to 2010 automatically on focus event.

Guru's help pls.

kind regards,

zahid
 
For the textbox:

Dim x as integer
x=val(Textbox1.Text)
OR
x=cint(Textbox1.Text)

for combobox

Dim i As Integer
For i = 2000 To 2010
Combo1.AddItem i
Next i

 
For a numeric text box see thread222-816253.

For the Combo use the .additem method.
Code:
combo1.AddItem "2001"
combo1.AddItem "2002"
etc.
You can also use a loop and base it on the current year. I would use the form load event for this.


zemp
 
Dear Friends,

Thanks for your support.

Can some suggest code of key press event where user only allowd to enter numeric value. in case of alphanumeric automatically go back to value one digit backword.


Appreciate,

Zahid
 
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8, 46, 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub

You still have to cover the cut&paste scenario

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Can some suggest code of key press event where...
Did you look at the thread I referenced. An entire Keypress event is there, as well as the cut and paste senario that johnwm mentioned.

zemp
 
Sorry zemp - I should have checked your link before posting [blush]

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

Essex Steam UK for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top