[RESOLVED] [02/03] protected vs Dim
if i define a webusercontrol :
lets say ,
dim withevents Webusercontrol11 as Webusercontrol1
then use of any of its public property or method , generates an error
"Object reference not set to an instance of an object ."
if i use ,
protected withevents Webusercontrol11 as Webusercontrol1
it works fine
why ?
Re: [02/03] protected vs Dim
Dim means Private. And Protected mean variable can be accessible to It class and it's immediate child.
Re: [02/03] protected vs Dim
Dim's a legacy BASIC keyword. You should use the explicit scope modifiers.
Re: [02/03] protected vs Dim
i know the basic difference regarding inheritance .
but that does not answer my question.
Re: [02/03] protected vs Dim
ok i got this one.
the answer lies in how aspx pages are processed.
http://msdn2.microsoft.com/en-us/lib...ontrols_topic4
When an aspx page is requested , a class is automatically created which is derived from the Web page's code-behind class (apx.vb).
this new class constructs the Web page's control hierarchy.
so any control which is declared as dim/private , will not appear in this hierarchy and hence reference to any such control will result in
"NullReferenceException" error .
so all controls on a web page needs to be declared protected ( at least ) :thumb:
Re: [02/03] protected vs Dim
Quote:
Originally Posted by penagate
Dim's a legacy BASIC keyword. You should use the explicit scope modifiers.
it is??
then what do you use to declare a variable at the procedure level?
as in:
Code:
Private Sub test()
Dim A As String 'VALID
Private B As String 'ERROR
Friend C As String 'ERROR
Public D As String 'ERROR
Protected E As String 'ERROR
End Sub
Re: [RESOLVED] [02/03] protected vs Dim
Whoops. I meant at class level. :)
1 Attachment(s)
Re: [RESOLVED] [02/03] protected vs Dim
I guess you could consider it legacy at the class level, however I don't have any gripes about using Dim at the class level (others might)
When you use Dim at the class level, VB automatically assumes its private, infact if you mouse over it, you will see that it has a private modifier.