HOWTO: Tips for Using Visual Basic 3.0 with SourceSafe

Last reviewed: May 23, 1997
Article ID: Q131453
The information in this article applies to:
  • Microsoft SourceSafe for Windows, version 3.1
  • Microsoft SourceSafe for Windows NT, version 3.1
  • Microsoft Visual Basic, version 3.0

SUMMARY

SourceSafe can be used to store Visual Basic source files. The following tips can make this process easier.

MORE INFORMATION

Moving Between Visual Basic and SourceSafe

When first adding a project to SourceSafe, it is important to set the working directory (CTRL-D) where you want to store files that you are working with. While this could be the directory that Visual Basic is in, this is not recommended. For maintenance reasons, you should store a Visual Basic project in its own directory.

Typically, SourceSafe is only used when you check out and update files, so it is generally used only two or three times a day. As a result, the most common configuration is to have Visual Basic up, and leave SourceSafe minimized in the corner. When you need to check out or update a file, double-click SourceSafe, and make the necessary changes. Then you minimize SourceSafe, and you're back in Visual Basic, immediately ready to return to work.

Visual Basic Projects and SourceSafe Projects

For each Visual Basic project you have, create a SourceSafe project. Add to that SourceSafe project all the .FRM, .FRX, .BAS, and .TXT files, as well as the .MAK file. Bitmaps, icons, and metafiles embedded in either the picture or icon properties of a Visual Basic form or control are stored in the .FRX file. However, any icon or bitmap files referenced by the Visual Basic project and not part of a form, picture control, or image control should be added as well.

Also, be sure to save the Visual Basic forms and modules as text. By saving as text, you can take full advantage of the diff and merge capabilities of SourceSafe. By default, Visual Basic saves forms and modules in binary format. You can update existing forms and modules by choosing Save File As from the File Menu, and then selecting the Save as Text check box.

You can configure Visual Basic so that it always saves forms and modules as text. From the Options menu, choose Environment. Then in the list box that comes up, change the "Default Save as Format" to indicate "Text." Then all new forms and modules will be saved as text.

It is probably best not to add .VBX files to the SourceSafe project because the .VBX files are usually stored in the Windows' System directory. The best way to store .VBX files in SourceSafe is to create a separate project that stores all the .VBX files you use.

Checking Out Files

The SourceSafe system is built on the assumption that you always check out a file before making changes to it. This can take a while to get used to if you have never used version control, but it is vitally important that you always do so.

To help you remember, SourceSafe flags files read-only when you do not have them checked out. Visual Basic signals this by putting a little red padlock symbol in the lower-left corner of the form icon file whenever the form file is read-only, so glance down before making changes to be sure the file can be changed.

However, Visual Basic does not indicate if the .MAK file has been checked out with any visual clue that is visible within Visual Basic. To be sure, you can switch to SourceSafe, and see if the file is checked out. Visual Basic stores a lot of information about the state of a project and its contents in the .MAK file, so it is probably safest to assume that if you check out any one file in your Visual Basic project, you should check out the .MAK file as well.

In addition, if you have any graphics embedded in your form, such as a bitmap, metafile, or icon, you need to check out the file with the .FRX extension for that form, or you won't be able to make any changes to the graphics used on that form.

If you do forget to check out a file and you make a lot of changes, you will find out the hard way when you try to save. When you see the error "XXX.FRM is a read-only file," proceed with caution. You can check out the file now and save your changes, but if another programmer has changed the file since you last got it from SourceSafe, you will wipe out his changes, which defeats the purpose of SourceSafe. So before you check out, use the Diff command to see if your (pre-saved) file is the latest in SourceSafe. If there are no differences between your local copy and the latest SourceSafe version, simply check out the file and save your changes. If there are differences, you need to reconcile the differences between your local copy and the latest version in SourceSafe.

Using Diff with Form Files

SourceSafe's ability to store disk-efficient changes works with any file, but its ability to report line-by-line changes to the user or to merge disparate sets of changes works only on text files. Therefore, if you save your form files as text and understand the format that Visual Basic uses, you can take better advantage of SourceSafe's full capabilities.

The following example should help you understand the text form file format. This file describes a form with a single textbox on it:

      Begin Form Form1
         Caption         =   "Form1"
         ClientHeight    =   4020
         ClientLeft      =   1080
         ClientTop       =   1545
         ClientWidth     =   7365
         Height          =   4425
         Left            =   1020
         LinkTopic       =   "Form1"
         ScaleHeight     =   4020
         ScaleWidth      =   7365
         Top             =   1200
         Width           =   7485
         Begin TextBox Text1
            Height          =   495
            Left            =   3120
            TabIndex        =   0
            Text            =   "Text1"
            Top             =   1800
            Width           =   1215
         End
      End

Note that the text box's properties are specified between the Begin TextBox Text1 section and End. If you change the Text property of the text box, SourceSafe will output a line like this:

      19 Change:   Text = "Text1"
      To:          Text = "Hello"

To determine which object is associated with the modified property, you need to find the Begin <object> statement immediately prior to line 19. Note that the Visual Diff feature of SourceSafe version 3.0 provides an easy way to do this, as you can simply scroll backwards from the changed property until you see the Begin <object> statement.

Sharing Common Files

If you have a set of .BAS files that are used in more than one project, use SourceSafe's Share command to share the files in each of the projects they are used in. Then, any time enhancements or bug fixes are made to these files the changes propagate automatically to all the projects that share them. You can use the Links command to get a list of all the projects that share a .BAS file, which can be useful in determining which programs need to be recompiled after a change.

Merging Visual Basic Files

The Merge command works only on text files and it expects the source files to be in relatively the same format. For example, if procedures are located randomly throughout the file or if the position for many of the existing procedures changes dramatically, SourceSafe may not be able to adequately determine if the procedure is the same between the two files because it can't locate the procedure between the different versions of the file. This may result in SourceSafe seeing the whole procedure as different even though it may not have changed. Visual Basic writes out procedures in a random formation to the .FRM and .BAS files, so the SourceSafe Merge command may not work as expected on these file types.

An alternative is to get the desired versions to two different locations and merge the file manually.


Keywords : kbusage SourceSafe ssvb vbwin vss kbusage
Version : 3.10 4.00
Platform : NT WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 23, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.