Methods in the ComsolUtil Class
Additionally to the COMSOL API, LiveLink™ for Excel® provides its own object ComsolUtil, which contains the methods to handle operation between the COMSOL server and Excel.
To make all COMSOL utility methods available using VBA, enter:
Set ComsolUtil = CreateObject("comsolcom.comsolutil")
ConvertToDoubleMatrix
ConvertToDoubleMatrix(obj, transpose As Boolean) As Double() converts the incoming object to an array of doubles in COMSOL API format.
The input object obj is either a scalar or an array, with the type string, integer (long or short) or double. The returned array will have the start index as zero, as it is requested in the COMSOL API.
If the boolean transpose is true then the input array is transposed before the output is created.
Code for use in VBA
Sub Convert2DoubleMatrixExample()
 
' Fill in data
Range("A1").Value = x
Range("B1").Value = y
Range("C1").Value = Z
Range("A2:C10").Value = 0
Range("A3").Value = 0.025
Range("A4").Value = 0.05
Range("B5").Value = -0.0125
Range("B8").Value = -0.025
Range("A5:A7").Value = Range("A2:A4").Value
Range("A8:A10").Value = Range("A2:A4").Value
Range("B6:B7").Value = Range("B5").Value
Range("B9:B10").Value = Range("B8").Value
' Reformat the data collected in the worksheet in a usable way for
' the COMSOL model
Dim coords() As Double
ReDim coords(0 To 2, 0 To 8)
Set ComsolUtil = CreateObject("comsolcom.comsolutil")
coords = ComsolUtil.ConvertToDoubleMatrix(Range("A2:C10").Value, True)
Range("E2:M4").Value = coords
 
End Sub
ConvertToDoubleMatrixDecimal
ConvertToDoubleMatrixDecimal(obj, transpose As Boolean, dec As String) As Double() converts the incoming object to an array of doubles in COMSOL API format.
The input object obj is either a scalar or an array, with the type string, integer (long or short) or double. The returned array will have the start index as zero, as it is requested in the COMSOL API.
If the boolean transpose is set to true then the input array is transposed before the output is created.
dec is a string that defines the decimal sign definition (usually "," or "."). Decimal sign definition is important to specify when converting strings to values.
ConvertToDoubleVector
ConvertToDoubleVector(obj) As Double() converts the incoming object to a vector of doubles.
The input object obj may be a scalar or a vector. The input may be of the type string, integer (long or short) or double. The returned vector will have the start index as zero, which makes it possible to send such vectors to COMSOL when vectors have to be supplied as an argument to a method in the COMSOL API.
get_errormessage
get_errormessage() As String returns error message.
This returns any error message that was created by StartComsolServer() or other methods in ComsolUtil.
get_port
get_port() As Integer returns the port number of the COMSOL Multiphysics server.
To return the port number the Multiphysics server has to be started StartComsolServer() in the same module.
get_Version
get_Version() As String returns the version of the ComsolCom interface.
The version of the ComsolCom interface does not include the build number as it is for the COMSOL version. The current ComsolCom version number is "6.4.0.0".
GetRibbonUtil
GetRibbonUtil() As IRibbonUtil returns the IRibbonUtil object to enable COMSOL ribbon utilities.
isGraphicsServer
isGraphicsServer() As Boolean returns if the COMSOL Multiphysics server is started as a graphics server.
The method isGraphicsServer requires an established connection to a COMSOL server.
StartComsolServer
StartComsolServer(usegraphics As Boolean) As Boolean starts a COMSOL Multiphysics server. The boolean usegraphics is true to start the graphics server.
The method StartComsolServer returns a boolean that indicates if the COMSOL server has started successfully or not, the value of the boolean being true or false respectively.
TimeOuthandler
TimeOuthandler(on As Boolean) applies a timeout handler to Excel.
Set on to True to apply a timeout handler to Excel in order to prevent any timeout when performing long running tasks (such as starting a server or solving large models).