Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

send a value from a form to another form or just access that value somehow

Hi,
I am trying to get a value from a form to use in a different form. The one form has a textbox that the user enters their employee ID into. Then that form uses that ID to decide what form to go to next. So it then chooses the clock in and out form which needs the employee ID that the user entered on the other form. I've been trying to set variables to public and also I tried making get and set functions and using them to retrieve the value.
here is some code...

Public rEmpID As String        (this is at the top of the login form)

setEmp(dr(0))            (this is in a button click procedure retrieving the employeeID from an executereader
                                    but I maybe could also get the value from the textbox)

Public Function setEmp(ByVal emp As Integer)
        rEmpID = emp                                               (my set and get functions located in the login form)
    End Function
Public Function returnEmp()
        Return rEmpID
End Function


Public loginForm As New LogForm                    (this is at the top of the clock in and out form)

employeeID = loginForm.returnEmp()           (this is in a button click procedure in the clock in and out form)


So I'm not sure how to make this work, any ideas would be great!
Thanks!
0
JoshWegener
Asked:
JoshWegener
  • 3
  • 2
1 Solution
 
Brian CroweCommented:
It is poor design practice to make controls or variables public.  It is a much better practice to create property methods for the variables you wish to expose.
 
public readonly property EmployeeID() as integer
   Get
      if isnumeric(txtEmployeeID.text) then
         return cint(txtemployeeid.text)
      else
         return -1
      end if
   end get
end property
0
 
Brian CroweCommented:
as for the usage...

dim iEmployeeID as integer

iEmployeeID = loginForm.EmployeeID
0
 
JoshWegenerAuthor Commented:
Ok I put that code in and it still doesn't work, would it be because when I go to the clock in and out form I first hide the login form so would it then be clearing out the textbox? I need to know how to make it not clear the textbox or to just save the value in the textbox to get later before it clears it out whenever its doing it.
0
 
Brian CroweCommented:
please post the code where you are instantiating the form with the employeeid textbox.
0
 
JoshWegenerAuthor Commented:
Ah yes I didn't have a textbox declared to put the value from the form textbox into.
I do now :-) Thanks so much!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now