This is my first effort in vb.net, so please excuse this simplistic question. I get:
'restrictedparamtextbox1' is not a member of 'test8.recipepage1' error. I grabbed this code from my research and I've done something wrong. Here's the code:
Public Class RecipePage1
Private Sub ParamTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ParamTextBox1.TextChanged
If Not IsNumeric(ParamTextBox1.Text) Or Val(ParamTextBox1.Text) < 0 Or Val(ParamTextBox1.Text) > 5.0 Then
MessageBox.Show("Only use numbers 0 - 5.000", "Input Error")
ParamTextBox1.Text = "5.000"
Debug.Print(Val(ParamTextBox1.Text))
End If
End Sub
Private Sub RecipePage1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.RestrictedParamTextBox1.AllowedKeys = RestrictedParamTextBox.RestrictionCategory.OneDecimalPoint
End Sub
End Class
Public Class RestrictedParamTextBox
Inherits System.Windows.Forms.TextBox
Enum RestrictionCategory
NoRestriction
NumeralsOnly
LettersOnly
AlphanumericOnly
OneDecimalPoint
End Enum
Private _allowedKeys As RestrictionCategory
Property AllowedKeys() As RestrictionCategory
Get
Return _allowedKeys
End Get
Set(ByVal Value As RestrictionCategory)
Select Case Value
Case 1 To 4 ' One of the enum choices
_allowedKeys = Value
Case Else ' No restriction
_allowedKeys = 0
End Select
End Set
End Property
Protected Overrides Sub OnKeyPress(ByVal e As KeyPressEventArgs)
MyBase.OnKeyPress(e)
' Test whether key is allowed, based on the current choice
' from the enum
Select Case _allowedKeys
Case 1 'Numerals only
If IsNumeric(e.KeyChar) Then
Exit Sub
Else
e.Handled = True
End If
Case 2 ' Letters Only
If e.KeyChar Like "[A-z]" Then
Exit Sub
Else
e.Handled = True
End If
Case 3 ' Alphanumeric
If e.KeyChar Like "[A-z]" Then
If IsNumeric(e.KeyChar) Then
Exit Sub
Else
e.Handled = True
End If
End If
Case 4 ' OneDecimalPoint
If IsNumeric(e.KeyChar) Then
Debug.Print(e.KeyChar)
If e.KeyChar = "." Then
e.Handled = False
End If
End If
End Select
End Sub
End Class
The ultimate goal is to have several ParamTextBox (up to 25) on the form and limit the entries to each box to:
numeric, one decimal point, and then one of several limits, like 0.000 to 5.000, or 1.000 to 8.000 or 0.000 to 12.000, etc.
Any help would be appreciated.
Thanks,
Norason
'restrictedparamtextbox1' is not a member of 'test8.recipepage1' error. I grabbed this code from my research and I've done something wrong. Here's the code:
Public Class RecipePage1
Private Sub ParamTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ParamTextBox1.TextChanged
If Not IsNumeric(ParamTextBox1.Text) Or Val(ParamTextBox1.Text) < 0 Or Val(ParamTextBox1.Text) > 5.0 Then
MessageBox.Show("Only use numbers 0 - 5.000", "Input Error")
ParamTextBox1.Text = "5.000"
Debug.Print(Val(ParamTextBox1.Text))
End If
End Sub
Private Sub RecipePage1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.RestrictedParamTextBox1.AllowedKeys = RestrictedParamTextBox.RestrictionCategory.OneDecimalPoint
End Sub
End Class
Public Class RestrictedParamTextBox
Inherits System.Windows.Forms.TextBox
Enum RestrictionCategory
NoRestriction
NumeralsOnly
LettersOnly
AlphanumericOnly
OneDecimalPoint
End Enum
Private _allowedKeys As RestrictionCategory
Property AllowedKeys() As RestrictionCategory
Get
Return _allowedKeys
End Get
Set(ByVal Value As RestrictionCategory)
Select Case Value
Case 1 To 4 ' One of the enum choices
_allowedKeys = Value
Case Else ' No restriction
_allowedKeys = 0
End Select
End Set
End Property
Protected Overrides Sub OnKeyPress(ByVal e As KeyPressEventArgs)
MyBase.OnKeyPress(e)
' Test whether key is allowed, based on the current choice
' from the enum
Select Case _allowedKeys
Case 1 'Numerals only
If IsNumeric(e.KeyChar) Then
Exit Sub
Else
e.Handled = True
End If
Case 2 ' Letters Only
If e.KeyChar Like "[A-z]" Then
Exit Sub
Else
e.Handled = True
End If
Case 3 ' Alphanumeric
If e.KeyChar Like "[A-z]" Then
If IsNumeric(e.KeyChar) Then
Exit Sub
Else
e.Handled = True
End If
End If
Case 4 ' OneDecimalPoint
If IsNumeric(e.KeyChar) Then
Debug.Print(e.KeyChar)
If e.KeyChar = "." Then
e.Handled = False
End If
End If
End Select
End Sub
End Class
The ultimate goal is to have several ParamTextBox (up to 25) on the form and limit the entries to each box to:
numeric, one decimal point, and then one of several limits, like 0.000 to 5.000, or 1.000 to 8.000 or 0.000 to 12.000, etc.
Any help would be appreciated.
Thanks,
Norason