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

"Not a member of" error 1

Status
Not open for further replies.

norason

Programmer
Jan 28, 2009
139
US
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
 

Somewhere in your code you need to do something like this:


'this line should be global to the form
Dim restrictedparamtextbox1 As RestrictedParamTextBox


'these lines should be in a sub, such as Form_Load
restrictedparamtextbox1 = New RestrictedParamTextBox
Me.Controls.Add(restrictedparamtextbox1)

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks a million - I'll make the additions tomorrow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top