XLPack API: VB.Net example programs
How to call XLPack from C#
To call XLPack from VB.Net, it is necessary to use DLL directly.
DLL interface program xlpack.vb is included in SDK, so that the calling program can easily call XLPack like built-in functions without considering the detail DLL interface by declaring “Imports XLPack”.
Two dimensional array is used for the coefficient matrix a. One dimensional array is used for the right hand matrix b.
Different from Excel VBA, two dimensional array of VB.Net is stored in row-major order like C/C++, and the 32 bit integer data type of VB.Net is “Integer” but not “Long”.
VB.Net example program (Example (1))
Imports XLPack
Class Test
Shared Sub TestDgesv
Const N = 3
Dim A(,) As Double = {
{ 0.2, -0.32, -0.8 },
{ -0.11, 0.81, -0.92 },
{ -0.93, 0.37, -0.29 } }
Dim B() As Double = { -0.3727, 0.4319, -1.4247 }
Dim IPiv(N - 1) As Integer
Dim Info As Integer
Call Dgesv(N, A, IPiv, B, Info)
Console.WriteLine("X = {0} {1} {2}", B(0), B(1), B(2))
Console.WriteLine("Info = {0}", Info)
End Sub
Public Shared Sub Main(ByVal args() As String)
Call TestDgesv
End Sub
End Class
Result
x = 0.86 0.64 0.51
info = 0
VB.Net example program (Example (2))
In Example (2), the integral of f(x) is computed using qk15. qk15 requires the external function defining f(x). It can be coded in VB.Net and qk15 will call it when necessary.
Imports XLPack
Class Test
Shared Function F(X As Double) As Double
F = 1/(1 + X ^ 2)
End Function
Shared Sub TestQk15
Dim A As Double, B As Double, Result As Double, AbsErr As Double
A = 0: B = 4
Call Qk15(AddressOf F, A, B, Result, AbsErr)
Console.WriteLine("Result = {0}, AbsErr = {1}", Result, AbsErr)
End Sub
Public Shared Sub Main(ByVal args() As String)
Call TestQk15
End Sub
End Class
Result
Result = 1.32581766136379, AbsErr = 0.00148272394121622