GetNumServers method

The number of servers available for logon is returned in the specified variable.

Method:
short GetNumServers(
VARIANT * pNumServers )
Parameters
pNumServers
Points to a variable to receive the number of servers available for logon. On return, this variable is set to type VT_I2.
Description
This value can be used with the GetServerNames method to prepare for a logon.
Return Value
Refer to return codes.
See Also
GetServerNames and Logon methods

C/C + +

The following example retrieves the names of all servers available for logon, puts them in a ComboBox control, retrieves the chosen server, user ID, and password, and performs a logon.
 CArsOle * pArsCtrl;
 ArsOleName * pServerNames;
 CComboBox * pServersList;
 CEdit * pUserId;
 CEdit * pPassword;
 char server[ sizeof( ArsOleName ) ];
 char user[ sizeof( ArsOleName ) ];
 char password[ sizeof( ArsOleName ) ];
 short rc, j, num_servers;
 int index;
 VARIANT vari;
   .
   .
 // During dialog initialization:

 rc = pArsCtrl->GetNumServers( &vari );
 if ( rc != ARS_OLE_RC_SUCCESS )
   ERROR;
 num_servers = var.iVal;

 pServerNames = new ArsOleName[ max( num_servers, 1 ) ];
 rc = pArsCtrl->GetServerNames( (IUnknown*)pServerNames, num_servers );
 if ( rc != ARS_OLE_RC_SUCCESS )
   ERROR;

 for ( j = 0; j < num_servers; j++ )
   index = pServersList->AddString( pServerNames[j] );
 pServersList->SetCurSel( 0 );
   .
   .
  // During OK button processing:

  pServersList->GetWindowText( server, sizeof(server) );
  pUserId->GetWindowText( user, sizeof(user) );
  pPassword->GetWindowText( password, sizeof(password) );

  rc = pArsCtrl->Logon( server, user, password );
  if ( rc != ARS_OLE_RC_SUCCESS )
    ERROR;
   .
   .

Visual Basic

Dim rc, count As Integer
Dim num_servers As Variant
Dim Temp As String

 .
 .

rc = ArsOle.GetNumServers (num_servers)
If rc <> ARS_OLE_RC_SUCCESS Then
    MsgBox "ERROR"
    End
End If

For count = 0 To num_servers -1
    rc = ArsOle.GetServerName(count, Temp)
    lbServers.AddItem Temp
Next count

 .
 .

' During OK button processing

rc = ArsOle.Logon (lbServers.List(lbServers.ListItem), txtUser.Value, txtPasswd.Value)
If rc <> ARS_OLE_RC_SUCCESS Then
    MsgBox "ERROR"
    End
End If