I tried this approach. It works fine.
If this is what you are looking for,
Dim oXMLHTTP
Dim vConn
Set oXMLHTTP = CreateObject("Scripting.dictionary")
Set vConn = CreateObject("Scripting.dictionary")
SetToNothing (Array("oXMLHTTP","vConn")) --> Pass the variable names as
String.
msgbox TypeName(oXMLHTTP) --> oXMLHTTP has been nullified.
'''This Still showing the value of oXMLHTTP as "abc" which should not be
Function SetToNothing( parameters())
Dim i
On Error Resume Next
SetToNothing = True
For i = LBound(parameters) To UBound(parameters)
Execute "Set " & parameters(i) & "= Nothing " -->
Passed variables are set to Nothing.
If Err.Number <> 0 Then SetToNothing = False 'if not object/variant
variable
Next
End Function
On Friday, January 11, 2013 10:15:07 AM UTC-6, vins wrote:
>
> Hi,
> I understand what you are trying to do.
>
> Hope this example might clear the behavior.
>
> Set A = CreateObject('Scripting.dictionary")
> Set B = A 'Now B & A are holding a reference of a dictionary object
> (As you have copied to an Array)
> Set B = Nothing 'B is destroyed.
>
> Msgbox TypeName(A) ' It will show Dictionary
>
> thats what happening in your code as well.
> It means,
>
> After Set B = A both A & B holds the reference for the same object. If
> one is set to Nothing, It does not mean that other will be simply destroyed.
>
>
> In your code, oXMLHTTP is simply copied to an Array. Only that is set to
> Nothing.
> oXMLHTTP is holding the reference for the object.
>
>
>
>
>
>
> On Friday, January 11, 2013 6:57:20 AM UTC-6, arihan sinha wrote:
>>
>> Hi all,
>>
>> Just quick question. In a sub/function I've few parameters which I need
>> to *set to Nothing* at the end of the function. I don't want to write
>> like set myvar = Nothing for 10/20 times..
>>
>> I tried the below code but the constrain is vbscript doesn't support the
>> param array . So the below code doesn't work. Any thoughts
>>
>> Dim oXMLHTTP
>>
>> Dim vConn
>>
>> oXMLHTTP = "abc"
>>
>> vConn = "xyz"
>>
>> SetToNothing (Array(oXMLHTTP,vConn))
>>
>> msgbox oXMLHTTP
>>
>> '''This Still showing the value of oXMLHTTP as "abc" which should not be
>>
>> Function SetToNothing( parameters())
>> Dim i
>> On Error Resume Next
>> SetToNothing = True
>> For i = LBound(parameters) To UBound(parameters)
>>
>> Set parameters(i) = Nothing
>> If Err.Number <> 0 Then SetToNothing = False 'if not
>> object/variant variable
>> Next
>> End Function
>>
>>
>> Cheers
>> A
>>
>>
>>
>>
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en