Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Dictionary object from a Function

Status
Not open for further replies.

Kai77

Programmer
Jun 7, 2004
77
NL
I am trying to create a function which returns a dictionary object. But I am getting an error when adding key/items to it :

getColums.add(i,tempfields(i))

Isnt this how I should add them?



Public Function getColumns(strText As String) As Dictionary
Dim tempfields As Variant

'splitting the line into fields with "<column>" as the delimiter

tempfields = Split(strText, "<column>")

For i = 0 To UBound(tempfields)
getColums.add(i,tempfields(i))
Next i

End Function

 
Sorry I am a noob vb programmer. I was under the impression that once you defined the Function as an object, you did not need to do "create"/ dim it in the function.

So I need to add a line

Dim getColumns as Scripting.Dictionary

?

I did that and it still gave me an error
 
The error is supposedly a syntax error on the line

getColums.add(i,tempfields(i))

I have searched everywhere and it also works in ASP in this fashion.
 
Code:
Public Function getColumns(strText As String) As Dictionary
    Dim i As Long
    Dim tempfields As Variant
                
    Dim dummy As New Dictionary


    tempfields = Split(strText, "<column>")
    
    For i = 0 To UBound(tempfields)
      dummy.Add i, tempfields(i)
    Next i
    Set getColumns = dummy
End Function
Mind you, I think I'd be investigating DrJavaJoe's suggestion in your previous thread about using Regular expressions for this...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top