The following is an example VISA application using message-based communication.

C Example

#include "visa.h"
int main(void)
{

    ViSession    defaultRM, instr;
    ViUInt32     retCount;
    ViChar       idnResult[72];
    ViChar       resultBuffer[256];
    ViStatus     status;
    /* Open Default Resource Manager */
    status = viOpenDefaultRM(&defaultRM);
    if (status < VI_SUCCESS) {
        /* Error Initializing VISA...exiting */
        return -1;
    }
    /* Open communication with GPIB Device at Primary Addr 1 */
    /* NOTE: For simplicity, we will not show error checking */
    viOpen(defaultRM, "GPIB::1::INSTR", VI_NULL, VI_NULL, &instr);
    /* Initialize the timeout attribute to 10 s */
    viSetAttribute(instr, VI_ATTR_TMO_VALUE, 10000);
    /* Set termination character to carriage return (\r=0x0D) */
    viSetAttribute(instr, VI_ATTR_TERMCHAR, 0x0D);
    viSetAttribute(instr, VI_ATTR_TERMCHAR_EN, VI_TRUE);
    /* Don't assert END on the last byte */
    viSetAttribute(instr, VI_ATTR_SEND_END_EN, VI_FALSE);
    /* Clear the device */
    viClear(instr);
    /* Request the IEEE 488.2 identification information */
    viWrite(instr, "*IDN?\n", 6, &retCount);
    viRead(instr, idnResult, 72, &retCount);

    /* Use idnResult and retCount to parse device info */

    /* Trigger the device for an instrument reading */
    viAssertTrigger(instr, VI_TRIG_PROT_DEFAULT);
    /* Receive results */
    viRead(instr, resultBuffer, 256, &retCount);
    /* Close sessions */
    viClose(instr);
    viClose(defaultRM);
    return 0;
}

Visual Basic Example

Private Sub vbMain()

    Dim stat            As ViStatus 
      Dim dfltRM          As ViSession
      Dim sesn            As ViSession
      Dim retCount        As Long
      Dim idnResult       As String * 72
      Dim resultBuffer    As String * 256 
    Rem Open Default Resource Manager
    stat = viOpenDefaultRM(dfltRM)
    If (stat < VI_SUCCESS) Then
      Rem Error initializing VISA...exiting
      Exit Sub
    End If

    Rem Open communication with GPIB Device at Primary Addr 1
    Rem NOTE: For simplicity, we will not show error checking
    stat = viOpen(dfltRM, "GPIB::1::INSTR", VI_NULL, VI_NULL, sesn)

    Rem Initialize the timeout attribute to 10 s
    stat = viSetAttribute(sesn, VI_ATTR_TMO_VALUE, 10000)

    Rem Set termination character to carriage return (\r=0x0D) 
    stat = viSetAttribute(sesn, VI_ATTR_TERMCHAR, &H0D)
    stat = viSetAttribute(sesn, VI_ATTR_TERMCHAR_EN, VI_TRUE)

    Rem Don't assert END on the last byte
    stat = viSetAttribute(sesn, VI_ATTR_SEND_END_EN, VI_FALSE)

    Rem Clear the device
    stat = viClear(sesn)

    Rem Request the IEEE 488.2 identification information
    stat = viWrite(sesn, "*IDN?", 5, retCount)
    stat = viRead(sesn, idnResult, 72, retCount)

    Rem Your code should use idnResult and retCount to parse device info

    Rem Trigger the device for an instrument reading
    stat = viAssertTrigger(sesn, VI_TRIG_PROT_DEFAULT)

    Rem Receive results
    stat = viRead(sesn, resultBuffer, 256, retCount)

    Rem Close sessions
    stat = viClose (sesn)
    stat = viClose (dfltRM)

End Sub