mikke3141
04-15-2010, 04:31 AM
Hello,
I'm studying the basics for building classes to support an array. One dimensional is already working, but the second dimensions has me in trouble.
Class1 module:
Option Explicit
Private str As Variant
Private MaxNo As Integer
Public Property Get aName(Index As Integer) As Variant
If Index > UBound(str) Or Index < LBound(str) Then
aName = ""
Else
aName = str(Index)
End If
End Property
Public Property Get aMonth(Index As Integer) As Variant
If Index > UBound(str) Or Index < LBound(str) Then
aMonth = ""
Else
aMonth = str(Index)
End If
End Property
Public Property Get Lukum() As Integer
Lukum = MaxNo
End Property
Public Sub fill_array(NameList() As Variant)
Dim ArrayNo As Integer
str = NameList
ArrayNo = UBound(NameList) - LBound(NameList) + 1
MaxNo = ArrayNo
End Sub
Module:
Option Explicit
Function FillIt() As Class1
Dim testobj As Class1
Dim names() As Variant
Dim Month() As Variant
Set testobj = New Class1
names = Array("First", "Second", "Third")
Month = Array("Jan", "Feb", "March")
testobj.fill_array names
testobj.fill_array Month
Set FillIt = testobj
End Function
Sub test()
Dim MyTest As Class1
Dim ArrayNo As Integer
Set MyTest = FillIt
MsgBox "Arrayn size is " & MyTest.Lukum
For ArrayNo = 0 To MyTest.Lukum - 1
MsgBox "2nd array " & ArrayNo + 1 & " is " & MyTest.aMonth(ArrayNo)
Next
For ArrayNo = 0 To MyTest.Lukum - 1
MsgBox "2nd array " & ArrayNo + 1 & " is " & MyTest.aMonth(ArrayNo)
Next
End Sub
I'm trying to add the month also to the array, so that e.g. MyTest.aName(0) would be 'First' and MyTest.aMonth(0) 'Jan'. Now the code writes over the first value, what is should not do. Thank you for your help.
I'm studying the basics for building classes to support an array. One dimensional is already working, but the second dimensions has me in trouble.
Class1 module:
Option Explicit
Private str As Variant
Private MaxNo As Integer
Public Property Get aName(Index As Integer) As Variant
If Index > UBound(str) Or Index < LBound(str) Then
aName = ""
Else
aName = str(Index)
End If
End Property
Public Property Get aMonth(Index As Integer) As Variant
If Index > UBound(str) Or Index < LBound(str) Then
aMonth = ""
Else
aMonth = str(Index)
End If
End Property
Public Property Get Lukum() As Integer
Lukum = MaxNo
End Property
Public Sub fill_array(NameList() As Variant)
Dim ArrayNo As Integer
str = NameList
ArrayNo = UBound(NameList) - LBound(NameList) + 1
MaxNo = ArrayNo
End Sub
Module:
Option Explicit
Function FillIt() As Class1
Dim testobj As Class1
Dim names() As Variant
Dim Month() As Variant
Set testobj = New Class1
names = Array("First", "Second", "Third")
Month = Array("Jan", "Feb", "March")
testobj.fill_array names
testobj.fill_array Month
Set FillIt = testobj
End Function
Sub test()
Dim MyTest As Class1
Dim ArrayNo As Integer
Set MyTest = FillIt
MsgBox "Arrayn size is " & MyTest.Lukum
For ArrayNo = 0 To MyTest.Lukum - 1
MsgBox "2nd array " & ArrayNo + 1 & " is " & MyTest.aMonth(ArrayNo)
Next
For ArrayNo = 0 To MyTest.Lukum - 1
MsgBox "2nd array " & ArrayNo + 1 & " is " & MyTest.aMonth(ArrayNo)
Next
End Sub
I'm trying to add the month also to the array, so that e.g. MyTest.aName(0) would be 'First' and MyTest.aMonth(0) 'Jan'. Now the code writes over the first value, what is should not do. Thank you for your help.