cNISRbRscLink Examples


The following examples demonstrate how to use an instance of the cNISRbRscLink class to run a Remote Basic subroutine.

Visual Basic 6/Microsoft Office

Private Sub CallSUBR()
    Dim RB As NISRbDataLink.cNISRbRscLink
    Dim p1, p2 As String
     Dim ErrNo As Integer

     On Error Resume Next

     ' Create a Remote Basic object.
     Set RB = New NISRbDataLink.cNISRbRscLink
    Err.Clear
    With RB
        ' Set up the connection to the database.
        .System = "80db"
        .UserId = "SYSMAN"
        .Account = "SYSMAN"

        ' Connect to the database.
        .OpenLink

        ' Data to pass to the subroutine.
        p1 = "Data1"
        p2 = "Data2"

        ' If we are connected... 
            If .LinkOpen Then
                ' Call a DataBasic subroutine.
            .CallSubroutine "SUBR", 2, _
                p1, NISRbDataLink.RSCMode.ParamInOut, _
                p2, NISRbDataLink.RSCMode.ParamInOut
            ErrNo = Err.Number
            If ErrNo = 0 Then
                   ' Display the results.
                MsgBox p1 & " " & p2, vbInformation
            Else
                   ' If anything went wrong, tell the user.
		 If ErrNo < 0 Then ErrNo = ErrNo - vbObjectError
                Debug.Print "Err.Number=" & CStr(ErrNo) _
                    & " Err.Description=" & Err.Description
                MsgBox Err.Description, vbExclamation
            	 End If
            End If
        
           ' Close the link, ignoring errors (guaranteed successful,
        ' even if connection was not established).
        .CloseLink True
          End With

    Err.Clear
    On Error GoTo 0
 End Sub

Visual Basic .Net

Private Sub CallSUBR()
    Dim RB As NISRbDataLink.cNISRbRscLink = Nothing
    Dim p1 As String
    Dim p2 As String  


    Try  
        ' Create a Remote Basic object.
        RB = New NISRbDataLink.cNISRbRscLink
        With RB
            ' Set up the connection to the database.
            .System = "80db"
            .UserID = "SYSMAN"
            .Password = ""
            .Account = "SYSMAN"  

            ' Connect to the database.
            .OpenLink()

            ' Data to pass to the subroutine.
            p1 = "Data1"
            p2 = "Data2"

            ' If we are connected...
            If .LinkOpen Then
                ' Call a DataBasic subroutine.
                .CallSubroutine("SUBR", 2, _
                    p1, NISRbDataLink.RSCMode.ParamInOut, _
                    p2, NISRbDataLink.RSCMode.ParamInOut)
                ' Display the results.
                MsgBox(p1 + " " + p2, MsgBoxStyle.Information)
            End If
        End With

    Catch ec As Runtime.InteropServices.COMException
        ' If anything went wrong, tell the user.
        Debug.Print "Error number=" + Cstr(ec.ErrorCode - vbObjectError) _
            & " Error description=" & ec.Message
        MsgBox(ec.Message, MsgBoxStyle.Exclamation)

    Catch ex As Exception
        Debug.Print ex.Message
        MsgBox(ex.Message, MsgBoxStyle.Exclamation)

    Finally
            ' Close the link, ignoring errors (guaranteed successful,
        ' even if connection was not established).
        RB.CloseLink(True)
    End Try
End Sub

See Also

Remote Basic ActiveX Control
cNISRbRscLink Class
cNISRbRscLink Members
cNISRbRscLink Errors