Return public class readonly property

klharding

Member
Joined
Sep 16, 2008
Messages
8
Location
New Hampshire
Programming Experience
3-5
I have created a class called clsLogIn
VB.NET:
Public Class clsLogin
    Private _user_id As Long
    Private _fullname As String
    Private _user_name As String
    Private _user_providernum As String
    Private _dept_id As Long
    Private _group_id As Long

    Public Sub New(ByVal cUser_id As Long, ByVal cFullName As String, _
                   ByVal cUser_Name As String, ByVal cUser_ProviderNum As String, _
                   ByVal cDept_ID As Long, ByVal cGroup_ID As Long)
        _user_id = cUser_id
        _fullname = cFullName
        _user_name = cUser_Name
        _user_providernum = cUser_ProviderNum
        _dept_id = cDept_ID
        _group_id = cGroup_ID
    End Sub

    Public ReadOnly Property UserId() As Long
        Get
            Return _user_id
        End Get
    End Property

    Public ReadOnly Property FullName() As String
        Get
            Return _fullname
        End Get
    End Property

    Public ReadOnly Property UserName() As String
        Get
            Return _user_name
        End Get
    End Property

    Public ReadOnly Property ProviderNum() As String
        Get
            Return _user_providernum
        End Get
    End Property

    Public ReadOnly Property DeptID() As Long
        Get
            Return _dept_id
        End Get
    End Property

    Public ReadOnly Property GroupID() As Long
        Get
            Return _group_id
        End Get
    End Property
End Class

So from frmLogIn I am using this code...
VB.NET:
Dim MyLogin As New clsLogin(results("user_id"), _
                                                fullname, _
                                                results("user_name"), _
                                                results("user_providernum"), _
                                                results("user_dept_id"), _
                                                results("user_group_id"))
Now I am on a different form, frmSchedule, and I want to get the ProviderNum property from clsLogin into a text box. How can I do this?

Thanks in advance for any help/advice!

Kristen
 
Well there are a number of ways to do this. Which form existed first, frmLogin or frmSchedule. If frmSchedule existed first, the I would call the frmLogin and have it return an object of type clsLogin.

The other possibility is if both forms exist at the same time, you could reach it be using syntax like myFormLogin.Login where your Login is a method to return an object of clsLogin type.

Does this help any?

Bernie
 
Well there are a number of ways to do this. Which form existed first, frmLogin or frmSchedule. If frmSchedule existed first, the I would call the frmLogin and have it return an object of type clsLogin.

The other possibility is if both forms exist at the same time, you could reach it be using syntax like myFormLogin.Login where your Login is a method to return an object of clsLogin type.

frmLogIn exists first. From the log in form I am calling a stored procedure to get the users information and placing it into the class with...
VB.NET:
Dim MyLogin As New clsLogin(results("user_id"), _
                                                fullname, _
                                                results("user_name"), _
                                                results("user_providernum"), _
                                                results("user_dept_id"), _
                                                results("user_group_id"))
Then based on the users "user_dept_id" I am opening certain forms with...
VB.NET:
Select Case MyLogin.DeptID
                        Case 1  'Administrator
                            Dim NewMDIChild As New frmSelectProvider()
                            NewMDIChild.MdiParent = frmMDI
                            NewMDIChild.Show()
                        Case 2  'Doctor
                            Dim NewMDIChild As New frmProviderSchedule()
                            NewMDIChild.MdiParent = frmMDI
                            NewMDIChild.Show()
                    End Select

So if the user is a doctor I want to open their schedule (frmProviderSchedule) and once that form opens I need to fill a text box with the doctor's "user_providernum" from the clsLogIn.
 
What you can do is use the Application's StartUp event (Look at the application event's in the project's properties) to handle the login stuff, if the login fails you can exit the app from the startup event without loading any other forms.

As for the passing data around, in the frmSchedule you can modify the constructor to include a parameter so when you make the instance of the form you pass the user_providernum variable at the same time
 
As for the passing data around, in the frmSchedule you can modify the constructor to include a parameter so when you make the instance of the form you pass the user_providernum variable at the same time

I am not sure how to pass the variable? Could you please give me an example?
 
Sure, look at the constructor in your clsLogin class:
VB.NET:
Public Class clsLogin
    Private _user_id As Long
    Private _fullname As String
    Private _user_name As String
    Private _user_providernum As String
    Private _dept_id As Long
    Private _group_id As Long

    [B]Public Sub New(ByVal cUser_id As Long, ByVal cFullName As String, _
                   ByVal cUser_Name As String, ByVal cUser_ProviderNum As String, _
                   ByVal cDept_ID As Long, ByVal cGroup_ID As Long)[/B]
        _user_id = cUser_id
        _fullname = cFullName
        _user_name = cUser_Name
        _user_providernum = cUser_ProviderNum
        _dept_id = cDept_ID
        _group_id = cGroup_ID
    End Sub
You're constructor's expecting the bolded items when you make a new instance of the class, just do the same with your frmSchedule
 
I am so confused...

So I need to create a new instance of clsLogIn everytime I need to get a variable?
No, change your form's constructor (the New sub) to accept the user_providernum value when you make an instance of the schedule form.
 
I feel really dumb today...

What do you mean by the "form's constructor"?
Do you mean this?

VB.NET:
Private Sub frmProviderSchedule_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
Back
Top