Hi guys!
Could someone please show me how to declare scope for variables outside their class?

Here's what i have in a class known Create_User:

Public Class Create_User

    Public conn As New SqlConnection(My.Settings.HotelConnectionString)
    Public usercmd As SqlCommand
    Public userstring As String
    Public userdat As SqlDataAdapter


............

End Sub

How can i increase the scope of these variables to be used in another class? I dont want to keep declaring them again and again.

Try the use of modules.
Go to project, add module.
declare your variables here.
They will be visible by all your classes.
Remember to make them public.

You could create a class/project to store all of your global variables. You could also create a main class and declare an instance of Create_User and your other classes within that class. Then you could just store your global variables within the main class.

Hi guys!
Could someone please show me how to declare scope for variables outside their class?

Here's what i have in a class known Create_User:

Public Class Create_User

    Public conn As New SqlConnection(My.Settings.HotelConnectionString)
    Public usercmd As SqlCommand
    Public userstring As String
    Public userdat As SqlDataAdapter


............

End Sub

How can i increase the scope of these variables to be used in another class? I dont want to keep declaring them again and again.

i've created a module that looks like this:

Module Connection
    Public conn As New SqlConnection(My.Settings.HotelConnectionString)
    Public usercmd As SqlCommand
    Public userstring As String
    Public userdat As SqlDataAdapter

End Module

I then commented out the instances where i had used them i.e in the above stated code but the compiler could not recognize them.

I'm i missing something or how does it work?

No worries. I restarted the project and it worked. thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.