# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  Two Classes, a HashList and a refArray

## georgekar

This is a new idea. First the refArray class  used for UDT substitute, by a simple way. WE make each "row" of refArray as a simple value or an array (we can choose specific type). If we want to write to an index above upperlimit then the class expand the arrays. We can't reduce but we can change with a fresh one, maybe a different type. We have Copy function, so we get all arrays in as a copy.

This is a part of an example in zip file. Normally we can't handle String() arrays or Long() arrays, using collections. So the refArray can be used for these situations. As you see we can define items, and arrays. 




```
Dim c As New Collection, i As Long
c.Add New RefArray, "One"
c("One")(0) = "This is a string"
For i = 1 To 9
    c("One")(i) = i ^ 2
Next i
c("One")(10) = "Hello There"


c("One").DefArrayAt 11, vbByte, 1000
Debug.Print TypeName(c("One")(11)) = "Byte()"
c("One").DefArrayAt 13, vbString, 1000
Debug.Print TypeName(c("One")(13)) = "String()"
```


The second class, is the HashList which use the refArray, to make lists with keys (string or numbers), of type string, variant, byte, integer, long, currency (for decimal use variant). So there is one class for some different types. The new approach here is the use of byte size for hashcode for under 150 items, then if we add more the class change the hashcode to integer size, and after 21500 items change to long size. Also we can copy the structure (keys, data, and hash data) with one statement, creating a new list. You can change in refArray the way you have to copy special objects.


We can use same keys, and we can iterate through all items. Here we use numbers for keys, so we want to iterate like a sparse array. But we have same keys, so there is a way to find all items with same keys. And this example show this.

The Find() method can work for key only (we may have string and number keys), or we can use one or more of three optional, the value, the position, the pointer to other (which have the same hash code, but is rare except for same keys).
Also we can prepare the list before the use to have plenty of space, to avoid auto rehash, if we know about the size we have to use.

There is no sort, or delete for items (we can use clear, and then we can change the type of the  item of the list). There is a Create function which create lists like this: Set list1 = list1.create("Hello", 1000, "bravo")  for variant type.




```
Dim list1 As New HashList, there, i As Long, j As LongDim list2 As New HashList
' list1.Prepare 20 ' optional
For i = 1 To 20
list1.Add "George", 10&
list1.Add "John 5", 5&
list1.Add "George 2", 10&
list1.Add "John 125", 125&
Next
Dim lookother
For i = 1 To 150
    lookother = Empty
    
    Do
    If list1.Find(i, , there, lookother) Then
       
        If lookother > 0 Or list2.Count Then
            list2.Add list1(there), there
        Else
            Debug.Print "Key: " & i
            Debug.Print "Found at pos: " & there
            Debug.Print "Data: " & list1(there)
        End If
        list1(there) = list1(there) + "!!!"
    End If
    Loop Until lookother = 0
    If list2.Count > 0 Then
        For j = list2.Count - 1 To 0 Step -1
            Debug.Print "Key: " & i
            Debug.Print "Found at pos: " & list2.KeyNumeric(list2.Key(j))
            Debug.Print "Data: " & list2(j)
        Next j
        list2.Clear
    End If
Next i
Exit Sub
For i = 0 To list1.Count - 1
    Debug.Print list1.KeyNumeric(list1.Key(i)) & ": " & list1(i), i
Next i
End Sub
```

That's all for now.

----------


## georgekar

The RefArray now used in M2000 Interpreter (a new version)
https://github.com/M2000Interpreter/...n/RefArray.cls

I have another class for arrays, the mArray which used for using dimensions on a flat array (one dimension), from the Interpreter and when I did some changes now the mArray has a variant ActualData which can be either a Variant() or a class RefArray and the VB6 when see that ActualData(index) take account automatic what to call depend on if it is an object (RefArray using the default property Value) or  it is the variant type.

This is M2000 code colorized by internal editor, and export color as html text when we copy to clipboard.


```
// M2000 Interpreter version 12 revision 3
// here mArray has a RefArray object in actualData
// so for each item we have 8 bytes (Long Long)
Dim A(1 to 10, 5 to 20)as Long Long
A(1,5)=1234565789012345678&&
A(1,5)++
? A(1,5)=1234565789012345679&&
? Type$(A(1,5))="Long Long"
k=A()// take a pointer
? Type$(k)="mArray" // it is a class mArray, the refArray is hidden
// here mArray has a Variant() in actualData
// so for each item we have 16 bytes
Dim B(-5 to 5, 1 to 10)
B(1,5)=1234565789012345678&&
B(1,5)++
? B(1,5)=1234565789012345679&&
? Type$(B(1,5))="Long Long"
k=B()// take a pointer
? Type$(k)="mArray" // it is a class mArray

// RefArray as array can hold two dimensions max
// but with a differnece
// we can expand from 1 to 2 dimension
// we can expand any "sub array" with different length
// C is a pointer to a RefArray
Long Long C[0]
? Type$(C)="RefArray", Len(C)=1
C[1][9]=1000&&
? Len(C[0])=1
? Len(C[1])=10
C[2][4]=0xFFFF_FFFFF&&
? Len(C[2])=5
? Len(C)=3
// this is a copy
L=C[]
// we didn't have ++ (operators work for mArray, yet, maybe for other revisions I fix this)
C[2][4]=C[2][4]+1
For i=0 to len(L)-1
? i, Len(L[i])// return sizes 1 10 5
next
? L[2][4]=C[2][4]-1&&  // true
```

----------

