P
peter
I have a problem with a 2D array containing objects
that crashes when I try to read more els out than I put in.
It gives a Type Mismatch.
Here's the main code (everything except the object)
Hope you can help,
Peter.
Const ID_CMD = 1
Const ID_MAC = 2
Const MAX_ARRAY = 5 ' max index of arrays
Const MAX_ROW = 22 ' max index of contents of all arrays
Private aAllArrays (1 To MAX_ARRAY, 1 To MAX_ROW) As Variant
Private aArrayNames (1 To MAX_ARRAY ) As String
Private aSheetNames (1 To MAX_ARRAY ) As String
Private aCurrIndexes(1 To MAX_ARRAY) As Integer
Private aMaxIndexes (1 To MAX_ARRAY) As Integer
aArrayNames(ID_CMD) = "CMD"
aArrayNames(ID_MAC) = "MAC"
aSheetNames(ID_CMD) = "spec6B"
aSheetNames(ID_MAC) = "MAC"
aCurrIndexes(ID_CMD) = 1
aCurrIndexes(ID_MAC) = 1
aMaxIndexes(ID_CMD) = 1
aMaxIndexes(ID_MAC) = 1
'
' addToArray
'
Private Sub addToArray(iID As Integer, _
vItem As Variant)
If aCurrIndexes(iID) > MAX_ROW Then
MsgBox "Too many objects in " & aArrayNames(iID), vbCritical
Else
MsgBox "Adding " & vItem.id & " to " & aArrayNames(iID) & "
array."
Set aAllArrays(iID,aCurrIndexes(iID)) = vItem
aCurrIndexes(iID) = aCurrIndexes(iID) + 1
aMaxIndexes(iID) = aMaxIndexes(iID) + 1
End If
End Sub ' addToArray
'
' getNextOBJ
' If pointer is in range,
' Get the current obj from its array.
' Increment the pointer to the next one.
' Else Return Nothing.
'
Public Function getNextOBJ(iID As Integer) As Variant
If aCurrIndexes(iID) > aMaxIndexes(iID) Then
Set getNextOBJ = Nothing
MsgBox "Too many objects in array " & iID, vbCritical
Else
Set getNextOBJ = aAllArrays(iID, aCurrIndexes(iID)) ' *******
' Type mismatch at runtime.
' debugger:
' iID = 1
' aCurrIndexes(iID) = 3
aCurrIndexes(iID) = aCurrIndexes(iID) + 1
End If
End Function ' getNextOBJ
'
' main
'
Sub main()
Dim oCMD As clsCMDdefn6B
Set oCMD = New clsCMDdefn6B
oCMD.init Me
addToArray ID_CMD, oCMD
addToArray ID_CMD, oCMD
oCMD = getNextOBJ(ID_CMD)
oCMD = getNextOBJ(ID_CMD)
oCMD = getNextOBJ(ID_CMD) ' ****crashes******
End Sub ' main
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
that crashes when I try to read more els out than I put in.
It gives a Type Mismatch.
Here's the main code (everything except the object)
Hope you can help,
Peter.
Const ID_CMD = 1
Const ID_MAC = 2
Const MAX_ARRAY = 5 ' max index of arrays
Const MAX_ROW = 22 ' max index of contents of all arrays
Private aAllArrays (1 To MAX_ARRAY, 1 To MAX_ROW) As Variant
Private aArrayNames (1 To MAX_ARRAY ) As String
Private aSheetNames (1 To MAX_ARRAY ) As String
Private aCurrIndexes(1 To MAX_ARRAY) As Integer
Private aMaxIndexes (1 To MAX_ARRAY) As Integer
aArrayNames(ID_CMD) = "CMD"
aArrayNames(ID_MAC) = "MAC"
aSheetNames(ID_CMD) = "spec6B"
aSheetNames(ID_MAC) = "MAC"
aCurrIndexes(ID_CMD) = 1
aCurrIndexes(ID_MAC) = 1
aMaxIndexes(ID_CMD) = 1
aMaxIndexes(ID_MAC) = 1
'
' addToArray
'
Private Sub addToArray(iID As Integer, _
vItem As Variant)
If aCurrIndexes(iID) > MAX_ROW Then
MsgBox "Too many objects in " & aArrayNames(iID), vbCritical
Else
MsgBox "Adding " & vItem.id & " to " & aArrayNames(iID) & "
array."
Set aAllArrays(iID,aCurrIndexes(iID)) = vItem
aCurrIndexes(iID) = aCurrIndexes(iID) + 1
aMaxIndexes(iID) = aMaxIndexes(iID) + 1
End If
End Sub ' addToArray
'
' getNextOBJ
' If pointer is in range,
' Get the current obj from its array.
' Increment the pointer to the next one.
' Else Return Nothing.
'
Public Function getNextOBJ(iID As Integer) As Variant
If aCurrIndexes(iID) > aMaxIndexes(iID) Then
Set getNextOBJ = Nothing
MsgBox "Too many objects in array " & iID, vbCritical
Else
Set getNextOBJ = aAllArrays(iID, aCurrIndexes(iID)) ' *******
' Type mismatch at runtime.
' debugger:
' iID = 1
' aCurrIndexes(iID) = 3
aCurrIndexes(iID) = aCurrIndexes(iID) + 1
End If
End Function ' getNextOBJ
'
' main
'
Sub main()
Dim oCMD As clsCMDdefn6B
Set oCMD = New clsCMDdefn6B
oCMD.init Me
addToArray ID_CMD, oCMD
addToArray ID_CMD, oCMD
oCMD = getNextOBJ(ID_CMD)
oCMD = getNextOBJ(ID_CMD)
oCMD = getNextOBJ(ID_CMD) ' ****crashes******
End Sub ' main
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!