Reference TextBox from Functions
I need to be able to referecne ofjects from my forms in my functions.
This is my Function
Function fncLogin(ByRef Sender As Object, ByVal e As System.EventArgs)
Dim EmployeeName As Login
EmployeeName = CType(Sender, Login)
If EmployeeName.TextBox1.Text = "" Then
MsgBox("You must enter a username!", vbExclamation)
EmployeeName.TextBox2.Focus()
Exit Function
End If
If EmployeeName.TextBox2.Text = "" Then
MsgBox("You must enter a password!", vbExclamation)
EmployeeName.TextBox2.Focus()
Exit Function
End If
End Function
When I try to call this function with this.
fncLogin()
It is underlined.
What am I doing wrong?
Thanks!
Re: Reference TextBox from Functions
Quote:
Originally posted by indydavid32
When I try to call this function with this.
fncLogin()
It is underlined.
What am I doing wrong?
You didn't pass in the required parameters (Sender and e) that is why it isn't working for you.
Should be something like this:
fncLogin(Me,Nothing)
Also A function (albeit doesn't have to) should return something where as a Sub should be used if no value is returned.
It looks like your function requires that a form be passed as the sender. And that form should have 2 textboxes one it. You should look into inhertiance and reuse the form itself instead of putting all the functions in a common module.