Writing Your Setup Program

See Also16WVDFO

You can quickly write your setup program by modifying the source code of the sample setup program, SETUP1.MAK, located in the \SETUPKIT\SETUP1 subdirectory of the main Visual Basic directory.  SETUP1.MAK installs the sample application LOAN.EXE, which is located in the \SAMPLES\GRID subdirectory of the main Visual Basic directory.

LOAN.EXE uses the grid2VGT0PT custom control and requires GRID.VBX to be properly installed on the user's system.  This is a typical setup scenario for applications that use custom controls.

To customize SETUP1.MAK so that it installs your application instead of LOAN.EXE, modify only the code in the Declarations section and the Form_Load event procedure of the SETUP1.FRM module.

To customize SETUP1.MAK

1  Modify the appropriate constants in the Declarations section of SETUP1.FRM.

2  In the Form_Load procedure of SETUP1.FRM, modify the arguments to the PromptForNextDisk function call.

3  Call the CopyFile function for each file on the current distribution disk.

4  Repeat steps 2 3 for each of the distribution disks, creating a new block of PromptForNextDisk and CopyFile calls for each disk.

5  Modify the arguments to the CreateProgManGroup and CreateProgManItem procedure calls.

 

SETUP1.FRM Constants

Several useful constants are defined in the Declarations section of SETUP1.FRM.  When customizing your setup program, redefine these constants to reflect information about your application.

Constant                 Description

 

APPNAME               The name of your application.  Use this constant to display the name of your application in the captions of forms and in messages in the setup program.

APPDIR                   The default directory in which your application is to be installed.

WINSYSNEEDED    The total size, in bytes, of all uncompressed files the setup program will install in the user's \WINDOW and \WINDOWS\SYSTEM subdirectories.  Use this number to determine whether the user has enough space on the disk that contains these subdirectories to install your application.

OTHERNEEDED      The total size, in bytes, of all uncompressed files the setup program will install in the application directory (the directory in which the user installs your application).  Use this number to determine whether the user has enough space to install your application on the disk that contains the application directory.

 

Example

This example of defining constants is taken from the Declarations section of SETUP1.FRM:

Const APPNAME = "Loan Application"

Const APPDIR = "C:\LOAN"

Const WINSYSNEEDED = 40896

Const OTHERNEEDED = 12555

PromptForNextDisk and CopyFile Functions

Use the PromptForNextDisk function to prompt the user to enter a disk.  If the user enters the correct disk, the function returns True.  Use the CopyFile function to copy a file from the distribution disk to the user's machine.  You must call CopyFile once for each file on the disk.  After copying all the files on a disk, call PromptForNextDisk again to prompt the user to insert the next disk.

Example

This example of the PromptForNextDisk and CopyFile functions is taken from the Form_Load event procedure of SETUP1.FRM:

' -----------

' Copy Files

' -----------

' Disk 1

' -----------

' Test to see if LOAN.EX_ is on the disk; if not, then you know the

' user did not insert the first disk.

If Not PromptForNextDisk(1, SourcePath$ + "LOAN.EX_") Then

   GoTo ErrorSetup

End If

' Install LOAN.EXE in the destPath$.

If Not CopyFile(SourcePath$, destPath$, "LOAN.EX_", "LOAN.EXE", 0)

   Then

   GoTo ErrorSetup

End If

' Install GRID.VBX in the user's \SYSTEM directory.

If Not CopyFile(SourcePath$, winSysDir$, "GRID.VB_", "GRID.VBX", 0)

Then

   GoTo ErrorSetup

End If

 

' -----------

' Disk 2

' -----------

' Test to see if FOO.DA_ is on the disk; if not, then you know the

' user did not insert the second disk.

If Not PromptForNextDisk(2, SourcePath$ + "FOO.DA_") Then

   GoTo ErrorSetup

End If

' Install FOO.DAT in the destPath$.

If Not CopyFile(SourcePath$, destPath$, "FOO.DA_", "FOO.DAT", 0)

   Then

   GoTo ErrorSetup

End If

CreateProgManGroup and CreateProgManItem Functions

These functions create a Microsoft Windows program group and program item for your application.

Example

This example of the CreateProgManGroup and CreateProgManItem functions is taken from the Form_Load event procedure of SETUP1.FRM:

' --------------------------------------

' Create Program Manager group and icon.

' --------------------------------------

CreateProgManGroup Setup1, "Loan Application", "LOAN.GRP"

CreateProgManItem Setup1, destPath$ + "LOAN.EXE", "Loan Application"