I was searching an hashtable implementation for XL 2K VBA and found yours. I copy/pasted your code inside an Type object declaration but I did not even achieve to compile it. How should it be used ? Sorry, I'm newbie to XL VBA
You need to copy the code into a VBA class. From the command bar, choose to insert a class object into your Visual Basic project. Then, double click on the empty class in your project and paste the code from this tutorial into your project (it is easiest if you use the download code option from the menu).
Hi, I understood than Is I should implement in a Class Module of VBA but I don't understand what I've to do and what I can expect with this code. Somebody could provide an exemple, please ?
I am interested in incorporating the class into an Excel project. In the article, you state that "[you] intend to illustrate how a hashtable works by using an class in VBA code that I found a long time ago on the Internet." However, you did not specify under which license it is released.
I have never been able to find the code again and am unsure as to what licensing terms apply to it. There was no license terms or attribution attached, otherwise I would have included them with the snippet.
I have a new VB.NET code using HashTable: Public Function XlsReadRange(ByVal iRowS As Integer, _ ByVal iColS As Integer, _ ByVal iColE As Integer, _ ByRef htRead() As Hashtable) As XLS_RESULT Dim iRow As Integer Dim iCol As Integer
Try
htRead = Nothing
Do 'Get Range oRange = oSheet.Range(Me.GetXlsRange(iColS) & CStr(iRowS) & ":" & _ Me.GetXlsRange(iColE) & CStr(iRowS))
'Hashtable definition ReDim Preserve htRead(iRow) htRead(iRow) = New Hashtable()
'Get data for every Row and Col For iCol = 1 To iColE - iColS + 1 'Get data htRead(iRow).Add(iCol, TOStr(oRange.Value(1, iCol))) Next
iRowS += 1
'Hashtable No iRow += 1
'Release Object MRComObject(oRange) Loop
Return XLS_RESULT.XLS_OK Catch ex As Exception Me.XlsFileRelease() Return XLS_RESULT.XLS_NG End Try End Function
Can I use your HashTable class to write the replacement code in VB6? In the belows, I use your class to hold the excel cells data. Public Function XlsReadRange(ByVal iRowS As Integer, _ ByVal iColS As Integer, _ ByVal iColE As Integer, _ ByRef htRead() As cHashTable) As XLS_RESULT Dim iRow As Integer Dim iCol As Integer
'Set htRead = Nothing 'ignore error?
Do 'Range Set oRange = oSheet.Range(Me.GetXlsRange(iColS) & CStr(iRowS) & ":" & _ Me.GetXlsRange(iColE) & CStr(iRowS))
'Hashtable ReDim Preserve htRead(iRow) htRead(iRow) = New cHashTable
' For iCol = 1 To iColE - iColS + 1 Get data Call htRead(iRow).Add(iCol, TOStr(oRange.value(1, iCol))) Next
' iRowS = iRowS + 1
'Hashtable No iRow = iRow + 1
'Release Object If Not oRange Is Nothing Then Set oRange = Nothing Loop
I copy/pasted your code inside an Type object declaration but I did not even achieve to compile it.
How should it be used ? Sorry, I'm newbie to XL VBA
Somebody could provide an exemple, please ?
It looks like they are cool with non-commercial use.
d00d
Very neat. Well done!
I put it in a Class module too, but I don't know how to use the hashtable.
Thank
Public Function XlsReadRange(ByVal iRowS As Integer, _
ByVal iColS As Integer, _
ByVal iColE As Integer, _
ByRef htRead() As Hashtable) As XLS_RESULT
Dim iRow As Integer
Dim iCol As Integer
Try
htRead = Nothing
Do
'Get Range
oRange = oSheet.Range(Me.GetXlsRange(iColS) & CStr(iRowS) & ":" & _
Me.GetXlsRange(iColE) & CStr(iRowS))
'Hashtable definition
ReDim Preserve htRead(iRow)
htRead(iRow) = New Hashtable()
'Get data for every Row and Col
For iCol = 1 To iColE - iColS + 1
'Get data
htRead(iRow).Add(iCol, TOStr(oRange.Value(1, iCol)))
Next
iRowS += 1
'Hashtable No
iRow += 1
'Release Object
MRComObject(oRange)
Loop
Return XLS_RESULT.XLS_OK
Catch ex As Exception
Me.XlsFileRelease()
Return XLS_RESULT.XLS_NG
End Try
End Function
Can I use your HashTable class to write the replacement code in VB6? In the belows, I use your class to hold the excel cells data.
Public Function XlsReadRange(ByVal iRowS As Integer, _
ByVal iColS As Integer, _
ByVal iColE As Integer, _
ByRef htRead() As cHashTable) As XLS_RESULT
Dim iRow As Integer
Dim iCol As Integer
'Set htRead = Nothing 'ignore error?
Do
'Range
Set oRange = oSheet.Range(Me.GetXlsRange(iColS) & CStr(iRowS) & ":" & _
Me.GetXlsRange(iColE) & CStr(iRowS))
'Hashtable
ReDim Preserve htRead(iRow)
htRead(iRow) = New cHashTable
'
For iCol = 1 To iColE - iColS + 1
Get data
Call htRead(iRow).Add(iCol, TOStr(oRange.value(1, iCol)))
Next
'
iRowS = iRowS + 1
'Hashtable No
iRow = iRow + 1
'Release Object
If Not oRange Is Nothing Then Set oRange = Nothing
Loop
XlsReadRange = XLS_RESULT.XLS_OK
Exit Function
ErrH:
Call XlsFileRelease
XlsReadRange = XLS_RESULT.XLS_NG
End Functio