M
Miro
First off...thanks in advance for getting me this far.
Sorry for all these class posts but im having a heck of a time here trying
to get something to work,
and have finally got it to work ( yahooooo ) but i dont know why now I cant
get it to work the other way.
Vb 2003
Below are 2 examples. One Does not work and the other does.
Now i know why the one example works, ive basically shared everything and
off we go.
But why cannot I Private the var and Public the property ?
It compiles...but its like it thinks then its assigning the value to a
"something" that doesnt exist yet.
Even if I dim BlaSys() without a ( # ) # in there...and redim...it
still fails.
--- my conclusion ---
What Im starting to think is that you CANNOT have an array of a Class that
has properties.
But what you have to do is have a Class with an Array of Properties.
Am I right in this statement?
Has anyone else tried to make an Array Class ?
My Last example is a simple way so the full length ( since it might not be
known ) will always work. 99 is not a set limit.
Miro
=======This does not work ================
'Somewhere in a sub
'compiles ok but will get an exception error during runtime
Dim BlaSys(2) As SystemFilesClass 'Cannot put "New" ...it
wont allow it
BlaSys(1).Prop_FieldName = "hi" 'will return "Object
reference not set to an instance of an object" - crashes here
'==== a class
Public Class SystemFilesClass
Private FieldName As String
Public Property Prop_FieldName() As String 'This cannot go "SHARED"
cause the FieldName is Private
Get
Return FieldName
End Get
Set(ByVal Value As String)
FieldName = Value
End Set
End Property
End Class
=====================
=========This works=============
'Somewhere in a sub
Dim BlaSys As New SystemFilesClass() 'Allows a "NEW" on the
class
BlaSys.Prop_FieldName(1) = "hi" 'Works
BlaSys.Prop_FieldName(2) = "Bye" 'Works
'======= a class
Public Class SystemFilesClass
Shared FieldName(99) As String 'Number of elelments must be defined
Shared Property Prop_FieldName(ByVal Element As Integer) As String
Get
Return FieldName(Element)
End Get
Set(ByVal Value As String)
FieldName(Element) = Value
End Set
End Property
End Class
================================
========= modified code of code that works that takes care of an infinite
array of FieldName ===========
Dim BlaSys As New SystemFilesClass() 'Allows a "NEW" on the
class
BlaSys.Prop_FieldName(1) = "hi" 'Works
BlaSys.Prop_FieldName(2) = "Bye" 'Works
Public Class SystemFilesClass
Shared FieldName(1) As String 'the 1 or a number must be here...taken
care of as we add new elements.
Shared Property Prop_FieldName(ByVal Element As Integer) As String
Get
Return FieldName(Element)
End Get
Set(ByVal Value As String)
If UBound(FieldName) < Element Then
'redims the array + 1 : probably want to go up by 10's to
save
'time / memory but it proves the point of just adding to it.
( preserve ) must be here to
'keep track of old assigned array values.
ReDim Preserve FieldName(UBound(FieldName) + 1)
End If
FieldName(Element) = Value
End Set
End Property
End Class
=============================
Sorry for all these class posts but im having a heck of a time here trying
to get something to work,
and have finally got it to work ( yahooooo ) but i dont know why now I cant
get it to work the other way.
Vb 2003
Below are 2 examples. One Does not work and the other does.
Now i know why the one example works, ive basically shared everything and
off we go.
But why cannot I Private the var and Public the property ?
It compiles...but its like it thinks then its assigning the value to a
"something" that doesnt exist yet.
Even if I dim BlaSys() without a ( # ) # in there...and redim...it
still fails.
--- my conclusion ---
What Im starting to think is that you CANNOT have an array of a Class that
has properties.
But what you have to do is have a Class with an Array of Properties.
Am I right in this statement?
Has anyone else tried to make an Array Class ?
My Last example is a simple way so the full length ( since it might not be
known ) will always work. 99 is not a set limit.
Miro
=======This does not work ================
'Somewhere in a sub
'compiles ok but will get an exception error during runtime
Dim BlaSys(2) As SystemFilesClass 'Cannot put "New" ...it
wont allow it
BlaSys(1).Prop_FieldName = "hi" 'will return "Object
reference not set to an instance of an object" - crashes here
'==== a class
Public Class SystemFilesClass
Private FieldName As String
Public Property Prop_FieldName() As String 'This cannot go "SHARED"
cause the FieldName is Private
Get
Return FieldName
End Get
Set(ByVal Value As String)
FieldName = Value
End Set
End Property
End Class
=====================
=========This works=============
'Somewhere in a sub
Dim BlaSys As New SystemFilesClass() 'Allows a "NEW" on the
class
BlaSys.Prop_FieldName(1) = "hi" 'Works
BlaSys.Prop_FieldName(2) = "Bye" 'Works
'======= a class
Public Class SystemFilesClass
Shared FieldName(99) As String 'Number of elelments must be defined
Shared Property Prop_FieldName(ByVal Element As Integer) As String
Get
Return FieldName(Element)
End Get
Set(ByVal Value As String)
FieldName(Element) = Value
End Set
End Property
End Class
================================
========= modified code of code that works that takes care of an infinite
array of FieldName ===========
Dim BlaSys As New SystemFilesClass() 'Allows a "NEW" on the
class
BlaSys.Prop_FieldName(1) = "hi" 'Works
BlaSys.Prop_FieldName(2) = "Bye" 'Works
Public Class SystemFilesClass
Shared FieldName(1) As String 'the 1 or a number must be here...taken
care of as we add new elements.
Shared Property Prop_FieldName(ByVal Element As Integer) As String
Get
Return FieldName(Element)
End Get
Set(ByVal Value As String)
If UBound(FieldName) < Element Then
'redims the array + 1 : probably want to go up by 10's to
save
'time / memory but it proves the point of just adding to it.
( preserve ) must be here to
'keep track of old assigned array values.
ReDim Preserve FieldName(UBound(FieldName) + 1)
End If
FieldName(Element) = Value
End Set
End Property
End Class
=============================