S
sougata12
Guest
Hi,
When an object is created for any class, we can access the properties of the class through that object and direct set it values. For example in the below example car1.Make ="Ford" is setting the value of the Make property for the car1.
Module Car
Class car
Public Property make As String
Public Property miles As Double
End Class
Sub Main()
Dim car1 As New car()
car1.make = "Ford"
car1.miles = 1254.3
End Sub
End Module
But in the nested class example that I am unable to directly set the "var2" property by direct assignment when accessed through the object "obj_nested". See code below:
Public Class Container
Public Property var1 As Integer
Private Class Nested
Public Property var2 As Integer
End Class
Dim obj_nested As New Nested()
Private example As Integer = obj_nested.var2 'works fine
Public Sub Demo() ' works fine
obj_nested.var2 = 1
End Sub
obj_nested.var2 = 5 'DOES NOT WORK. Red swiggly line coming
End Class
Module Nested_Example
Sub Main()
Dim obj_container As New Container()
'Cant create object of NESTED here as it is private
End Sub
End Module
Question is:
WHY is the statement obj_nested.var2 =5 not working? Is it not the same as car1.make = "Ford".What am I missing? And what declaration do I need to give (see error message in pic)?
PFB the screenshot where it is seen that the red swiggly line comes only on the "obj_nested.var2 =5". I am unable to sort this out..so requesting help.
Sougata Ghosh
Continue reading...
When an object is created for any class, we can access the properties of the class through that object and direct set it values. For example in the below example car1.Make ="Ford" is setting the value of the Make property for the car1.
Module Car
Class car
Public Property make As String
Public Property miles As Double
End Class
Sub Main()
Dim car1 As New car()
car1.make = "Ford"
car1.miles = 1254.3
End Sub
End Module
But in the nested class example that I am unable to directly set the "var2" property by direct assignment when accessed through the object "obj_nested". See code below:
Public Class Container
Public Property var1 As Integer
Private Class Nested
Public Property var2 As Integer
End Class
Dim obj_nested As New Nested()
Private example As Integer = obj_nested.var2 'works fine
Public Sub Demo() ' works fine
obj_nested.var2 = 1
End Sub
obj_nested.var2 = 5 'DOES NOT WORK. Red swiggly line coming
End Class
Module Nested_Example
Sub Main()
Dim obj_container As New Container()
'Cant create object of NESTED here as it is private
End Sub
End Module
Question is:
WHY is the statement obj_nested.var2 =5 not working? Is it not the same as car1.make = "Ford".What am I missing? And what declaration do I need to give (see error message in pic)?
PFB the screenshot where it is seen that the red swiggly line comes only on the "obj_nested.var2 =5". I am unable to sort this out..so requesting help.
Sougata Ghosh
Continue reading...