Solved

Why did I have to change my method to "shared"?

Posted on 2006-11-13
4
181 Views
Last Modified: 2010-04-23
1. *** in UserInterface, aspx, I have this:
       Dim test As New U_DAL.MyUni.WebProject.Data.UserData.UserAccess
        test.DBType = UDAL.DataProvider.SqlServer  '********* This SETS the correct value *************

        U_BLL.MuUni.WebProject.Business.UserInfo.User.UniUser("Tom")

2. *** IN BLL, I have this:
 Public Class User
        Shared Function UniUser(ByVal Identity As String) As ArrayList

            Dim userData As New ArrayList

            Dim test As New U_DAL.MyUni.WebProject.Data.UserData.UserAccess  '***note the word NEW
            userData = test.GetSystems(RemoveDomain(Identity))
            Return userData
        End Function

3. ***IN DAL,
Private _DBType As DataProvider
        Public Property DBType() As DataProvider
            Get
                Return _DBType
            End Get
            Set(ByVal value As DataProvider)
                _DBType = value

            End Set
        End Property

        Public Function GetSystems(ByVal userLogin As String) As ArrayList
           ......

        End Function

******I had to change the "GetSystems" to Shared and the "Property" to Shared and remove "  Dim test As New U_DAL.MyUni.WebProject.Data.UserData.UserAccess" in BLL. Otherwise, the "set" was working but "Get" was not returning the value that was already "set"...

0
Comment
Question by:Camillia
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:Hillwaaa
Hillwaaa earned 250 total points
ID: 17934370
Hi Farzadw,

You had to change the GetSystems to shared as you have "UniUser" set as Shared.  The User class is therefore never instanciated, which means that when GetSystems is called it has to be as a Shared method as well.

As an alternative, you could create a new User object in UserInterface like

Dim newUser = U_BLL.MuUni.WebProject.Business.UserInfo.User()

and change the UniUser function declaration to:

Public Class User
        Function UniUser(ByVal Identity As String) As ArrayList 'Note that it is not shared


Then you could call:

newUser.UniUser("Tom")

Cheers!
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17934859
Farzadw,

Shared method is part of class rather than instances. So whener you need to share certian functionality or to share common property thru out all instance of classes, u can think of shared fields.

So you dont have create instances, just use with class name.
0
 
LVL 7

Author Comment

by:Camillia
ID: 17935017

All makes sense...But I still cant remove the 'shared' from DAL code. I can remove it from the BLL code. If I remove the "Shared" from the DAL code, then BLL has to create an instance of "GetSystems" which means the "Get property" will be rest...

----This works with removing "shared" from BLL code:

***DAL code:
Private Shared _DBType As DataProvider
        Public Shared Property DBType() As DataProvider
            Get
                Return _DBType
            End Get
            Set(ByVal value As DataProvider)
                _DBType = value

            End Set
        End Property

        Public Shared Function GetSystems(ByVal userLogin As String) As ArrayList
           ......

        End Function


***BLL:
Public Class User
        'check user authorization. If user exists,get datbases user can access
        'Shared Function UniUser(ByVal Identity As String) As ArrayList
        Function UniUser(ByVal Identity As String) As ArrayList

            Dim userData As New ArrayList
            userData = GetSystems(RemoveDomain(Identity)) '*** If I remove shared from DAL, then I have to create an instance
            Return userData


        End Function

***UI:
Dim newUser As New U_BLL.MuUni.WebProject.Business.UserInfo.User()
newUser.UniUser("Tom")

***********I guess it's ok to have the DAL as shared..yes, no?

0
 
LVL 6

Accepted Solution

by:
riyazthad earned 250 total points
ID: 17935207
I think your code is good have shared method. This is best place to create as shared method. So go ahead with shared in DAL.

Enjoy coding

Thad
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now