Wednesday, August 30, 2006

basic Vector class for VB 6


Private arrObj() As Variant
Public Function length() As Integer
length = UBound(arrObj)
End Function

Private Sub Class_Initialize()
ReDim Preserve arrObj(0)
End Sub

Public Sub add(oObject)
If IsObject(oObject) Then
Set arrObj(UBound(arrObj)) = oObject
Else
arrObj(UBound(arrObj)) = oObject
End If
ReDim Preserve arrObj(UBound(arrObj) + 1)
End Sub

Public Function getAt(intAtWhat As Integer) As Variant
If intAtWhat >= 0 And intAtWhat < length() Then
If IsObject(arrObj(intAtWhat)) Then
Set getAt = arrObj(intAtWhat)
Else
getAt = arrObj(intAtWhat)
End If
End If
End Function

Public Sub remove(intAtWhat As Integer)
If intAtWhat >= 0 And intAtWhat < length() Then
For i = intAtWhat To length - 1
If IsObject(arrObj(i + 1)) Then
Set arrObj(i) = arrObj(i + 1)
Else
arrObj(i) = arrObj(i + 1)
End If
Next
ReDim Preserve arrObj(UBound(arrObj) - 1)
End If
End Sub

Web Hosting Cheap PHP Plans Also at For free flags of the world