# XLPack 5 reverse communication versions

For the routines which require external functions, from the XLPack version 5, the reverse communication versions are newly supported in addition to the existing callback versions.

### 1. Existing (callback version) routines

For example, let’s compute the following integral.

```
∫ 1/(1 + x^2) dx [0, 4]

```

The typical progam using Qk15 is as follows:

``````Function F(X As Double) As Double
F = 1 / (1 + X ^ 2)
End Function

Sub Ex_Qk15()
Dim A As Double, B As Double, Result As Double
A = 0: B = 4
Call Qk15(AddressOf F, A, B, Result)
Debug.Print "S =", Result
End Sub``````

When the quadrature Qk15 needs an integrand value, it calls (back) the user supplied external routine F which compute the integrand value at the given point x. Qk15 returns the control to the caller program when the computation of the value of integral has been completed.

### 2. Reverse communication version

In contrast to the existing routine, if the reverse communication routine needs an integrand value, it returns to the caller routine with the value of point x and requests to reenter with the necessary function value at x. This procedure repeats until the final value of integral has been obtained.

The program for above example using reverse communication version is as follows:

``````Sub Ex_Qk15_r()
Dim A As Double, B As Double, Result As Double
Dim XX As Double, YY As Double, IRev As Long
A = 0: B = 4
IRev = 0
Do
Call Qk15_r(A, B, Result, XX, YY, IRev)
If IRev = 1 Then YY = 1 / (1 + XX ^ 2)
Loop While IRev <> 0
Debug.Print "S =", Result
End Sub``````

The name of reverse communication version routine is “name of callback version routine” + “_r”. For example, the reverse communication version of QK15 is Qk15_r.

IRev is the control variable for the reverse communivation. It should be initialized to 0 before calling the reverse communication routine. When the computation has been completed and the final result has been obtained, IRev=0 will be returned. When the additional information is necessary, IRev<>0 will be returned. In the latter case, the value of IRev and required action depends on the routine.

In the case of Qk15_r, XX and YY are the additional arguments for reverse communication. In the case of IRev=1, the function value at XX should be stored in YY and should call Qk15_r again.

### 3. Pros and cons of reverse communication version

The advantages of the reverse communication version are as follows:

• It will be safer because the AddressOf operator is not used. Since VBA cannot check the validity of the interface to the external routine when AddressOf operator is used, Excel can easily crash if there is an interface error.
• There may be more flexibility of programming. Since the arguments of user supplied external routine in the case of callback version are strictly defined, there may be some difficulty to pass some additional information.

On the other hand, the following disadvantage is considered.

• The calling sequence of the routine is more complicated than that for callback version. The program therefore may become complicated.

The same computation result will be obtained by the callback version and the reverse communication version. Please use the appropriate one depending on the conditions.
{"ft_lang_label":"__label__en","ft_lang_prob":0.848084,"math_prob":0.83408034,"size":3228,"snap":"2022-27-2022-33","text_gpt3_token_len":741,"char_repetition_ratio":0.17152606,"word_repetition_ratio":0.047445256,"special_character_ratio":0.22738537,"punctuation_ratio":0.10891089,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96069,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-20T05:18:09Z\",\"WARC-Record-ID\":\"<urn:uuid:4587414e-906e-4599-b610-5e21a08284e2>\",\"Content-Length\":\"40650\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d470319a-3808-4b87-8891-dde1193b0484>\",\"WARC-Concurrent-To\":\"<urn:uuid:20c390f0-2709-42a3-ae2f-de3ff6554fa8>\",\"WARC-IP-Address\":\"163.44.176.11\",\"WARC-Target-URI\":\"https://www.ktech.biz/manual/xlpack-5-revcom/\",\"WARC-Payload-Digest\":\"sha1:KF7BIVG2MCUNHVI34BIW46GNXUD75BX6\",\"WARC-Block-Digest\":\"sha1:K4EVTHGBDVUQDVZUENWRV4ZCGDYLBKJU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882573908.30_warc_CC-MAIN-20220820043108-20220820073108-00786.warc.gz\"}"}