Back ] Up ] Next ]

Chapter 11

Optimizing and Deploying an Application

Optimizing and Deploying an Application *

Certification Objectives *

Optimizing an Application *

Tips and Tricks of Optimization *

Selecting the Appropriate Compiler Options *

Using Conditional Compilation to Control an Application *

Monitoring the Values of Expressions and Variables Using the Debug Window *

Using the Immediate Window to Check or Change Values *

Setting Watch Expressions During Program Execution *

Defining the Scope of a Watch Variable *

Using the Locals Window to Check or Change Values *

Implementing Project Groups to Support the Development and Debugging Process *

Debugging DLLs in Process *

Testing and Debugging a Control in Process *

Deploying an Application *

Using the Package and Deployment Wizard to Create a Setup Program to Install a Desktop Application, Register the COM Components, and Allow for Uninstall *

Creating a Setup Program for Desktop Application Installation *

Registering the COM Components in a Desktop Application *

Manipulating the Windows Registry *

Allowing for Uninstall *

Planning and Implementing Floppy Disk–Based Deployment or Compact Disc–Based Deployment for a Desktop Application *

Floppy Disk–Based Deployment of a Desktop Application *

Compact Disc–Based Deployment of a Desktop Application *

Planning and Implementing Web-Based Deployment for a Desktop Application *

Deploying an ActiveX Control *

Planning and Implementing Network-Based Deployment for a Desktop Application *

Certification Summary *

From the Classroom *

Optimization and Deployment *

Two-Minute Drill *

Self Test *

 

Certification Objectives

There’s not much point to creating an application if people can’t use it. That’s the entire point of optimizing, debugging, and deploying an application. It allows you to set how you want your program to run, make sure it runs properly, and get it out to the user.

Optimization allows you to get the most out of your application. You can optimize for speed or performance. While optimization is a bit of a trade-off, Visual Basic version 6 allows quick and easy options that help you to create an application that runs the way you want it to.

Debugging allows you to test for runtime and logic errors through tools that come with VB 6. This allows you to test for problems before compiling and deploying your program.

Also in this chapter, we’ll cover how to package and deploy a program so it gets from your desktop to someplace that users can install it on theirs. This includes floppy disk, CD-ROM, local and network folders, and deployment to an Internet Web site.

Optimizing an Application

There are three basic rules to optimization, and none of them are very appealing. The first rule is that no matter how many tricks and tools you use to optimize performance, it will always run poorly if the design is poor. While we covered design in Chapter 5, this aspect can never be stressed enough.

You need to put the user’s needs before your own. While it may look great to have a high-resolution picture that’s enormous in size as the background of your forms, is it really needed? Just because you think something should be added to a program, is it the general consensus? A cornerstone of design is asking what the program is supposed to do. What does the user need to get out of the program? This information can be obtained by talking to your target users. Finding out what the users needs, and then designing the application for performance is the first step to optimization.

This leads to the second rule of optimization: It is important to determine what factors are important to the user. You can’t tune an application if you don’t know what the user needs. If users of an application have computers that are limited in memory, then it does little good to increase performance by loading every form into memory at once. In short, you need to understand the problems before you can optimize them.

After getting the necessary information, you should then outline your application in a flowchart program, a word processor, or on a piece of paper. Figure out what forms need to be created, what controls should appear on the form, and how different components of the program will interact. A common mistake is adding too many controls on a form. Not only does this make the form more confusing for the user, but it eats up memory and slows performance. When the form is loaded, each control has to be loaded. If the controls access data from a database, each control must access data as the user moves through records. By designing your application properly before coding takes place, you can increase its performance dramatically.

The third rule of optimization is that optimization is a trade-off. Increasing performance in one area can often increase the overhead of another resource. To use the example of forms, an application will run faster if each form is loaded into memory, but memory is sacrificed. This makes optimization a bit of a balancing act. The trick is to increase performance as make it as good as possible, but know when to quit. It is easy to keep trying to optimize an application, losing the objectivity that you’ve optimized it as best you can.

Tips and Tricks of Optimization

One of the easiest ways to increase performance is by using the correct data type. As we saw in Chapter 2, there are many different data types that you can use in your applications. However, data types take up different amounts of memory. For example, let’s say you used a variable to store a person’s age. While you could use either an Integer or Double to store it, an Integer uses two bytes and a Double uses eight. Unless Phyllis Diller is a user, you can safely assume you’ll never get a person over the age of 32,767. Using anything other than an Integer would be overkill and use up memory unnecessarily. In addition, the smaller-sized data type will increase the speed of calculations. Remember the KISS method: Keep It Simple, Silly. Always use the simplest data type.

Another tip for increasing performance is to cache properties in variables when you’re using a loop. It is faster to access data stored in a variable, than data stored in a property. When using a loop, you should first set the property to a variable, then use the variable—rather than the property itself—in a loop. As your loop moves through the variables, it will access the data faster.

When you’re done with data, you should discard it from memory. You can significantly increase performance by reclaiming the space used by arrays and variables. For example, when data isn’t needed by a dynamic array, you should use Erase or Redim Preserve to discard the data. Erase is used to eliminate an array, while Redim Preserve can make the array smaller. In addition you should remove the values of variables to reclaim space. This is seen in the following example:

strMyName="My Name is Michael Cross and this is my string"
strMyName=""

In the first line, we assign a long sentence to the String variable called strMyName. In the second line, we clear the value of strMyName and reclaim the space. In doing so, memory is freed up, and performance increases.

However, removing the values of variables to reclaim space should only be done if the variables are going to be out of memory for some time. It makes no sense, and will decrease performance, if you reclaim space only to use the variable a short time later.

Graphics can be an evil beast where optimization is concerned. They gobble up memory and network bandwidth, and can affect the overall performance of applications. There are, however, ways to tame the beast and increase performance.

When a picture is no longer needed, it is advisable to clear the object. If you have a graphic shown in a picture box, you should use the LoadPicture function to clear it. This is shown in the following code:

picPicture.Picture=LoadPicture("GRAPHIC.BMP")
picPicture.Picture=LoadPicture()

The first line of this code assigns a bitmap called GRAPHIC.BMP to the Picture property of a picture box called picPicture. In the next line of code, we clear the Picture property by using LoadPicture(). This frees up memory that was previously used to store the graphic.

Picture boxes are useful for simulating groups of controls. As was mentioned, having large groups of controls eats up memory and slows performance. By using a picture to simulate a control set, you can decrease the amount of memory used.

Another way to decrease the overhead of graphics is using an Image control. The Image control uses less memory than the PictureBox control does. It should be used instead of picture boxes in cases where you’re just using a graphic to respond to a Click event.

The AutoRedraw property of a form can also be used to increase performance. AutoRedraw sets the output of a graphic to either Graphics method or Persistent Graphic. Graphics method performs runtime drawing operations and is used for animation and simulations. Persistent Graphic is a method that stores output in memory and retains the graphic during screen events. An example of a screen event would be if you switched between applications in Windows and hid and redisplayed a form. When AutoRedraw is set to False, Graphics method is used, while Persistent Graphic mode is used when AutoRedraw is set to True. If your application uses or generates complex graphics, it is better to use Graphics method (setting AutoRedraw to False), and handling the repainting of graphics yourself through code.

Up until this point, we’ve dealt with real ways of increasing performance. Some methods are along the lines of sleight of hand. There are a number of ways to make users think performance has increased, when in fact nothing has improved.

One way of masking the speed of an application is through the use of "splash screens". As your application first loads, a form is displayed with it’s MinButton, MaxButton, and ControlBox properties set to False. The contents of the form can include the application’s name, your company name, and so forth. You’ve seen these types of screens when you load VB. A form telling you the program name is displayed as the application loads. This not only masks the time spent for a large application to load but also lets the user know that something is happening. Without this, a user might think that nothing has happened and try to start the application again.

Another way to let users know that an application hasn’t locked up on them is by using progress indicators. The professional and enterprise editions of VB include the ProgressBar control in the Microsoft Windows Common Controls. After adding this control to a form, you can then use DoEvents at points in your program to update the value of the progress bar. The point of doing this is to let the user know that the application is working. This is especially useful when doing such things as populating a large array or loading a particularly large database. If you decide not to use a progress bar, you should at least change the mouse icon to an hourglass.

Finally, while its been mentioned here about the problems of loading multiple forms into memory, you should load commonly used forms and keep them hidden. Hidden forms display quicker than forms that are loaded from disk. This doesn’t mean to load every form in an application—just the common ones a user will use. For example, you shouldn’t hide things like About this Program or forms that supply configuration options. They aren’t used often, and eat up unnecessary memory.

Exercise 11-1: Optimizing a Program

  1. From the Project menu, choose New Project, and then choose Standard EXE. Add a new form to the project. Under Project, choose Add Form, and then choose Form.
  2. Under the Project menu, choose Components. Select Microsoft Windows Common Controls from the list, and check the check box beside it. Click OK.
  3. Add a Timer control to Form1. In the Property window, change the Interval value to 2000. The Interval value sets the number of milliseconds between events. After doing this, add the following code to the Timer’s Timer event:

Unload Form1

  1. In the Property window for Form1, change the MinButton, MaxButton, and ControlBox values to False. Change the BorderStyle to 0 – None. In the Form1_Load event, add the following code:

Form2.Show

  1. On Form2, add a progress bar and command button. Change the Caption property of the command button to Array.
  2. We will now add code that will create an array, populate the array with the value of the counter, and show the progress of this work in the progress bar. In the command button’s Click event, add the following code:

Dim counter As Integer
Dim intNum(100) As Integer

For counter = 1 To 100
intNum(counter) = counter * 5
ProgressBar1.Value = counter
Next counter
ProgressBar1.Value = ProgressBar1.Min

  1. Save the project, as we will be using this in later exercises. Press F5 and test your application.

Selecting the Appropriate Compiler Options

VB allows you to control how your project is compiled into an executable. It also allows you to tweak your application, so it is optimized in a way that best suits your needs and the needs of your user. The options you can set are found under the Project menu, and can be accessed by selecting Project Properties.

The Make tab of the Project Properties dialog box allows you to add information to an executable. By adding code to your project, you can retrieve the property values of the application object. Other applications can also retrieve this information with API calls. Figure 11-1 illustrates the Make tab of the Project Properties dialog box.

Figure 1: The Make tab of the Project Properties dialog box

The first section of the Make tab allows you to set the version number of your application. You can set Major, Minor, and Revision release numbers from zero to 9,999. Checking the Auto Increment check box will increase the revision number by one, each time you compile your project with the Make Project command on the File menu.

Additional version information can be placed in the Version Information section. By scrolling through the Type list, you can choose different kinds of information and then type the value for the particular type in the Value area. The types of information available to you are Comments, Company Name, File Description, Legal Copyright, Legal Trademarks, and Product Name.

On occasion you may write applications that require arguments. In such cases, a user has to type the executable’s name followed by arguments required by the application. For example, you might create a program called TIME.EXE that performs actions within a certain amount of time. In such a case, the user would start the application by using Run from the Windows Start menu, typing the executable’s name followed by the argument of how many minutes before the task starts. If he or she wanted the application to perform its activities in 60 minutes, the user would type: TIME.EXE 60.

However, in Design mode, you can only run an application by pressing F5 or by choosing Start from the Run menu. This doesn’t give the opportunity to add arguments. In cases where arguments are required by an application, you can type them into the Command Line Arguments field. In doing so, VB will start as if the application were started from a command line with the arguments added. Any arguments placed in the Command Line Arguments field won’t be compiled with the project. This allows a user to use his or her own arguments when starting the executable, without problems from Command Line Arguments that were used in Design mode.

The Conditional Compilation Arguments field on the Make tab will be covered in the next section of this chapter. Though important to compiling your application, the amount of information on conditional compilation requires a section of its own.

The Compile tab allows you to set how your application compiles, and—depending on the method you choose—allows you to set a number of options for optimization. The two choices offered to you in the Professional and Enterprise editions of VB are Compile to P-Code and Compile to Native Code.

P-code is short form for pseudo-code, which is an intermediate step between high-level instructions (the code you write in VB) and low-level instructions (the native code your computer executes). When you compile your project, your VB code is converted, and elements of the code is compiled into compressed tokens. These tokens are placed into the compiled executable. By compressing the VB language code into a compressed form, it is executed faster than if it were in the original format. In comparison to native code executables, programs compiled as p-code are generally smaller in size.

Compiling into native code skips over the intermediate step of p-code, and compiles it into native instructions used by the processor. This increases the speed of processing loops and mathematical calculations. When it is compiled, VB uses a compiler engine that Microsoft uses for C++ development suites. Because native code is the same format that C executables are compiled in, you can use debugging tools for C language executables on VB executables. There are numerous benefits to compiling in native code over p-code.

Choosing to compile in native code offers you a number of options for optimization, which are seen in Figure 11-2. As was mentioned at the beginning of this chapter, optimization is a trade-off, and this becomes apparent on the Compile tab. You can choose to optimize for speed, size, or neither. You can’t choose both size and speed. You can only set the compiler to favor one over the other when it compiles your project.

Figure 2: The Compile tab of the Project Properties dialog box

The other two general optimizations on this screen are Favor Pentium Pro and Create Symbolic Debug Info. Favor Pentium Pro will cause your application to run faster on computers with Pentium Pro processors. If you select this, your application will still run on computers with other processors, but they will run a bit slower. Create Symbolic Debug Info will have the compiler create a debug file with the extension .PDB. This file can be used by external debugging tools to debug the application as it runs.

Also on this screen is the Advanced Optimizations button. By clicking this button, you’ll bring up the dialog box shown in Figure 11-3. This screen has a number of options that allow you to increase the speed or reduce the size of your executable. However, they are in a separate area from the other options for a reason. As the warning on the dialog box says, depending on how you’ve written your code, setting these options can cause serious problems.

Figure 3. Advanced Optimizations

Exam Watch: It is important to know the optimization options on the Project Properties tabs and the effect that each will have on compiling. Many questions on the exam deal with problems resulting from changing settings; knowing the settings and effects can lead you to the correct answer.

An alias is a name that refers to an area of memory that’s already referred to by another name. The Assume No Aliasing check box tells the compiler that the application doesn’t use aliasing. When you check this box, the compiler can then optimize your code in ways that it wouldn’t normally be able to do, and performance will increase. However, if you have included any code in your project that passes arguments by reference (which is the default argument passing style in VB), problems will result when the application is run.

In an array, there is a range of indices that can be accessed. For example, if you have an array of 100 indices, and you try and access the hundred and first index, an error message is displayed. This is because VB adds code to your application that checks the array bounds to determine that the index accessed isn’t out of bounds. By selecting Remove Array Bounds Checks the compiler doesn’t add this code, and your application will run faster. However, if the program reads and writes outside of the array, it will be reading and writing to unrelated memory areas. Not only can this cause problems for your application, but to programs using other memory areas as well.

The next two options on the Advanced Optimizations screen are similar. Remove Integer Overflow Checks determines whether a value is within the range of Byte, Data, and Integer data types. Remove Floating Point Error Checks does the same thing, but with Single and Double data types. The compiler normally adds these checks to your application and will generate a runtime error if the value is greater or less than the data type is meant to contain. Selecting this box will speed up calculations, but can produce unexpected results if the data type is overflowed. Selecting these options turns off the error checking, while deselecting them enables the error checks.

Checking the Allow Unrounded Floating Point Operations check box will cause your application to use floating point registers more effectively and avoid loads and stores from memory. In addition, it will also increase the precision of floating point comparisons. Sounds great, except that it can cause some unexpected errors. Because the comparison of floating point is more precise, it can cause the comparison of floating point numbers to be found unequal when you expect them to be equal! This can cause your code to react unexpectedly, or provide results that you deem incorrect.

You may remember that when Pentium chips first came out there was a big stink shortly afterward about bad chips. In 1994, Intel admitted to a flaw in the processor. When floating-point algorithms are used in an application, and a certain combination of digits are divided by each other, the answer comes up as flawed. The problem only seems to affect arithmetic division in math-intensive programs. Intel claims this problem will only crop up once every 27,000 years, while IBM’s claims are more conservative: once every 24 days. No matter which company you believe, owners of these Pentium chips are able to replace the chips by contacting Intel. You also should consider that unless your application uses math extensively, the Pentium problem shouldn’t affect it.

Because the problem exists, your compiler adds code that will produce the correct answer, even if the processor running the application is flawed. Because this code is added, your application’s performance will decrease, as extra work needs to be performed by the code to check answers. When you consider the points in the above paragraph, it becomes apparent that it is fairly safe to enable the Remove Safe Pentium FDIV Checks option. Checking this option will remove the added code and make your application run faster. However, if your application is math-intensive (such as a science or engineering program that does intensive math), you should leave this option unchecked.

On the Job: While the Advanced Optimizations options allow you to set numerous settings for optimizing a program, you should only use them if you’ve considered the implications of each setting. If you configure these settings and experience problems, try removing the settings before altering your code. The optimization settings in Advanced Optimizations may be causing your problem, and its easier to test that (by clicking on a check box) than to rewrite code.

Using Conditional Compilation to Control an Application

There may be times where you don’t want certain code in certain compilations of your application. For example, you may have different versions of a program with different features, or applications that are distributed to different countries. Depending on the countries to which you’re distributing your application, you may need to change the language or currency symbol. When your requirements certain code be included or removed from an application, conditional compiling can be done.

Conditional compilation allows you to create one project that deals with all versions of your application. Compiler constants are created to indicate version information about code to be used, and compiler directives are used to specify what code is to be added to a project. The way you can differentiate compiler constants and directives from other code is by preceding them the pound sign (#).

Compiler constants allow you to specify which version is to be used during compilation. You can almost think of a compiler constant as a title. You define the constant in your code with #CONST and give it a True or False value. When the compiler works through the code, it looks at whether the constant is True or False, then compiles the code related to it. Examples of #CONST are as follows:

#CONST conEnglish=True
#CONST conSpanish=False
#CONST conEnglish=-1
#CONST conSpanish=0

The values of True and –1 are synonymous, as are False and zero. You can use either in your code when defining such constants.

Conditional directives outline what is to be added and ignored during compilation. If the value of the compiler constant evaluated to True, then that section of code would be compiled. Any constant evaluating to False will be ignored. For example:

#If conStandardVersion Then
‘Insert code specific to Standard version here
#ElseIf conProfessionalVersion Then
‘Insert code specific to Professional version here
#Else
‘Insert code for other versions here
#End If

The scope of compiler constants is Private, and cannot be made Global in your code. However, when you specify compiler constants in the Make tab of the Project Properties dialog box, they are global. Specifying constants on the Make tab is done in the Conditional Compilation Arguments field. In this field you can enter assignment expressions, such as:

conEnglish=-1

Or

conEnglish=1;conSpanish=0

As you can see in the second line of the above code, you can enter multiple assignments by separating them with a semicolon.

It is important to remember that any compiler directives and constants you add to your project won’t be compiled into the application. They are instructions for the compiler, and not part of the actual executable. As such, you needn’t worry about the size of directives effecting performance.

Exercise 11-2: Conditionally Compiling an Application

  1. Open the project from Exercise 11-1. In the General Declarations section of Form2, add the following code:

#Const conOne = False
#Const conTwo = False

  1. In Form2’s Load event, add the following code:

#If conOne Then
MsgBox "First conditional option was used"
#ElseIf conTwo Then
MsgBox "Second conditional option was used"
#Else
MsgBox "Welcome!"
#End If

  1. Run the program, and verify that a message box appears saying "Welcome!"
  2. Change the value of conOne to –1, so it now says #CONST conOne=-1. Then run the program, and verify that a message box appears saying "First conditional option was used."
  3. Change the value of conOne to zero, so it now says #CONST conOne=0. Change the value of conTwo to True, so it now says #CONST conTwo=True. Run the program, and verify that a message box appears saying "First conditional option was used."

Monitoring the Values of Expressions and Variables Using the Debug Window

The Debugging windows allow you to monitor what’s happening to data in your code. You can see what the value of variables and expressions are, and enables you to determine if logic errors are present. Logic errors occur when your code returns a result that wasn’t expected, such as if you expected sales tax to be added but your program is subtracting it. Though the code is running properly, the results are not what you wanted. By using the Debugging windows in VB, you can monitor the values of expressions and variables.

The Debugging windows consist of three separate windows: the Immediate, Watch, and Locals windows. The Locals window allows you to monitor the value of any variables within the current procedure’s scope. The Immediate window lets you type code that responds as if it were directly in your code. Through this window, you can also view the results of debugging statements in your code. The Watch window allows you to specify which expressions to watch and returns information about their values as your program runs. Together, they are essential tools for debugging your application.

Before going in-depth into each of these windows, it is important that you understand the Debug toolbar. When using any of these three windows, the Debug toolbar (Figure 11-4) is used to step through statements of code and bring up the Locals, Watch, and Intermediate windows. To view the Debug toolbar, click on View, select Toolbars, and then click on Debug.

Figure 4: The Debug toolbar

The Debug toolbar has a number of options that save you from having to constantly access the Debug, Run, and View menus. By using the Debug toolbar, you can start, stop, and pause execution, as well as use functions to step through code. The different buttons are listed below in Table 11-1, and detail each of the toolbar’s buttons from left to right.

Button

Other Methods to Access this Function

Description

Start/Continue F5, or clicking Start item on the Run menu Starts an application. This button becomes the continue button if the application is in Break mode.
Break Ctrl-Break, or clicking Break item on the Run menu Temporarily stops execution of the program.
End Clicking End item on the Run menu Stops running the application, and returns the user from runtime to Design mode.
Toggle Breakpoint F9, or by clicking the Toggle Breakpoint item on the Debug menu On the current line of your code, clicking this will set up or remove a breakpoint. A breakpoint signals that execution should stop on that line.
Step Into F8, or by clicking Step Into item on the Debug menu Clicking this will execute your code one line at a time.
Step Over Shift-F8, or by clicking Step Over item on the Debug menu Clicking this will execute code one line at a time, but when it reaches a call to another procedure, it will execute that procedure as one step and move to the next line.
Step Out Ctrl-Shift-F8, or by clicking Step Out on the Debug menu. Only available in Break mode Clicking this will execute code one line at a time. If the line is a call to another procedure, the next line displayed is the first line of the called procedure.
Locals Window Click Locals Window item on the View menu Displays Locals window.
Immediate Window Ctrl-G, or by clicking Immediate Window item on the View menu Displays Immediate window.
Watch Window Click Watch Window item on the View menu Displays Watch window.
Quick Watch Shift-F9, or by clicking the Quick Watch item on the Debug menu Displays Quick Watch dialog box. The value displayed will be the current value of the expression you’ve selected.
Call Stack Ctrl-L or by clicking Call Stack item on the View menu. Only available in Break mode Displays Call Stack dialog box. This dialog box shows called procedures that are called by the current procedure, but have not yet completed.

Table 1: Buttons on the Debug Toolbar

The Watch window allows you to monitor the information dealing with watch expressions, which are expressions (variables, properties, and so on) that you’ve decided to watch during your application’s execution. You can specify which expressions to monitor, and then view their values as the program runs.

The Watch window (illustrated in Figure 11-5) is made up of four columns. The Expression column shows the name of the expression being monitored. These expressions can be variables, arrays, properties, and so on. The Value column shows the current value of the expression, and the Type column shows what data type the expression is. Finally, the Context column shows the context of the current expression, such as what procedure the expression is associated with.

Figure 5: The Watch window

The Locals window shows the current value of all values that are declared in the current procedure, when your application enters Break mode. You can specify where in the code you would like Break mode to occur, by clicking on the desired part of code, and then clicking the Toggle Breakpoint button on the Debug toolbar. When execution reaches this part of the code, it will automatically enter Break mode. You can also click the Break button on the Debug toolbar, though this won’t be a precise method of entering Break mode.

The Locals window (Figure 11-6) is made up of three columns. The first column shows the name of the expression in the scope of the current procedure. All declared variables are shown here, as are object variables. The Me expression appears in the Locals window, showing the current form. The Value column shows the current value of an expression, and the Type column shows the expression’s data type. If the expression is an object, the Type column will display what object it is.

Figure 6: The Locals window

As with the Watch window, any structured variables (such as arrays or object variables) will have a plus sign (+) beside the expression’s name. By clicking on the plus sign, you can view additional information dealing with that expression. For example, if you had an array named intNum, you could view the values of each element in the array by clicking the plus sign. To collapse this expanded view of the expression, click on the minus sign (-) that appears when the expression is expanded.

The Immediate window, illustrated in Figure 11-7, allows you to view the current value of an expression at runtime, and allows you to type code during runtime as you would during Design mode. If you wanted to test a line of code you’d just come up with during runtime, you can use the Immediate window to see if it will work. In addition, you can print the values of expressions in the Immediate window to view what their current values are.

Figure 7: The Immediate window

To use the Immediate window, your application must be in Break mode. Once in Break mode, you can then type code into it as if it were the Code window used during Design mode. Any code you then type will immediately execute on pressing Enter. This of course assumes that your cursor is on the line of code you want to execute when you press Enter.

Using the Immediate Window to Check or Change Values

The Print method allows you to view the values of variables in the Immediate window. There are two variations of the Print method, which are quite similar. With the first method, type the word Print followed by the variable you want to view the value of. The second method is a shorthand version of the Print method. By typing a question mark (?) followed by the variable name, you can view the current value. Each of these are shown in the following examples:

Print intNum
? intNum

You can also do "What if" scenarios on the values displayed with the Print method. For example, if you wanted to view what a percentage of the value of intNum might be, you could type:

Print intNum * .25

or

? intNum * .25

After pressing Enter, the value of the What If scenario would be shown in the Immediate window. Performing such an action won’t affect the results of the original variable, as it doesn’t affect the variable’s actual value.

If you wish to change the actual value of a variable with the Immediate window, you can do it as you would in your actual code. This is done by assigning a new value to the variable, as shown in this example:

counter = 50

By assigning the value of 50 to the variable called counter, your code will now execute the remaining code of a procedure with this value. As far as your program is concerned, any new values assigned to a variable in the Immediate window is the same as if it were assigned through the Code window.

Because any of the above methods shown above require you to be in Break mode, this can cause problems when viewing large amounts of data. As in the case of large arrays, you must step through your code and print each current value. To help you in cases like this, you can use Debug.Print in your code to view current values as the program runs.

In the following example, a counter has been created that loops from one to 100. By placing Debug.Print into the code, we can view the value of a variable as execution moves through each loop:

Dim counter as Integer
For counter = 1 to 100
Debug.Print counter
Next counter

When this code is run, you can view the value of the variable counter in the Immediate window.

Unlike Print and ?, Debug.Print won’t work when typed into the Immediate window. To use Debug.Print, you must type it directly into your code. Likewise, Print and ? are only used in the Immediate window, and not typed directly into your code.

Exercise 11-3: Using the Immediate Window to Check and Change Values

Open the project begun in Exercise 11-1. On the View menu, select Toolbars, and then click Debug. The Debug toolbar will appear.

Click the Immediate window button on the Debug Toolbar, so that the Immediate window appears.

In the Click event of the command button on Form2, add the following statement on the line immediately before the line that says "Next Counter":

Debug.Print counter

Run the program by pressing F5. Click Form2’s command button, and notice that the value of the counter variable displays in the Immediate window.

Stop the application. In the Code window, go back to the Click event of Form2’s command button. Click over the line that says "For counter = 1 To 100", so that the cursor is now on that line. Click the Toggle Breakpoint button on the Debug toolbar. Notice that this line now appears highlighted with a breakpoint.

Run the program again. Click Form2’s command button, and notice that execution breaks at the loop. Click the Step Into button on the Debug toolbar to step through the loop several times.

In the Immediate window, type Print counter, and press Enter. The value of counter appears in the Immediate window.

In the Immediate window, type:

counter=50
Print counter

The value of counter is now 50, and stepping through the code will show that this value affects the remainder of the loop. Counter will go from 50 to 51 to 52 and so on.

Stop the program and save it. We will use this project in future exercises.

Setting Watch Expressions During Program Execution

Setting a watch expression in Design mode is done through the Debug menu, by selecting Add Watch. Any expression that you’ve placed your cursor over in the Code window will appear in the Expression text box of the Add Watch dialog box, illustrated in Figure 11-8 below. If you decide that you’d like to watch a different expression, you can type in the name of the expression to watch in this field. The Procedure listbox has a listing of all procedures in the current form or module, while the Module listbox has a listing of all forms and modules in your project.

Figure 8: The Add Watch dialog box

The Add Watch dialog box also allows you to specify what is to occur when execution reaches the expression. Watch Expression will simply monitor the expression. Break When Value Is True will send the application into Break mode if the value of the watched expression has a value of True. Break When Value Changes will send the application into Break mode if the expression’s value changes at all. What kind of problem you are debugging will determine which setting you use.

You can also set watch expressions with the Quick Watch button on the Debug toolbar. The Quick Watch button only becomes active during runtime in Break mode. You can click the Break button or set a breakpoint in your code to enable this button. During Design mode, Quick Watch is available from either the Debug menu or from the Debug toolbar.

By putting your cursor over a variable, you can add the expression to the Watch window with Quick Watch. Unlike the Add Watch command, you cannot edit the expression chosen and select a different variable or property from another module or procedure.

Once you’ve added a watch expression, you can then view its value in the Watch window as the program runs. As seen back in Figure 11-5, the Watch window has four columns including the Value column. It is in the Value column that an expression's value appears. To change the value of an expression, you just click the value and change it. After moving off of the new value (by pressing Enter, Tab, or clicking elsewhere) the new value is assigned to the expression.

The Edit Watch item on the Debug toolbar allows you to modify and delete watch expressions. The Edit Watch dialog box is exactly the same as the Add Watch dialog box, except that it has a Delete button added. By selecting an expression from the Watch window, and then choosing Edit Watch, you can modify or delete that entry.

Exercise 11-4: Adding Watch Expressions

  1. Open the project used in Exercise 11-3. In the Code window, go to Click event for Form2’s command button.
  2. Click the intNum variable in this procedure. From the Debug menu, select Add Watch. The Add Watch dialog box should appear with intNum as the expression. Click OK.
  3. Click the counter variable in the command button’s Click event. From the Debug menu, select Quick Watch. The Quick Watch dialog box should appear with counter as the expression. Click Add.
  4. Run the program. On the Debug toolbar, click the Watch window button, so that this window appears. Click Form2’s command button. Notice that the Watch expressions and their values appear in the Watch window

Defining the Scope of a Watch Variable

When monitoring watch expressions, it is important to be aware of the scope of a variable. The scope of a variable is the area that other parts of code can be aware of an object or variable. For example, if you declare a variable called intCount in a procedure, only code within that procedure can access and modify the value of intCount. Its scope is procedure-level, and only code within that scope can use the variable. As such you need to be aware of the scope of the variable you’re watching.

Depending on how a variable is declared, it can have a procedure-level and module-level scope. Procedure-level variables are available only to code within that procedure. Variables that are module-level can be declared as Private or Public. Private declarations are available to the module that they appear in, while public declarations are available to all modules.

When using variables that are out of scope (not available to the currently running code), the Watch window will show it. The Value column will show <Out of Context>, meaning that the expression being monitored is out of scope. If the variable is needed to be monitored at all times, you should define a different scope for the variable. For example, if the variable was declared at a procedure-level, you should return to Design mode and declare the variable as Private or Public.

Using the Locals Window to Check or Change Values

The Locals window allows you to check and change the values of expressions in the current procedure. It also shows the Me variable, which is the current form. These values only appear when the application is in Break mode.

If you wish to change the value of an expression through the Locals window, click the value of an expression, which is listed under the Value column. You can then change the value, and by moving off of the value, it will retain its new value. You can move off of the value by pressing Enter, using navigation keys, pressing Tab, or clicking off the value with your mouse.

Exercise 11-5: Checking and Changing Values in the Locals Window

  1. Open the project from Exercise 11-4 and run it. There should still be a breakpoint set in your code. Run the application, and click the Locals window button on the Debug toolbar so that the Locals window is displayed.
  2. Click the command button on Form2. When your code reaches the breakpoint it will enter Break mode. Notice that the Me variable for the form object is shown, as are all other variables declared for this procedure.
  3. In the Locals window, click on the plus sign beside the intNum expression. Notice that all elements of the intNum array are displayed with their current values. Click the Debug toolbar’s Step Into button several times and notice that the values change.
  4. In the Locals window, click on the value (shown in the Values column) of the counter expression. Change the counter’s value to 20, and then press Enter.
  5. Click the Step Into button on the Debug toolbar several times. Notice that the value of the counter has effected the programs execution. By looking through the intNum elements in the Locals window, you’ll see that elements of the intNum array are now being filled from the twenty-first element on.
  6. Stop your program. In the Code window, click on the highlighted breakpoint you created in a previous exercise (in the Click event of Form2’s command button). On the Debug toolbar, click the Toggle Breakpoint button to remove the breakpoint.
  7. Save your project. We will use this project for later exercises.

Implementing Project Groups to Support the Development and Debugging Process

Until this point, you’ve been working with only one project at a time. VB allows you to work on multiple projects at once, called project groups. By working with project groups, you can increase your productivity by having several projects loaded at once to work on.

You can also use project groups to test your code in a test project, before adding it to the application you plan to distribute. One project is used to test your code, while the other is used as your "real" application. In this way, you don’t need to worry about ruining a project by adding code that you’re uncertain will work.

To create a project group, you need to add a project to your current project. From the File menu, choose Add Project. You can then add a new project or an existing one. You can select from Standard EXEs, ActiveX EXEs, and so forth, just as you can when creating a new project.

When a project is added, you have created a project group. The Project window reflects this by stating in the title bar Project Group, followed by the Group name (that is, Group 1). You can move between projects in the group by double-clicking the forms or projects contained in the group.

Since multiple projects now exist as a group, you must designate one of these projects as the startup project. The startup project is the project that will start when you press F5, or use the Run menu’s Start command. To set a specific project as the startup project, select the project in the Properties window, then right-click to bring up the contextual menu. From this menu, select Set as Start Up. The startup project will appear bolded, showing that this is the designated startup project. All other projects will appear in normal text.

The Professional and Enterprise editions of VB can be used to create project groups for creating and debugging applications that use ActiveX components. By using project groups, you can create and debug groups that contain ActiveX dynamic-link library projects, ActiveX control projects, ActiveX EXEs, or standard EXE projects.

To change an existing project to any of these ActiveX projects, you must use the General tab of the Project Properties dialog box (which is accessed from the Project menu). On the General tab, use the Project Type listbox. This listbox allows you to select what type of project the currently selected project will be. You can choose from Standard EXE, ActiveX EXE, ActiveX Control, or ActiveX DLL. This allows you to convert a project after it has been created with the Add Project menu item.

Debugging DLLs in Process

By using project groups, you can load in-process components with your standard executable application and run all the projects together. This allows you to step from the application’s code into the in-process component’s code. To do this, you must create a project group consisting of your standard executable, and whatever in-process components you wish to include.

Once you’ve included your ActiveX DLL to a project group, you can then go about the process of debugging the DLL. It is important to remember that the process of debugging ActiveX DLLs is the same as debugging most other in-process components.

The first step to debugging an ActiveX DLL is setting breakpoints and watch expressions, as shown in the previous sections. After adding breakpoints and watch expressions in the class module and control code, you are then ready to fully compile the project.

To debug an ActiveX DLL (or most other ActiveX components), you should fully compile the project. The reason is because ActiveX components won’t unload while it’s running in the development environment. You can have all references to it released and meet all of the shutdown conditions, but it will still remain in memory. Therefore, to test the unloading of a DLL, you must fully compile components.

The default behavior of VB version 6 is to compile on demand. This means that some code isn’t compiled until a client calls for it. As compiling errors often require fixing the error in Design mode, this means you would have to return the entire program group to Design mode to fix the error.

To resolve compiling errors, you should fully compile your project or remove the compile on demand setting. To run the project after fully compiling it, start your project by choosing Start with Full Compile from the Run menu, or by pressing Ctrl-F5. You can disable the Compile On Demand setting from the General tab of Options, which is accessed from the Tools menu. On the General tab, uncheck the Compile On Demand check box. When your program now runs, everything will be compiled before starting.

After running your debugging session, it is important to shut down your application properly. This means using the Close button on your application’s main window to return to Design mode. The reason for this is that using the End button on the Debug toolbar will cause every project to close down. Your DLL will not receive Terminate events from the application, so you won’t be able to effectively test how it shuts down. To test the shutdown behavior of a DLL effectively, you must always use the Close button.

Testing and Debugging a Control in Process

To debug and test a control in process, you should follow the procedures outlined in the section above. First create a project group by adding your ActiveX controls to the initial project. You must then add the necessary breakpoints and watch expressions to your control, and you should fully compile the project before testing the code. Fully compiling the project will allow you to deal with compiling errors before dealing with problems (such as logic errors) that exist in the control itself. Once this is done, you’re ready to deal with the issues that affect controls.

Debugging controls are different from debugging other objects. Why? Because parts of your code in your control has to execute while the form (that the control instance is placed on) is in Design mode. If the code isn’t able to run, then you will be unable to access such things as property procedures and resizing.

There are several areas of control code that you must consider when debugging a control. The first is the property procedures that are used to implement your control’s properties. These allow you to set the control’s properties using the Properties window. The next is the code that saves and retrieves property values. When you load a form containing a control instance, run the project, or save it to disk, this code has to be able to run at Design mode. Finally, the Resize event must run in Design mode so that you have an appearance of the control on your form. If the control is user-drawn, then the Paint event must be run.

The way that you allow such code to run at Design mode is closing the control’s visual designer. This is done by clicking the visual designer’s Close box, or by using Ctrl-F4. One the visual designer is closed, the icon representing the control appears in the Toolbox, so you can add instances of the control to your forms.

When the control’s visual designer is open all instances of the control are disabled. The icon for the control, which appears in the tool bar, is disabled and appears grayed-out. Should you need to open a form that contains instances of a control whose visual designer is open, the control will be covered with cross-hatching.

Since your control is running when the visual designer is closed breakpoints encountered in the control during Design mode will engage, as if the program as a whole were running. When this occurs, Break mode is entered. You can either click the Continue button on the Debug toolbar, or press F5 to continue if this occurs. This avoids having to remove the breakpoint while using the control in Design mode.

Deploying an Application

There are two ways to deploy a VB application: manually, or with the Package and Deployment Wizard. The Package and Deployment Wizard is covered in the following sections. In this section we will cover manual deployment.

Manual deployment takes a little more thinking than the wizard but it’s not very difficult. Before packaging and deploying your application, you must first compile it. From the File menu, choose the Make command. This command is followed by the name of your project, so that if your application were named Project1, it will say Make Project1.exe. A dialog box will then appear, allowing you to choose where the executable will be compiled. After clicking the OK button, the project will compile and become an EXE file.

If your project is part of a project group, you must first select which project in the group you want to compile. In the Project window, select the project you want to compile, and then select the Make command from the File menu. If you would like to compile the entire project group, select Make Project Group from the File menu. A dialog box will appear. After clicking the Build button, the group will be compiled.

Once the project is compiled, you’re ready to copy the files onto the distribution media you intend to use. After that, it’s just a matter of uploading it to the site. If you’re using other deployment methods, then the procedures are a little more involved.

Using floppy disks requires that you put the files for your application in a certain order. You must put the SETUP.EXE and SETUP.1ST on the first disk, then all files that are listed in the Bootstrap section of the SETUP.1ST file. To view this file, you can use any text editor. Any other CAB files are then placed on additional disks.

To distribute your application to a network share, you must first ensure that you have the property permissions or rights (depending on the network operating system used) to access the share. You then use the command prompt or Windows Explorer to access the share and copy the setup files to the target directory.

CD-ROM distribution requires that you have a CD-ROM burner. You won’t get far without one. You then copy your files to the CD.

Using the Package and Deployment Wizard to Create a Setup Program to Install a Desktop Application, Register the COM Components, and Allow for Uninstall

Doing it manually is like a barber not using a bowl when cutting Bill Gates’ hair – you can do it, but why bother with the extra work? The Package and Deployment Wizard is a much easier solution. The wizard walks you through packaging and deploying your application with screens that explain every step. There is no need to follow any of the steps in the previous section if you intend to use the wizard. Figure 11-9 shows the main screen of the Package and Deployment Wizard.

Figure 9. The Package and Deployment Wizard's main screen

The Package and Deployment Wizard is actually two wizards and one dialog box, which you can access from the main screen. The Package Wizard allows you to package your program into CAB files or a self-extracting executable. The Deploy Wizard allows you send your package to a distribution site or media, such as an Internet site, floppy disk, and so forth. The Manage Scripts button opens a dialog box that allows you to rename, delete, or duplicate package and deployment scripts. Such scripts can be used to manipulate the packaging and deployment of an application.

Before using the wizard, you should compile the application. To compile your application, you can follow the steps provided in the previous section. However, upon clicking the Package button, you’ll be informed if your application hasn’t been compiled yet. The resulting screen will offer you the option of compiling the project from here. After clicking the Compile button, the wizard will automatically compile the project, then move on to the Packaging Wizard.

Creating a Setup Program for Desktop Application Installation

To package an application you must first choose what saved project you want to bundle. This is done from the Package and Deployment Wizard’s main menu. The Select Project listbox contains a listing of projects that were previously used in the wizard. If you want to bundle a new project, select the Browse button and select a saved project from your hard disk.

After selecting the project you wish to use, click the Package button. Your project will be analyzed, and the Package Wizard will be started. The Package Type screen will appear, asking you to select the type of package you want to create. The first option is Standard Setup Package, which will create a package that is installed by a SETUP.EXE file. The other option will create a file listing information about runtime components that are required by your application to run. To create a setup program, select Standard Setup Package and click Next.

The following screen asks you to specify where you would like the package to be created. You can have the package assembled in an existing local folder or a network folder, or you can use the New Folder button to create a new folder for the assembly. If you accept the default location, a folder called Package will be created in the folder that contains your project. Clicking Next will bring up a message box that asks you to confirm creation of the Package folder. Click OK to continue.

The Included Files screen lists all files that the Wizard determines are needed by your application to run. It determines this information when the Package Wizard starts and analyzes the project. In almost every case (I say "almost" to cover my butt. I’ve never seen an incorrect listing result.), the listing will be correct. If you require some files not to be included with the package, deselect the check box beside the name of the file. If you want a file added, click the Add button on this screen. An Open File dialog box will appear, allowing you to browse your hard disk for files. You may need to add a file to your project in cases such as when you’re packaging a database program, or when third-party controls are used in your application. As an example, if your application used an Access database file, you would need to add this file to your package.

The next screen you’ll encounter will be Cab Options. This screen allows you to decide whether you want the package to have one huge CAB file, or multiple CAB files. You might select Single Cab if you were distributing your application on CD-ROM, a network folder, or over the Internet. However, if you are going to distribute the application on floppy disk, you must choose Multiple Cabs. Upon selecting Multiple Cabs, a listbox for Cab Size will become enabled. You can use this Cab Size list to specify whether you’d like the cab size to be 1.44MB, 2.88MB, 1.2MB, or 720KB. The cab size you choose should correspond to the size of the floppy disks you’re using for the package.

Exam Watch: While you probably won’t have to deal with a question that requires knowledge of every CAB size available, you should know that multiple CABs must be used for floppy distributions. To use a single CAB won’t enable you to fit the application on one disk.

The next screen is the Installation Title screen, which allows you to specify the title of the package. This name will be displayed when the application is installed. By default, the name that appears in the Installation Title field is the name of the project. If this isn't suitable, simply type in the new name you’d like to be displayed at installation.

The screen that follows (illustrated in Figure 11-10) allows you to specify what will appear in the Start menu, when the user installs your application. This screen offers you a Windows Explorer–style interface, which shows a tree of where on the Start menu your application will be placed. You can change the name and properties of your menu group or item by clicking the Properties button. This button will display the name of the menu item. If it is a group item, you can change whether it is a Private or Common group. If it is a menu item, you can also change the target (application that the item represents) and where the application will start in. You can choose the application path, system path, and numerous other places to start. The New Group button allows you to add additional groups to the Start menu. New Item opens a dialog box that is identical to the one that appears when you choose Properties for a menu item, and adds a new item to the menu. If you want to remove any groups or items, click the Remove button.

Figure 10: The Start Menu Items screen of the Package Wizard

The next screen is Install Locations, which lists certain files (like your application’s executable) for which you can modify the installation location. At the end of the listed file, there is a column called Install Location. Clicking an item in this column will display a drop-down list with a number of choices for installation. You can choose to install into the application path, system path, or numerous other choices.

Following this, you will see the Shared Files screen. The wizard displays a listing of files that can be shared by other applications. At the very least, it will display the name of your application’s executable. If you want a file in this listing to be shared, you should select the check box beside the file’s name.

The final screen allows you to specify the name of the script for this session. This will contain the settings you choose for your session with the wizard. After naming this script, you can later duplicate, rename, or delete it by clicking the Manage Scripts button on the Package and Deployment Wizard’s main screen. If you don’t want to save the settings, simply accept the default name and click the Finish button. Clicking the Finish button will start the bundling of your application based on the settings you choose using the wizard.

Registering the COM Components in a Desktop Application

When you deploy an application, you must include all of the COM components you use in your application. ActiveX controls (OCX files) and ActiveX DLLs have to be included with the package. These are listed on the Included Files of the Package Wizard, and you should verify that all of these have been included.

If a user installs your application, and a COM component can’t be found, the VB Runtime Library will produce a "File not found" message. You should have all of your OCX files installed into the Windows\System directory. If an OCX doesn’t have this path, you should change this in the Install Location column of the Install Locations screen.

If you are using COM components that are included with VB version 6, you won’t need to worry about registering them with the Windows Registry. This is because these files are self-registering. If you want to use an ActiveX component that you’ve created, you should create a dependency file so that the component can be added to the SETUP.1ST file and then registered upon installation.

Dependency files have the extension of .DEP, and contain information about runtime requirements of an application or component. This information includes such things as the files needed by the component or application, where these files should be installed, and how they should be registered with the Registry. When you click the Package button in the Package and Deployment Wizard, it scans for dependency information. It reads the information, builds a list of files required, and builds a listing of installation information. Dependency files are read, and the information is added to a SETUP.1ST file that resides outside of a Standard Setup Package’s SETUP.EXE file. Internet packages have this file written to an INF file stored in the CAB.

After clicking the Package button, the Package portion of the wizard starts. As was previously mentioned, you can then choose to create a standard setup package or a dependency file. After selecting Dependency File and clicking the Next button, you are presented with the Package Folder screen. This allows you to specify where the package will be assembled. For further information on this screen, see the previous section. Clicking Next, you reach the Included Files screen.

Included Files allows you to specify what files are to be included with the package. The list contains all dependent files that the wizard has determined are necessary from analyzing your project. Clicking the Add button can include any additional files you want to add. Upon doing so, a dialog box appears that allows you to browse your hard disk. After specifying the files to add, click Next.

The next screen is only important if you are bundling the dependency file into a CAB file for dependency on the Internet. Here you can enter the name for the CAB file, a URL from which it can be retrieved, and the default file to execute when the file is downloaded. The file to execute can be either an executable or an INF file. If you are not packaging the dependency file for the Web, accept the defaults, and choose next.

The screen after this is the Install Locations screen. This screen allows you to specify where files are to be installed. As mentioned in the previous section, you can modify the location through the final column on this screen. The Install Location column allows you to change the installation location of a particular file, via a drop-down list.

The final screen allows you to name a script for the dependency settings you specified in this setting. You can duplicate, rename, and delete this file by clicking the Modify Scripts button on the Package and Deployment Wizard’s main screen.

Manipulating the Windows Registry

The GetSetting and SaveSetting functions allow you to read and write information to and from the Windows Registry, respectively. These are built-in VB procedures that access entries under the HKEY_CURRENT_USER\Software\VB and VBA Program Settings. You can use these functions to programmatically manipulate the Windows Registry.

GetSetting and SaveSetting both have the following arguments: appname, section, and key. The appname argument is the application’s name, section is the name of the section where a key setting is found, and key is the name of the key to return. SaveSetting also has a fourth argument called value, which allows you to specify the contents to be stored in the Registry.

If you wanted to save settings to the Registry, you could do something like this example:

SaveSetting app.exename, strUser, strID, txtUser.Text

In doing so, the SaveSetting function would take the name of the currently running program, and the values of the other variables and save them to the Registry. To retrieve this information, you could use the following code:

txtRegInfo.Text=GetSetting (app.exename, strUser, strID)

Unlike most of the other material in this chapter, you would use the GetSetting and SaveSetting functions in your code. In doing so, you could access and write to the Registry and manipulate data contained therein.

Allowing for Uninstall

While no programmer likes to admit it, there are times where users won’t want to use your application anymore. Despite all your hard work, they’ll want to cast your application by the wayside and uninstall it from their system. I know you’ll read this with tears in your eyes, but it’s important to know how to provide a user with the ability to uninstall your program.

Users can use the Add/Remove Programs applet in Control Panel. However, the Package and Deployment Wizard installs a program that works with Add/Remove Programs, so that the user can uninstall an application. While packaging your program, it adds a file called ST6UNST.EXE, which is the application removal utility. It installs this to the \Windows or \WinNT directory.

In addition to this, when the user installs your application, a file called ST6UNST.LOG is created in the application directory. This file contains information on directories that were created during installation, Registry entries that were created and modified, and self-registered DLL, EXE, or OCX files. In addition, the log file has information on links and Start menu items that were created and the files (and their location) that were installed. The listing of files is comprehensive. It lists all files in the setup program, including ones that weren’t installed because newer or identical files existed. It also specifies whether files are shared files, and (if shared) if setup replaced the existing file.

ST6UNST.EXE reads the log file and determines all files that should be removed. When executed, it will remove all files, directories, and other items logged in the ST6UNST.LOG. It allows the user to fully remove your application from their system.

Planning and Implementing Floppy Disk–Based Deployment or Compact Disc–Based Deployment for a Desktop Application

In cases where you’re selling your application, the most common methods of deploying an application will be on compact disc (CD-ROM deployment) or on floppy disks. The Package and Deployment Wizard allows you to deploy to such media easily. By following the screens, you should have little problem distributing an application on such media.

On the Job: It is important to offer both CD and floppy installations of your applications. CD deployment is better, as the user won’t have to keep switching disks during the installation. However, remember that not everyone has a CD-ROM drive. Though an application may have to be split up over several floppies, it is wise to offer both installations. Not doing so will exclude a significant number of people from using your application.

Floppy Disk–Based Deployment of a Desktop Application

Floppy disk deployment requires that you package your application into multiple CAB files. As shown in Figure 11-11, the Cab Options screen allows you to choose to bundle your application in a large single CAB file, or multiple CABs. You can select different sizes of CAB sizes that will apply to your CAB files. These sizes range from 720KB to 2.88MB. The size you choose will depend on the size of blank disks you are using to distribute the application. You can’t use disks of different sizes or choose to deploy to more than one size of disk. Whatever size you choose will apply to all of the blank disks you use.

Figure 11: Cab Options screen of the Package portion of the Package and Deployment Wizard

Once you have properly packaged your application, you’re ready to deploy your application to floppy disks. After selecting the package you want to deploy, from the Select Package listbox on the Package and Deployment Wizard’s main screen, click the Deploy button. The Wizard will analyze the project, and you will see a screen that asks you which script you want to use. Select the package you wish to deploy, from the listbox of scripts available, then click the Next button.

The Deployment Method screen asks you what method you wish to use to deploy your application. On the list of available deployment methods, there should be an entry for floppy disks. If you haven’t packaged the application as multiple CABs, the floppy disks option won’t appear. If the floppy disks option doesn’t appear, you’ll have to return to the Package Wizard and repackage the application as multiple CABs.

Exam Watch: Floppy disk deployment won’t appear on the Deployment Method listing if you haven’t packaged your application as multiple CAB files. If this is the case, you must return to the package portion and repackage the application as multiple CABs.

After selecting floppy disks, click the Next button, and you’ll be asked which drive you want to use. If you have a single floppy drive, only one drive will appear in the drive box. You should also check the Format before copying check box. Floppy disk deployment requires blank, formatted disks. If you have existing data on a disk, deployment will fail. In addition, you’ve probably experienced buying a box of formatted floppies, only to find that the occasional one (or all of them) haven’t been formatted. To avoid problems, select this check box. After doing so, select the floppy drive to which you want to deploy, and click Next.

The final screen allows you to name the script used to save settings for your deployment session. As has been mentioned, you can rename, duplicate, or delete this script through the Manage Scripts portion of Package and Deployment Wizard. Clicking the Finish button on this screen will begin transferring files to the floppy disks.

Exercise 11-6: Packaging and Deploying an Application to Floppy Disk

  1. Open the Package and Deployment Wizard. On the main screen, click the Browse button and open the project you saved in Exercise 11-5.
  2. Click the Package button. Wait as the wizard analyzes your project. Accept the Standard Setup Package 1 script name default and click Next. On the Package Type screen, select Standard Setup Package and click Next.
  3. Accept the default for the wizard to package the application in the project’s folder. Click Next, and accept the confirmation message box that appears. A new folder named Package will be created in your project’s folder.
  4. Accept the files to be included with your package. Click the Next button, and you’ll be brought to the Cab Options screen. On this screen, select Multiple cabs. The Cab Size listbox will be enabled. Select the size of disks you are using from this list and click Next.
  5. On the following screen, enter a title for your installation. Click Next. On the Start Menu Items screen, rename the group and name of your application using the Properties button. Select the group or item, click Properties, and enter a new name in the Name field. After doing this, click Next to continue.
  6. Accept the defaults for the following screens. Toggle through them, clicking Next. At the end of the wizard, click Finish and your application will be packaged.
  7. On the Package and Deployment Wizard’s main screen, click Deploy. As this is your first time using the Deploy portion, only one package script will appear on the first screen. Click Next.
  8. Select Floppy Disks from the Deployment Method screen, and click Next.
  9. Select the floppy drive you wish to use. Check the Format before copying check box, then click Next. This will bring you to the final screen. Click Finish, and your package will be deployed.

Compact Disc–Based Deployment of a Desktop Application

The CD-ROM deployment of a desktop application is very similar to folder deployment, which is covered later in this chapter. In fact, you can use the folder deployment method for CD-ROM deployment. You would use Folder option, then transfer the files afterward to CDs. In most cases, this would be the option you would use in the real world. The reason for this, is that you will rarely encounter a CD burner attached to every programmer’s workstation.

A CD burner is also called a writeable CD-ROM. While normal CD-ROM drives only allow you to read from a CD, CD burners allow you to read and write to CDs. To write your packaged application to a writeable CD, you must insert a blank CD into your CD burner. While the price of writable CD-ROMs is still quite high, the price is dropping to a level that many people and smaller companies are able to afford.

Depending on the writeable CD-ROM you own, you may be able to deploy files directly to the CD with the Package and Deployment Wizard. This will allow you to transfer the files, with the settings you’ve chosen, directly to the writeable CD. For such a deployment, you can use either single or multiple CAB files, though a single CAB is more commonly used. The files are transferred to the CD with the same type of procedures as detailed in the network folder deployment.

Planning and Implementing Web-Based Deployment for a Desktop Application

The Internet is an effective way of deploying an application to users. Deploying a package via the web requires you to have some sort of Internet access and proper permissions to a directory on a Web site. Since you’ll be deploying your application to a directory on an Internet server, you must ensure that you’re able to post (upload or transfer files) to a particular directory. Check with your Internet Service Provider or system administrator to determine if these permissions exist.

You can package your application as single or multiple CAB files, but single is often the better choice for Web deployment. Having too many files can often confuse novice users, and a single CAB file limits their choices as to what they need to download. After packaging your application, start the Deploy portion of the Package and Deployment Wizard.

On the Deployment Method screen of the Deployment Wizard, select Web Publishing, then click Next. The Items To Deploy screen lists all of the files in your package (SETUP.EXE, SETUP.1ST, and CAB files). If you don’t want to deploy certain files, deselect the check box beside the file’s name. You will generally want to deploy all files listed. Click Next to move to the following screen.

You are given the option of selecting other files and folders to deploy. A tree is shown on this screen, displaying all files and directories in the directory containing your Package folder. Checking the checkbox beside a file or directory’s name will include the file. This is useful if you are deploying a sample application, and want to include the code (that is, forms) for the application. It is also useful if you’re deploying database applications and want to deploy a blank copy of the database. That way, if they experience problems, they can access a fresh database file.

Clicking the Next button will bring you to the Web Publishing Site screen. This screen allows you to enter the URL (uniform resource locator, or Web site address) of where you want the application deployed. You must enter a valid URL that you have permissions to upload to in the Destination URL combo box. If you leave this blank, you won’t be able to continue. In addition, you have two protocols to choose from in the Web publishing protocol listbox: HTTP Post and FTP. You should check with the Internet server’s system administrator to determine the preferred protocol.

Clicking the next button will bring you to the final screen. You can enter a name to save the settings for this session to a script, or just click Finish to complete the session. Your package will then be deployed to the Web site.

Deploying an ActiveX Control

If your project contains an ActiveX control, you can deploy your project as an Internet package. This will create a CAB package that can be either downloaded from a Web site, or posted to a Web server. Using the Package and Deployment Wizard to deploy an ActiveX control is significantly easier than doing it manually.

From the main screen of Package and Deployment Wizard, select the project you want to package from the Select Package listbox, or click Browse to add your project to the list. Having done this, click Package. Your project will be analyzed. If you have created previous Internet packages, you can select a script to use from the listbox, or choose None to create a fresh installation package.

The next screen allows you to determine the type of package to create. Since the Wizard has determined that this project contains an ActiveX control, it offers the choice of creating an Internet package. You should select this package, then move through the following two screens. The two screens following this allow you to determine where the package is to be bundled and what files are to be included.

Next you will encounter is the File Source screen. These will list runtime CAB files that are linked to those on Microsoft’s Web site or another location, such as the CAB file itself. There is a listing of files that have such links. Clicking on each of the files will determine where the links reside. The Files Source section of this screen allows you to modify the source, so you can either include the information in the CAB file, download it from Microsoft, or download it from another source. Depending on the file, you may be limited on the options available in the Files Source section. For example, the OCX file for the ActiveX control you created may only be able to include the information or download it from a site other than Microsoft’s.

The next screen allows you to specify safety settings for your components. If certain components can’t be determined as safe to initialize or script, they will be listed here. Files listed here will have a value of No for initialization and scripting safety. To set your component as Safe for Scripting and Safe for Initialization, click each of the columns for these settings and change their value to Yes.

Clicking Next will bring you to the final screen. You can rename an Internet package and save the settings for this session. Clicking Finish will create the package.

Clicking Deploy will analyze the project and bring of the first screen of the Deploy portion. The Package to Deploy listbox will list a new script for your Internet package. Select this script and click Next.

The next screen allows you to specify whether to use a deployment method of folder or Web publishing. Select Web Publishing and click Next to have your packaged published to a Web server. The screens that follow are the same as those covered in the previous section.

Planning and Implementing Network-Based Deployment for a Desktop Application

If you plan to deploy your application to a folder on a network, you must first ensure that you have the proper permissions or rights (depending on whether your network is NetWare or NT) to do so. In addition, the people you’re planning to have use your application must also have proper permissions. If you or they do not, people won’t be able to access the directory containing your application. Check with your network administrator to ensure that you and others can access the network directory.

After doing this, you are ready to use the Package and Deployment Wizard. After packaging your application as either a single or multiple CABs bundle, click the Deploy button to start the deployment portion of the Wizard. The first screen will display a listbox that allows you to select the package you want to deploy.

The screen that follows this is the Deployment Method (refer back to Figure 11-12). Select Folder from the list, and click Next to see the Folder screen. The Folder screen allows you to select a local or network folder for deployment. A Windows Explorer–style tree is displayed, allowing you to navigate through folders on your hard disk. If you want to deploy locally, you could select a folder from the tree. To create a new folder, you would click the New Folder button, and then name the newly created folder.

Figure 12: The Folder screen of the Package and Deployment Wizard

Since we’re deploying to the network, the Network button on this screen would be used. This will display a dialog box that shows a tree of the network, which is similar to what you see when you use Network Neighborhood in Windows. Clicking through the listing, you would find the networked computer to which you wish to attach. You would then navigate to an existing folder or—depending on your permissions—create a new folder for deployment.

Depending on the network you’re on, and how your computer is configured, you may also be able to switch to the network drive using the Drive box. You could then navigate through the tree of folders to find the one you wish to deploy to. This would be the case if you were on a Novell NetWare network and had drives mapped to your computer.

Clicking the Next button will bring you to the final screen. Here, you can name the script that will contain the settings chosen in this session. Clicking the Finish button will initiate the deployment and transfer the files to the network folder.

Begin Q&A

How can I optimize an application for both size and speed? You can’t. Optimization is a trade-off, and you can only optimize for speed or for size, not both.
How can I check for logic errors in my application? Use the Debugging windows in VB. They will allow you to test your program and help you find and fix logic errors.
How do I give a user the ability to fully uninstall my application? The Package and Deployment Wizard automatically adds the file called ST6UNST.EXE to your package. This file reads the ST6UNST.LOG file created during installation and fully removes your application from their system.
If a user already has the ST6UNST.EXE installed, does this mean they won’t be able to uninstall my application when my installation tries to install it? Each time one of your applications is installed, the setup program will put the ST6UNST.EXE on the user’s system. This won’t effect an uninstall of your application, as the ST6UNST.EXE file reads uninstall information from the ST6UNST.LOG file that’s created in the application directory.
I am only using controls included with VB version 6. Do I need to create a dependency file for my package? Generally, no. The Package and Deployment Wizard will analyze your project and include the files required for your application.

Certification Summary

Optimization allows you to improve the size or speed of an application. VB version 6 allows you to configure a number of optimization options through the Project Properties dialog box tabs. In addition, there are advanced optimization options you can set, which should only be configured if you understand what effects they will have on your application.

VB’s Debugging windows allow you to monitor what is happening to data as you step through execution. The Debugging windows consist of the Watch window, the Local window, and the Immediate window. They are tools provided with VB to allow you to debug your application.

The Package and Deployment Wizard allows you to bundle an application into an installation package, then deploy it to a distribution site or media. By using the wizard, you are able to create professional installations quickly and easily. The wizard steps you through the process, allowing you to package and deploy an application by answering its questions.

From the Classroom

Optimization and Deployment

Throughout the countless development cycles, an ongoing process of optimization should be undertaken. Application optimization should focus on one (two at most) areas of application characteristics: calculation speed, display speed, perceived speed, memory size, or executable size. Advances on one area often contradict desired progress in other areas, forcing either a balancing act of optimization procedures, or a distinct trade off. Its very important for the developer to properly recognize not only what to optimize, but where to optimize code for maximum return on development time.

Visual Basic also provides for conditional compilation directives for providing conditional logic during the compiling of an application executable. This greatly increases the flexibility of debugging and selective code inclusion during binary compiling.

In addition to application optimization, debugging plays a crucial role in application development. For this, be very aware of the part the Watch, Locals, and Immediate windows play in the debugging process. Knowing what options are available in each is crucial to understanding application debugging. Also note how project groups can assist in application development. Be prepared to describe the established methods for debugging DLLs, ActiveX controls, and using all the possible ways to invoke breakpoints for debugging standard executable projects.

After successfully wading through the mirage of development, optimization, and debugging cycles, application development remains. Be aware of the syntax for declaring conditional compilation directives, limitations on conditional compilation syntax structure, and how conditional compilation techniques can assist application debugging. For the exam, be able to explain the ramifications of choosing P-Code versus Native Code compilation, especially the effect of altering the Advanced Optimization choices available in Visual Basic.

To cover the bases, also be aware of the basics of application deployment methods, such as floppy, compact-disc, and web-based deployment, including the files generated.

By Michael Lane Thomas, MCSE+I, MCSD, MCT, A+

Two-Minute Drill

Self Test

The following Self-Test questions will help you measure your understanding of the material presented in this chapter. Read all the choices carefully, as there may be more than one correct answer. Choose all correct answers for each question.

  1. You have decided to increase performance of an application by using the correct data types for variables. One of your variables is used to store the current year. What data type would you use?
    1. Double
    2. Single
    3. String
    4. Integer
      D. Integer. Since the current year would be a value in the thousands, but not over 32, 767, you would use an Integer. Any other data type would be overkill and use more memory space.
  2. Which tab of the Project Properties dialog box allows you to set version information for an executable?
    1. General
    2. Make
    3. Compile
    4. Debugging
      B. The Make tab allows you to set version information for an executable.
  3. Which of the following will remove the value of a String variable to reclaim space?
    1. strName = Null
    2. End strName
    3. strName=""
    4. Reclaim strName
      C. strName="". To remove the value of a String variable and reclaim space, you would assign an empty value, as seen in the code: strName="".
  4. You have decided to compile to p-code and then set optimization settings for this to optimize for both speed and size. When you go to the Compile tab, you find you cannot accomplish this. Why?
    1. You can only optimize for both speed or size.
    2. P-code doesn’t offer optimization settings for compiling.
    3. You need to make these settings on the Make tab.
    4. None of the above.
      B. p-code doesn’t offer any optimization settings for compiling. Settings are only available when compiling to native code.
  5. What will be the effect of the following conditional compilation code?
    1. #CONST conEnglish=0
      #CONST conFrench=-1
      #CONST conSpanish=False
    2. conEnglish will be compiled.
    3. conFrench will be compiled.
    4. conSpanish will be compiled.
    5. All constants will be compiled.
      B. conFrench has a value of –1, which evaluates to True. Both of the other compiling constants have False values. Therefore, code associated with conFrench will be compiled.
  6. You want to display the value of intNum in the Immediate window by typing code directly into a procedure. Which of the following would be valid to use in your code to perform this action?
    1. ? intNum
    2. Print intNum
    3. Debug.Print intNum
    4. All of the above
      C. Debug.Print intNum. Debug.Print is used in a procedure’s code to display the value of an expression in the Immediate window. The others are typed in the Immediate window, not used in the application’s actual code.
  7. Your are deploying your application to floppy disks. Part way through the deployment, you find that one of the floppies isn’t formatted. What can you do?
    1. Stop the packaging and return to the Package portion of Package and Deployment Wizard. Check the Format before copying check box, and repackage your application.
    2. Stop the packaging and return to the Deploy portion of Package and Deployment Wizard. Check the Format before copying check box, and redeploy your package.
    3. Repackage and redeploy your application. All information will be lost when you stop deployment.
    4. Repackage your application on formatted floppy disks.
      B. Stop deployment, return to the Deploy portion of Package and Deployment Wizard, and check the Format before copying check box. Your floppies will now be formatted before files are copied.
  8. You want to remove a picture from memory, to reclaim the memory space. What will you do?
    1. Use the LoadPicture() function
    2. Use the RemovePicture() function
    3. Use LoadPicture to load a nonexistent graphic file
    4. Use UnloadPicture() function
      A.. The LoadPicture() function is used to remove a graphic from memory, and reclaim space.
  9. You want to configure your form to use Graphics method rather than Persistent Graphics. What will you set to do this?
    1. AutoRedraw to False
    2. AutoRedraw to True
    3. AutoRedraw to Graphics
    4. AutoRedraw to Persistent
      A. To use the Graphics method, set AutoRedraw to False.
  10. You have entered code to load all of the commonly used forms at application startup. What effect will this have on performance?
    1. It will give the appearance that performance has increased.
    2. It will give the appearance that performance has decreased.
    3. It will increase the size of the application.
    4. It will decrease the speed of the application.
      A. Loading all commonly used forms at startup will give the appearance that performance has increased. This is because hidden forms will display faster than forms that have to load into memory from the hard disk.
  11. You have decided to use the Web Publishing option in the Deploy portion of the Package and Deployment Wizard. What protocols are available for you to send your package to a Web site?
    1. HTTP Post
    2. HTTP Get
    3. FTP
    4. HTML Post
      A. (HTTP Post) and C. (FTP). The protocols available for Web publishing are HTTP Post and FTP.
  12. What Deployment method would you select to deploy your application to a network folder?
    1. Web Publishing
    2. Folder
    3. Network Folder
    4. NT Folder
      B. Folder. To deploy an application to a network folder, select Folder from the Deployment Method screen.
  13. What file contains a listing of files installed, directories created, and so on when the application is installed, and what is it used for?
    1. ST6UNST.LOG contains a list of installed files for ST6UNST.EXE to use if the application is uninstalled.
    2. SETUP.LOG contains a record of how the installation went and what files are installed, for review by the user.
    3. UNINSTALL.LOG contains a list of installed files for ST6UNST.EXE to use if the application is uninstalled.
    4. INSTALL.LOG contains a list of installed files for Add/Remove Programs to use if the application is uninstalled.
      A. ST6UNST.LOG contains a list of installed files for ST6UNST.EXE to use if the application is uninstalled.
  14. You want to register a COM component. What is the easiest and best way to do this?
    1. Use the Package and Deployment Wizard to create a dependency file.
    2. Use the Package and Deployment Wizard to create a Registry file.
    3. Using a text editor, manually edit the SETUP.1ST file.
    4. Using a text editor, create a SETUP.1ST file.
      A. Use the Package and Deployment Wizard to create a dependency file. While you can create or edit SETUP.1ST files and include information to register a COM component, the easiest and best way is to use the Package and Deployment Wizard to create a dependency file.
  15. You are debugging a DLL in process, but find that when you click the End button on the Debug toolbar, you are unable to test the shutdown behavior of the DLL. Why?
    1. DLLs don’t have a shutdown behavior.
    2. The End button closes down every project, so you must close the application properly.
    3. The code that determines the shutdown behavior has a bug in it.
    4. The DLL can’t be loaded in the design environment.
      B. The End button will close down every project. To effectively test a DLL’s shutdown behavior, close the application properly. This is done by clicking the application’s Close button.
  16. In the Watch window, the value of the variable intMyInt reads <Out of Context>. What does this mean?
    1. intMyInt hasn’t been declared.
    2. intMyInt is out of scope.
    3. intMyInt has a value of zero.
    4. intMyInt has a null value.
      B. intMyInt is out of scope.When the value of an expression in the Watch window reads <Out of Context>, that variable is currently out of scope.
  17. During runtime you notice the Quick Watch button on the Debug toolbar is inactive. Why?
    1. There are no watch expressions currently set.
    2. There are no variables in the current procedure.
    3. The Quick Watch button becomes active in Break mode.
    4. There are no breakpoints set in the project.
      C. The Quick Watch button becomes active in Break mode. While not an option here, it also becomes active in Design mode.
  18. The variable intNum has a value of four . You type the following code in the Immediate window. What will be printed?
    1. Print intNum * .25
    2. 4
    3. intNum * .25
    4. 1
    5. An error will result
      C. intNum * .25. The answer printed will be one . You can manipulate data in the Immediate window by typing math equations such as this. In this case, if intNum has a value of four, it will be multiplied by 0.25, resulting in a printed answer of one in the Immediate window.
  19. You have a variable with a Boolean value of False, that you want to monitor. You want the application to break when this value changes. Which of the following options would you set in the Add Watch dialog box?
    1. Watch expression
    2. Break when value is True
    3. Break when value changes
    4. Break when value is False
      B. (Break when value is True) and C.(Break when value changes). Since you’re monitoring a Boolean value that’s False and want to monitor a change in value, you could use either Break when value is True, or Break when value changes. Either would cause execution to break when the value changes.
  20. You want to fully resolve compiling errors before debugging a DLL in process. What can you do to resolve any compiling errors before doing this?
    1. From the Run menu, select Start with Full Compile.
    2. From the Run menu, select Start.
    3. In Options, uncheck Compile on Demand.
    4. Press F5.
      A. (From the Run menu, select Start with Full Compile) and C. (In Options, uncheck Compile on Demand). To resolve compiling errors, fully compile your application by choosing Start with Full Compile from the Run menu. You can also disable the Compile on Demand setting in Options. This will force your application to fully compile before running.
  21. You have decided to distribute an application to Web sites like http://www.microsoft.com. When you attempt to deploy the package, it fails. Why?
    1. You selected single CAB rather than multiple CABs for packaging.
    2. You selected multiple CABs rather than single CAB for packaging.
    3. You don’t have proper permissions to deploy to that site.
    4. You aren’t able to deploy to Web sites with the Package and Deployment Wizard.
      C. You don't have proper permissions to deploy to that site. To deploy a package to an Internet site you must have proper permissions on the Web server.
  22. The application removal program is automatically added to your package by the Package and Deployment Wizard. Upon installation to a user’s computer, where is this program installed?
    1. The application directory
    2. The system directory
    3. The Windows or WinNT directory
    4. A subdirectory in the application directory
      C. The Windows or WinNT directory. The application removal program, ST6UNST.EXE, is installed to the Windows or WinNT directory.
  23. A user installs your application. Unfortunately your forgot to include a COM component with the package. What will happen when it can’t find the COM component?
    1. The VB Runtime Library will give a "File not found" message.
    2. The problem will cause the program to crash.
    3. The problem will be ignored.
    4. The problem will cause the installation to uninstall itself.
      A. The VB Runtime Library will give a "File not found" message. When a COM component can’t be found, the VB Runtime Library will give a "File not found" message.
  24. You want to manipulate information contained within the Registry. Which of the following functions would you use?
    1. GetSetting
    2. SaveSetting
    3. GetKey
    4. SaveKey
      A. (GetSetting) and B. (SaveSetting). GetSetting and SaveSetting are used to respectively read and write to the Registry.
  25. Which button will allow you to step through code one line at a time, but when it reaches a called procedure, will execute the called procedure as a single step then move to the next line?
    1. Step
    2. Step Into
    3. Step Over
    4. Step Out
      C. The Step Over button allows you execute code one line at a time, but when it reaches a call to another procedure, it will execute that procedure as one step and move to the next line.
  26. What does the Create Symbolic Debug Info option on the Compile tab of the Project Properties dialog box do?
    1. Allow breakpoints to be set
    2. Creates a file for use with the Package and Deployment Wizard
    3. Logs debugging problems that occur during a debugging session
    4. Creates a debug file for external debugging tools
      D. Creates a debug file for extended debugging tools. This option will have the compiler create a debug file with the extension .PDB. This file can be used by external debugging tools to debug the application as it runs.
  27. Which of the following can you use to test code before adding it to your actual application?
    1. Project groups
    2. Immediate window
    3. Locals window
    4. Watch window
    5. Code window
      A. (Project groups) and B. (Immediate window). Project groups and the Immediate window allow you to test code before adding it to the application. The Immediate window can be used to test code on the fly, while project groups allow you to use one project for testing (like a scratch pad).
  28. Which of the following would you use to save settings to the Registry?
    1. PropertyGet
    2. PropertyLet
    3. SaveSettings
    4. GetSettings
      C. SaveSettings. To save settings to the Registry, use the SaveSettings function.
  29. You want to change the value of an expression in the Locals window. How will you do this?
    1. Right-click the value, and select Properties from the contextual menu
    2. Click the value in the Value column and enter the new value
    3. Click the expression and enter the new value
    4. Click the variable associated with the expression. A properties box will appear.
      B. Click the value in the Value column and enter the new value. To change the value of an expression in the Locals window, click the value in the Value column, and enter the new value.
  30. How can you create a project group?
    1. From the File menu, select Make Project Group
    2. From the File menu, select Add Project
    3. From the File menu, select New Project
    4. From the Project menu, select Make Project Group
      B. From the File menu, select Add Project. To create a project group, from the File menu, select Add Project. You can then add a new or existing project.
  31. Where can you rename, delete, and duplicate package and deployment scripts?
    1. Manage Scripts in the Package and Deployment Wizard
    2. Scripts in the Package and Deployment Wizard
    3. The Scripts utility that comes with VB
    4. The Package portion of the Package and Deployment Wizard
      A. Manage Scripts in the Package and Deployment Wizard allows you to rename, duplicate, and delete package and deployment scripts.
  32. Which entries does GetSetting and SaveSetting allow you access?
    1. Anything in the Registry
    2. Entries under HKEY_CURRENT_USER\Software\VB and VBA Program Settings
    3. Entries under HKEY_CONFIG\Software\VB Program Settings
    4. Any currently open Key
      B. Using GetSetting and SaveSetting you can access entries under HKEY_CURRENT_USER\Software\VB and VBA Program Settings.
  33. During installation, the file ST6UNST.LOG is created. Where is this file stored on the user’s hard disk, and why?
    1. The application directory, for use in uninstalling the application
    2. The system directory, for use in uninstalling the application
    3. The root directory, for logging the success or failure of installation
    4. The system directory, for logging the success or failure of installation
      A. ST6UNST.LOG is created in the application directory and used for uninstalling the application.
  34. You are using the Locals window and see that an expression called Me is displayed in it. You don’t recall setting a watch expression for it. What does this expression represent?
    1. This is an error.
    2. This expression represents the Locals window.
    3. This expression represents the current form.
    4. This expression represents the current project.
      C. This expression represents the current form. The Me variable is an object variable representing the current form. It appears in the Locals window in Break mode.
  35. An array called intArray is displayed in the Locals window. You want to view the elements of this array, and each of the values contained. What can you do to view this information?
    1. Click the Plus sign beside the variable’s name.
    2. Click the Minus sign beside the variable’s name.
    3. Nothing. Each of the variables appear by default in the Locals window.
    4. Nothing. The variable is shown in the Locals window, but elements of the array can’t be shown.
      A. Clicking the Plus sign beside the variable's name (e.g. a structured variable, such as an array), will expand the structure. Doing so will allow you to view the elements in the array.
  36. Which file is included with your application to allow for the removal of your application from a user’s computer?
    1. SETUP.EXE
    2. SETUP1.EXE
    3. UNWISE.EXE
    4. ST6UNST.EXE
    5. Add/Remove Programs
      D. ST6UNST.EXE is added to your package, for application removal.
  37. You are packaging and deploying an application to floppy disk. You have a mix of different disks. Some are 1.44MB, others are 1.2MB. What must you do for packaging the application with different CAB sizes?
    1. On the Cab Options screen, choose Mix from the Cab Size listbox.
    2. On the Cab Options screen, select 1.44MB and 1.2MB.
    3. You can’t package using a mixture of CAB sizes.
    4. You can’t package on 1.2MB disks.
      C. You can't package using a mizture of CAB sizes. You must choose one size of cab when packaging your application for deployment to floppy disk
  38. You want to display the value of intNum in the Immediate window. Which of the following would be valid to use in the Immediate window to perform this action?
    1. ? intNum
    2. Print intNum
    3. Debug.Print intNum
    4. All of the Above
      A. (? intNum) and B. (Print intNum) can be used in the Immediate window to display the value of an expression. Debug.Print is used in a procedure’s code to display the value of an expression in the Immediate window.
  39. Your application loads a large database that takes a considerable amount of time to load. Which of the following can you do to let the user know the application hasn’t locked up when loading the database?
    1. Implement a splash screen
    2. Implement a progress bar that shows that the database is loading
    3. Set AutoRedraw to False
    4. Optimize the application for size
      A. (implement a splash screen) and B. (implement a progress bar that shows the database is loading). This question doesn’t specify at what point the database loads. If it is loading when the application starts, you could implement a splash screen. You could also add a progress bar at any point in the application to show the status of the loading database.
  40. You have decided to compile to native code and then set optimization settings for this to optimize for both speed and size. When you go to the Compile tab, you find you cannot. Why?
    1. You can only optimize for speed or size. You can’t optimize for both.
    2. Native code doesn’t offer optimization settings for compiling.
    3. You need to make these settings on the Make tab.
    4. None of the above.
      A. You can only optimize for speed or size. You can't optimize for both. When setting optimization settings for native code, you can optimize for speed, size, or neither. You can choose only one. You can’t optimize for both speed and size.