?
Solved

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

Posted on 2006-11-13
4
Medium Priority
?
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:Hillwaaa
Hillwaaa earned 1000 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 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 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