Solved

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

Posted on 2006-11-13
4
199 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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