The Student Room Group
Reply 1
Riffy
hey!

I need help with my VB programme! I was wondering if any of you guys know how to validate a text box?

I need to validate a text box so it only excepts numbers.

Thanks
Riffy


use either the _validate event or _lostfocus

then put this in it

if Not IsNumeric(text1.text) THen
Msgbox("Must be numeric")
text1.setfocus
end if
Reply 2
alternatively, you could say:

Private Sub txtText1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57, 8 'allows numbers and backspace
Case Else
KeyAscii = 0
MsgBox "Please Enter a Number"
End Select
End Sub
Reply 3
Cheers m8 that was Gr8!
The piece of code my professor gave me was atleast 5 lines!!

Anyway you studying the same course as me? (Advanced VCE in ICT)

I'm aiming for an A in Visual Basic, the professor told me that the programme that i have made is at a A grade but it all depends on my documentation!

Once again i thank you kind person
Reply 4
Thanx but the 1st one makes more sense
hehehe
thanx anyway!

Latest

Trending

Trending