This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Store character array in Automation server


IDL Method Signature

PutCharArray([in] BSTR varname, [in] BSTR workspace, 
    [in] BSTR string)

Microsoft Visual Basic Client

PutCharArray(varname As String, workspace As String, 
    string As String)




PutCharArray(h,'varname','workspace','string') stores the character array in string in the specified workspace of the server attached to handle h, assigning to it the variable varname. The values for workspace are base or global. The function name is case-sensitive.

Visual Basic .NET Examples

This example uses the Visual Basic® MsgBox command to control flow between MATLAB® and the Visual Basic Client. To run examples in products that execute VBA code, see Tips.

Dim Matlab As Object
    Matlab = GetObject(, "matlab.application")
Catch e As Exception
    Matlab = CreateObject("matlab.application")
End Try
MsgBox("MATLAB window created; now open it...")
Matlab.PutCharArray("str", "base", _
  "He jests at scars that never felt a wound.")
MsgBox("In MATLAB, type" & vbCrLf _
  & "str")
MsgBox("closing MATLAB window...")

Open the MATLAB window, click OK, and then type str. MATLAB displays:

str =
He jests at scars that never felt a wound.

Click OK to close and terminate MATLAB.


  • The character array specified in the string argument can have any dimensions. However, PutCharArray changes the dimensions to a 1-by-n column-wise representation, where n is the number of characters in the array. Executing the following commands in MATLAB illustrates this behavior:

    h = actxserver('matlab.application');
    chArr = ['abc'; 'def'; 'ghk']
    chArr =
    tstArr = GetCharArray(h,'Foo','base')
    tstArr =
  • To run examples in Microsoft® Office products that execute VBA code, replace the statement:

    MatLab = CreateObject("matlab.application")


    Set MatLab = CreateObject("matlab.application")

    If you need more information, then refer to your VBA product documentation.

Introduced before R2006a