|
-
Dec 31st, 2002, 12:08 PM
#1
Thread Starter
Fanatic Member
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!
-
Dec 31st, 2002, 12:16 PM
#2
You actually have aq multitude of problems
a) Your function has no return type
b) You never return a value so using a function is pointless anyway, should be a sub
c) What object is Login?
-
Dec 31st, 2002, 12:25 PM
#3
Thread Starter
Fanatic Member
Login is the code that runs when the user 1st logs in.
I want this code to be able to run if they hit enter on the password text box, or if they click the command button.
That's why I have it in a function so I don't have to put the same code in twice.
I would rather use modules because it's easier to find the code than buried in subs on the form.
Is this a bad practice?
I've only been programming a few years with very little in the way of structure and only one other programmer here who is an old Basic programmer.
-
Dec 31st, 2002, 01:08 PM
#4
Re: Reference TextBox from Functions
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.
Last edited by Edneeis; Dec 31st, 2002 at 01:12 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|