Using the SDK from Visual Basic

This section provides a few simple examples that demonstrate how to use the StarTeam APIs from Microsoft Visual Basic.

Note that to use the StarTeam COM interfaces from Visual Basic, you must load the StarTeam type library into your Visual Basic project. In Visual Basic 6.0, on the Project menu, choose the References command. In the References dialog box click the Browse button, and find the file StarTeamSDK.dll. It should be located in the lib subfolder of the StarTeam SDK installation folder.

Getting Started

The following example shows how to create a Server object, and establish a connection to a StarTeam Server, using Visual Basic.

' Sample code showing how to connect to a 
' StarTeam Server using Microsoft Visual Basic. 
Dim strAddress As String 
Dim nPort As Long 
Dim strUser As String 
Dim strPassword As String 
 
strAddress = "localhost" 
nPort = 49201 
strUser = "SampleUser" 
strPassword = "MyPassword" 
 
' Create a new StarTeam Server Factory. 
Dim Factory As New StServerFactory 
 
' Use factory to create a new initialized Server object. 
Dim Server As StServer 
Set Server = Factory.Create(strAddress, nPort) 
 
' Establish a connection to the Server. 
' This is optional - logOn() connects if necessary. 
Server.connect 
 
' LogOn as a specific user. 
Server.logOn strUser, strPassword 
 
' Use the Server object to enumerate 
' Projects and Views, etc. 
' . . . 
 
' Disconnect when finished. 
Server.disconnect 

In the StarTeam COM APIs (including both the C-style interfaces and the Automation interfaces), the various object types do not have constructors in the same sense that they do in the Java APIs. Instead, there are factory objects that are used to create initialized instances of the base object.

For example, to create a Server object, we must first instantiate a new server factory, as follows:

Dim Factory As New StServerFactory

Note that when using the COM interfaces, the names of the StarTeam object types all have the "St" prefix (for example, StServerFactory for the server factory, StServer for the server object, and so on).

Next, we can use the Create() method of the StServerFactory object to create a properly initialized Server object, as follows:

Dim Server As StServer
Set Server = Factory.Create(strAddress, nPort)

Just as the Server object had multiple constructors in the Java APIs, the StServerFactory object has multiple Create methods. The CreateEx() method can be used to create a StServer object using a specific encryption algorithm and compression level.

Collections and Enumeration

The following example shows how to enumerate the projects that are available on a given server, searching for the project with a given name.

' Enumerates the projects available on the given  
' server, looking for the one with the given name. 
Public Function FindProject( _ 
            Server As StServer, _ 
            strName As String) As StProject 
 
    Set FindProject = Null 
    For Each P In Server.Projects 
        If P.Name = strName Then 
            Set FindProject = P 
            Exit For 
        End If 
    Next 
     
End Function 

The StarTeam APIs use the standard COM representation for collections. Visual Basic provides built-in support for iterating over the members of such a collection, using the For Each ... Next statement. So, to iterate over the members of the Projects collection, we use the following:

For Each P In Server.Projects
     . . . 
Next

The enclosed loop is executed once for each project in the collection, with the object variable P bound to successive members of the collection.

Also, note that in Visual Basic (as well as most other automation-aware scripting environments), the properties of an object are referenced using the property name. Thus, Server.Projects is used to retrieve the value of the Projects collection (whereas in Java, we used the Server.getProjects() method).


Back      Home     Next