M
MrJim
How should variables be declared and referenced in both the base and
derived form so they can be accessed?
derived form so they can be accessed?
MrJim said:How should variables be declared and referenced in both the base and
derived form so they can be accessed?
I've tried this method, but all I got was the variable is not a memberKen said:Hi,
You should be able to access stuff in a base class with
mybase.VariableName
Ken
I've tried this method, but all I got was the variable is not a member
of deviceapp1.etc.
Both the base and derived sub are declared as protected but still no luck.
ofFrom the description it sounds like you have something along the lines
Thanks a lot for your help, that makes things clearAlanT said:The important point is not whether or not how the subs are declared but
how the variable is declared.
of
BaseClass
Protected overridable Sub Foo()
dim bar as integer = 19
End Sub
DerivedClass
Protected Overrides Sub Foo()
bar = 23
End Sub
If so, you cannot access bar within the derived sub. it is not a
instance variable, it is local to the Base:Foo() sub and can only be
seen within that sub. If you want a variable that can be accessed in
both Base and Derived classes it needs to be a member of the class
e.g.
BaseClass
protected _bar as integer
Protected overridable Sub Foo()
_bar = 19
End Sub
DerivedClass
Protected Overrides Sub Foo()
_bar = 23
End Sub
or,
BaseClass
Private _bar as integer
Protected Property Bar as integer
get
return _bar
end get
set (value as integer)
_bar = value
end set
end property
Protected overridable Sub Foo()
Bar = 19
End Sub
DerivedClass
Protected Overrides Sub Foo()
Bar = 23
End Sub
hth,
Alan.