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.

Edited 6 Years Ago by roottybrian: clarity

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?
This question has already been answered. Start a new discussion instead.