Results 1 to 4 of 4

Thread: Reference TextBox from Functions

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Unhappy 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!
    David Wilhelm

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612
    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.
    David Wilhelm

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    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
  •  



Click Here to Expand Forum to Full Width