public variable reference issue - help (noob)

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Here is the code. If I rem out the first line, everything works, but
I can't reference the myVariables object in later methods (form
events). If I leave it in, and remove the declaration line in the
Main method, I get an error (Error 1 An object reference is required
for the nonstatic field, method, or property
'RLPI.Subscriptions.Explorer.myVariables'). How do I refence a
varialbe accross methods, within a class?

Thanks.

public BaseVariables myVariables = new BaseVariables();

public static void Main()
{
BaseVariables myVariables = new BaseVariables();
myVariables.connectionString =
"server=SQLDB.RL.INT;database=Subs_Dev;Integrated Security=SSPI;";
myVariables.LoadSqlConnection();



Application.Run(new Explorer());
}



Dan
 
Here is the code.  If I rem out the first line, everything works, but
I can't reference the myVariables object in later methods (form
events).  If I leave it in, and remove the declaration line in the
Main method, I get an error (Error      1       An object reference is required
for the nonstatic field, method, or property
'RLPI.Subscriptions.Explorer.myVariables').  How do I refence a
varialbe accross methods, within a class?

Thanks.

public BaseVariables myVariables = new BaseVariables();

public static void Main()
        {
            BaseVariables myVariables = new BaseVariables();
            myVariables.connectionString =
"server=SQLDB.RL.INT;database=Subs_Dev;Integrated Security=SSPI;";
            myVariables.LoadSqlConnection();

            Application.Run(new Explorer());
        }

Dan

your "Main" method is static, so you'll need any member variables that
it uses to also be static. add the static keyword to your variable
declaration.
 
Guess this should ideally be in the VB forumn, but i'll try to give it a shot.
Have you tried :
//Declaration
public BaseVariables myVariables;

public static void Main()
{
//instantiate
myVariables = new BaseVariables();
myVariables.connectionString =
"server=SQLDB.RL.INT;database=Subs_Dev;Integrated Security=SSPI;";
myVariables.LoadSqlConnection();



Application.Run(new Explorer());
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top