I do Code - A Weblog by Finn Ladegaard Knudsen. About Code and things related to Code

Passing Arguments by Value and by Reference

Finn L. Knudsen  15 November 2008 10:00:00
When you are calling an external function:
C-API function or OLE objects

Be aware of how the value is passed.

Example with wrong passing of value:

Dim vWinHTTP As Variant

Set vWinHTTP = CreateObject("WinHTTP.WinHTTPRequest.5.1")

Dim sSoapEnvelope As String

sSoapEnvelope = |<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"         xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<SOAP-ENV:Body>
<m:SAYHELLO xmlns:m="urn:DefaultNamespace"         SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<NAME xsi:type="xsd:string">Finn Knudsen</NAME>
</m:SAYHELLO>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>|

Call vWinHTTP.Open( "POST", "http://idocode.net/ws/helloworld", False )

Call vWinHTTP.Send( sSoapEnvelope ) ' Don't do like this. Passing by reference .

The last line should be:

Call vWinHTTP.Send( (sSoapEnvelope) ) ' Passing by value


In the example you don't get an error when you call .Send with the value passed as reference, but the reply from the server won't be what you expected.

From MSDN documentation of WinHTTPRequest:
Sub Send( _
[ ByVal varBody As VARIANT ] _
)


See more on:

Lotus Domino Designer Help: "Passing arguments by reference and by value "

http://msdn.microsoft.com/en-us/library/ddck1z30.aspx

http://www.ls2capi.com/web/ls2capi/ls2capihome.nsf/Content/SC_DATA_TYPES?OpenDocument&ExpandOutline=1.2
Technorati Profile Add to Technorati Favorites