bobetko
bobetko

Reputation: 5168

VBS - how to pass object to function as parameter

I am working on little script and made wrong decision to do it in VBS.

...
result = FindAndUpdate(objDictionary, id)
...
Function FindAndUpdate(objDictionary, id)
    MsgBox(objDictionary.Count)
    FindAndUpdate = true
End Function

Now I am struggling with things that doesn't make any sense. I am passing Dictionary object to function. In function MsgBox(objDictionary.count) executes and I get number 15 in alert box, but immediately error gets reported on the same line Object Required: 'objDictionary'

Any help is appreciated

Upvotes: 1

Views: 3713

Answers (1)

Nathan Rice
Nathan Rice

Reputation: 3111

You might add a check for the objDictionary and exit your function if it doesn't exist:

Function FindAndUpdate(objDictionary, id)
  If Not IsObject(objDictionary) Then
    FindAndUpdate = false
    Exit Function
  End If

  MsgBox(objDictionary.Count)
  FindAndUpdate = true
End Function

Upvotes: 2

Related Questions