public var not visible? :(

  • Thread starter Thread starter droll
  • Start date Start date
D

droll

i must be doing something fundamentally wrong.

i have a main form class in which i declare a
public int testvar;

i have another class i created. this class is in the same namespace as the
main form class. however, i cannot access 'testvar' from this class. it
doesn't show up in intellisense. if i declare an enum in the main form
class, it does show up.

????? what am i doing wrong? :(
 
Are you using VS2003 as I have seen a bug in this version. Try writing to
code to access the variable then compiling forgetting about intellisense for
a minute.

Cheers
Simon.
 
i must be doing something fundamentally wrong.

i have a main form class in which i declare a
public int testvar;

i have another class i created. this class is in the same namespace as the
main form class. however, i cannot access 'testvar' from this class. it
doesn't show up in intellisense. if i declare an enum in the main form
class, it does show up.

????? what am i doing wrong? :(

Hmm - apologies if this is a mistake you'd never make, but could you
be trying to access an instance variable via the type name of your
form class, instead of via an instance of the form?

That is, if your main forms (class) name is MainForm, and you have a

public int testvar;

in there, you cannot access it from within another form or class via

int v = MainForm.testvar;

For this to work, you'd need to make testvar static, like so:

static public int testvar;

The consequence of this is that this variable is common to all
instances of your form (that is, if you want to open several windows
of this same type) - probably less likely under the CF than under the
full framework.

Regards,
Gilles [MVP].

(Please reply to the group, not via email)
 
yes, you are right. that's what i'm trying to do. thanks. i understand it
now! *banging head against wall* sigh :(
 
Back
Top