I need assistance with using Keypress to only allow a certain range of numbers (1-26) to be typed into the textbox. When ever I do it, it only allows me to press the numbers "1 and 2".
I'm very new to VB so the help is much obliged. I know Im doing something very stupid! :P
Public Class Form1
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim intMath As Integer
Dim intReadingWriting As Integer
Dim intScienceHistoy As Integer
Dim intSum As Integer
Dim intAverage As Integer
intMath = Val(txtMath.Text)
intReadingWriting = Val(txtReadingWriting.Text)
intScienceHistoy = Val(txtScienceHistory.Text)
intSum = intMath + intReadingWriting + intScienceHistoy
intAverage = intSum / 3
lblAnswer.Text = intAverage
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Close()
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
lblAnswer.Text = String.Empty
txtMath.Text = String.Empty
txtReadingWriting.Text = String.Empty
txtScienceHistory.Text = String.Empty
txtMath.Focus()
End Sub
Private Sub txtMath_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtMath.KeyPress
If (e.KeyChar >= "1" And e.KeyChar <= "26") Or e.KeyChar = ControlChars.Back Then
Else
e.Handled = True
End If
End Sub
Private Sub txtReadingWriting_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtReadingWriting.KeyPress
If (e.KeyChar >= "1" And e.KeyChar <= "26") Or e.KeyChar = ControlChars.Back Then
Else
e.Handled = True
End If
End Sub
Private Sub txtScienceHistory_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtScienceHistory.KeyPress
If (e.KeyChar >= "1" And e.KeyChar <= "26") Or e.KeyChar = ControlChars.Back Then
Else
e.Handled = True
End If
End Sub
End Class