Class theory, what am I missing
-
Good day fellow codeproject.com'ers. I am missing a vital part of theory which I've identified when I tried the below. (I believe it's theory...) Please can one of you assist me by filling the theory gap I have. I've been through MSDN and Google, but to no avail... Question: Why can one not call a class from within another class? I don't mean within a function of a class, but at the top, where one declares variables pertaining to that class. E.g. Below:
Friend Class Class1
Dim _message As StringPublic Property Message() Get Return \_message End Get Set(ByVal value) \_message = value End Set End Property
End Class
And here is where it fails, intellisense doesn't see the properties or methods of the variable (first class), I've labled the variable as THISDOESNTWORK.
Friend Class Class2
Dim _myVariable As String
Dim THISDOESNTWORK as New Class1Public Property myVariable() Get Return \_message End Get Set(ByVal value) \_message = value End Set End Property
End Class
It works when I place the code
Dim THISDOESNTWORK as New Class1
within a function, so either there is a "secret way to do this", or I'm missing a bit of .Net/OOB Theory. Thanks in advance... :) -
Good day fellow codeproject.com'ers. I am missing a vital part of theory which I've identified when I tried the below. (I believe it's theory...) Please can one of you assist me by filling the theory gap I have. I've been through MSDN and Google, but to no avail... Question: Why can one not call a class from within another class? I don't mean within a function of a class, but at the top, where one declares variables pertaining to that class. E.g. Below:
Friend Class Class1
Dim _message As StringPublic Property Message() Get Return \_message End Get Set(ByVal value) \_message = value End Set End Property
End Class
And here is where it fails, intellisense doesn't see the properties or methods of the variable (first class), I've labled the variable as THISDOESNTWORK.
Friend Class Class2
Dim _myVariable As String
Dim THISDOESNTWORK as New Class1Public Property myVariable() Get Return \_message End Get Set(ByVal value) \_message = value End Set End Property
End Class
It works when I place the code
Dim THISDOESNTWORK as New Class1
within a function, so either there is a "secret way to do this", or I'm missing a bit of .Net/OOB Theory. Thanks in advance... :)class2 needs to be like this
Friend Class Class2
Dim _myVariable As String
Dim THISDOESNTWORK As New Class1
Public Property myVariable()
Get
Return THISDOESNTWORK.Message
End Get
Set(ByVal value)
THISDOESNTWORK.Message = value
End Set
End Property
End Class'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
-
class2 needs to be like this
Friend Class Class2
Dim _myVariable As String
Dim THISDOESNTWORK As New Class1
Public Property myVariable()
Get
Return THISDOESNTWORK.Message
End Get
Set(ByVal value)
THISDOESNTWORK.Message = value
End Set
End Property
End Class'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
Thank you! Ah, a blonde moment of note! This one will definatly go down in the books a silly moment for me, hopefully this helps someone else :) Thanks again. - Artificial intelligence is no match for natural stupidity
-
Thank you! Ah, a blonde moment of note! This one will definatly go down in the books a silly moment for me, hopefully this helps someone else :) Thanks again. - Artificial intelligence is no match for natural stupidity
It should also be mentioned that your syntax might be a bit off: Friend Class Class2 Dim _myVariable As String Dim THISDOESNTWORK as New Class1 Public Property myVariable()as string Get Return THISDOESNTWORK._message End Get Set(ByVal value as string) THISDOESNTWORK._message = value End Set End Property End Class or Friend Class Class2 Dim _myVariable As String Dim THISDOESNTWORK as New Class1 Public Property myVariable() as Class1 Get Return THISDOESNTWORK End Get Set(ByVal value as Class 1) THISDOESNTWORK= value End Set End Property End Class
Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my Blog