Global varible

That is different. My apologies. Just give me a minute to get my high horse off this soap-box... I think Microsoft would be happy if everyone migrated to C#, but it ain't gonna happen. A good developer will not be lulled, but removing the temptation is often a solution to preventing bad behaviour in any situation.
 
While I disagree with not using .Net, I have to agree that the module can lull you into a false sense of security

For example, you write a program that two people are using. You have a global variable called 'sGlobFilter', which is a perfectly good name for a global variable which holds a SQL expression which is sometimes used as a filter.

Unfortunately, it is global to the program. That means person 'a' sets it, and person 'b' is suddenly affected by it, always in ASP.Net and sporadically in Windows applications

Now it looks like your program doesn't work. Another drawback with .Net is that the documentation reads like an after-thought. If it isn't intuitively obvious to you how OOP works, then you are going to get these neat little surprises that survive your one-man-operation test environment and make it out into the field.
 
All you newbies out there...you should read these posts about 20 times in a row!!!

btw nice example Joe of Singleton pattern.
 
The purpose of having a global variable is exactly that, to have access to it from everywhere. It doesn't matter whether you use a module, a singleton class or a class with all Shared members, you can still affect the single value of a global variable from anywhere in your application, so the same issues are applicable. If you don't want global access then don't use a global variable, of any kind, but if you do want global access then do. If someone is at the stage of creating a multi-user application then they should be at the stage of knowing the issues associated with global access to variables. Having a single database accessed by multiple clients is just an extension of this. Basically, good programming is good programming and bad is bad. If someone uses a global variable out of laziness then they deserve to have their application crash and burn, but if they truly need a global variable then the same issues apply, however they implement it.
 
Joe Mamma,

Thanks for the example of how to use a Global Class it has been a really help and I am in the process of getting rid of all the Global Variables :p .

I however do need a bit of help of how to write a public property for an arraylist. Below is the code that I am using but it is giving me an error 'Object reference not set to an instance of an object'

Code:
Public Class ICASData

    Private Shared mInstance As ICASData
    Private mPermissions As ArrayList

    Private Sub New()
    End Sub

    Public Property Permissions() As ArrayList
        Get
            Return mPermissions
        End Get
        Set(ByVal Value As ArrayList)
            mPermissions = Value
        End Set
    End Property

    Shared ReadOnly Property Instance() As ICASData
        Get
            If mInstance Is Nothing Then mInstance = New ICASData()
            Return mInstance
        End Get
    End Property
End Class

And this is the code that I am using to try and set the arraylist property.

Code:
ICASData.Instance.Permissions.Add("RW")

But it's not working, any help from you guys would be of great help.

Cheers

Simon
 
At a quick glance you might want to replace Private mPermissions As ArrayList with
Visual Basic:
Private mPermissions As New ArrayList
And
Visual Basic:
    Public Property Permissions() As ArrayList
        Get
            Return mPermissions
        End Get
        Set(ByVal Value As ArrayList)
            mPermissions.AddRange(Value)
        End Set
    End Property

I haven't tested this but I think it should work fine.
 
Back
Top