The following example uses the Form object in Visual Basic.

Option Explicit

'This will need to be changed for your organization.
'The serial number can be found from Tools, Help About the Raiser's Edge.
Private Const SERIAL_NUMBER = "WRE1111"
        
'50 is the number for the standard sample database.
Private Const DATABASE_NUMBER = 50

'Command Button constants
Private Const CMD_CONNECT = 0
Private Const CMD_DISCONNECT = 1

'Option Button constants
Private Const OPT_USERE7LOGIN = 0
Private Const OPT_USESUPERVISORLOGIN = 1
Private Const OPT_LOGINTHEHARDWAY = 2

''Global' variables, ideally these would be in a code module elsewhere,
'but are declared here for the sake of simplicity in this sample.
Public goREAPI As REAPI

Private Sub cmdConnect_Click(Index As Integer)
    
    Dim bLoginOK As Boolean
    
    Select Case Index
    
        Case CMD_CONNECT
            bLoginOK = False
            Set goREAPI = Nothing  '< Clear any current connections
            
            If optLogin(OPT_USERE7LOGIN).Value = True Then
                'This shows the RE7 login form.  If you have more then one RE7 database, this
                'method will prompt you for the database first, then the username and password
                bLoginOK = REAPI.Init(SERIAL_NUMBER)
            
            ElseIf optLogin(OPT_USESUPERVISORLOGIN).Value = True Then
                'This will log into the sample database with no user prompts.  You'll want to
                'be careful with this method since you are exposing your password to anyone who
                'can access your code.
                bLoginOK = REAPI.Init(SERIAL_NUMBER, "Supervisor", "ADMIN", DATABASE_NUMBER)
                            
            ElseIf optLogin(OPT_LOGINTHEHARDWAY).Value = True Then
                'This will ask the user for their system, user name and password.  You'll want to
                'Enter '50' to the first prompt,
                ''Supervisor' to the second, and
                ''Admin' to the third to login to the sample database as the supervisor.
            
                Dim sUserName As String
                Dim sPassword As String
                Dim lDatabaseNumber As Long
        
                lDatabaseNumber = Val(InputBox("Enter Database Number:", "Logging in the hard way"))
                
                sUserName = InputBox("Enter User Name:", "Logging in the hard way")
                sPassword = InputBox("Enter Password:", "Logging in the hard way")
                
                If lDatabaseNumber >= 0 And Len(sUserName) > 0 And Len(sPassword) > 0 Then
                    bLoginOK = REAPI.Init(SERIAL_NUMBER, sUserName, sPassword, lDatabaseNumber)
                Else
                    bLoginOK = False
                End If
            
            End If
            
            If bLoginOK Then
                MsgBox "Login successful!"
                Me.Caption = "Currently logged in as " & REAPI.SessionContext.CurrentUserID
            Else
                MsgBox "Login failed for this reason: " & REAPI.LastErrorMessage
                Me.Caption = "<not logged in>"
            End If
                    
        Case CMD_DISCONNECT
            'Since we set the .SignOutOnTerminate property to True, the user will be signed out of the system.
            Set goREAPI = Nothing
            Me.Caption = "<not logged in>"
        
    End Select

End Sub

Private Sub Form_Load()

    Me.Caption = "<not logged in>"

End Sub

Private Function REAPI() As REAPI
    If goREAPI Is Nothing Then
        'Create a new instance of the API object.  You'll want to do this only once.
        Set goREAPI = New REAPI
        goREAPI.SignOutOnTerminate = True
    End If
    Set REAPI = goREAPI
End Function


Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Microsoft Visual Basic and the tools used to create and debug procedures. Our Customer Support can help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality. If you are interested in learning more about the VBA and API modules, contact your account manager.