05 09 V2DJIZMEILH4M4SJI747MNRM6BX6Z3JEKQ43FQI




Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Visual Design + Basic Code = Visual Basic
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




When you select the Native Code option, you have several more options available. The ones you need to know about are listed here:


•  Optimize for Fast Code—Compiles so that program execution speed is maximized, possibly at the expense of EXE file size.

Figure 5.10  The Compile tab in the Project Properties dialog box.

•  Optimize for Small Code—Compiles so that EXE file size is minimized, possibly at the expense of program execution speed.
•  Favor Pentium Pro—Creates an executable that is optimized for best performance when run on a Pentium Pro system but may run slower on other systems.

If you are unsure of which compilation options to choose, I suggest that you select the Compile to Native Code and the Optimize for Fast Code options.

Variable Scope
Before ending this chapter, we need to explore the concept of variable scope. The scope of a variable refers to the parts of the program where it is visible. When a variable is not visible, or is out of scope, it may as well not exist. True, it still exists, but somewhere out of your reach. You won’t be able to access it again until it comes back in scope. The concept of scope applies to procedures also.
What do I mean by “parts” of a program? In a Visual Basic module, some code is contained in procedures (both general and event procedures) and is called procedure level code. Most of the code in the Calculator project is procedure level code. Other code (such as Calculator’s Const declarations) exists outside any procedure and is called module level code. Because some Visual Basic programs contain more than one module, identifying which one the module code is within is also important.
The location of a variable’s declaration (its Dim statement) is one factor that determines the scope of a variable. If you declare a variable inside a procedure, its scope is limited to that one procedure. Module level code cannot access it, nor can code in other procedures. Such variables are called local variables, because their scope is local to the procedure where they are declared. In fact, different procedures can have local variables of the same name. They exist as totally independent variables because their scopes do not overlap. For example, we used a variable named Result in more than one procedure in the Calculator project.
If you declare a variable in module level code, its scope is determined by the keyword used to declare it. If you use the Dim statement or use the Private keyword, the scope of the variable will be limited to that single module. Thus, the following two statements in module level code have the same effect: declaring a variable whose scope is limited to that one module:


Dim X As Integer
Private Y As Double


If you use the Public keyword in a module level declaration, the variable’s scope will be the entire project (all modules). You can also use the Global keyword with the same effect:


Public X As Integer
Global Y As Double


You cannot use the Public or Global keywords within a procedure.
You may wonder why programmers don’t simply make all their programs’ variables public—why worry about scope? Bad idea! Don’t look at scope as a restriction, but as a tool that helps you create bug-free programs. The ability to hide variables in procedures from the rest of the program is a major component of the power of structured programming. With local variables, a procedure can be completely independent from the rest of the program. It receives information via its arguments, and returns information (if it is a function) via its return value. No other part of the program can screw up what goes on in the procedure. Likewise, what goes on in the procedure cannot screw up the rest of the program. The rule to follow is to use local variables as much as possible. Public variables should be reserved for situations where they are really needed.
The Visual Basic Application Wizard
If you have used Microsoft software products, you may have encountered wizards. A wizard is a tool that helps you perform some task. Typically, a wizard walks you through a series of steps, asking you questions and offering choices related to the task at hand. Then, it carries out the specified actions, performing a lot of work that you would otherwise have to perform yourself.
One of Visual Basic’s neatest features is the Application Wizard. It takes you through the steps of creating a Visual Basic application; then, based on your responses, it creates the skeleton of the program. You must still write the code and design the forms that provide the application’s unique functionality, but a lot of the busy work—such as menus and toolbars—will be done for you (at least in their basic form).
Using the Application Wizard—or any wizard—is a fairly simple matter. I will not attempt to explain all the choices that the wizard offers you, for two reasons. First, the wizard dialog boxes are usually quite clear, with explanatory notes for the various choices. You’ll probably be able to figure out most, if not all, of the options on your own. Secondly, some of the project choices offered by the wizard—such as menus and multiple versus single document interfaces—have not been covered yet. Therefore, I will explain the basics of using the Application Wizard without going into the details. As you read further in the book, you can experiment on your own to explore its full capabilities.
To start the Application Wizard, display the New Project dialog box by selecting New Project from the File menu. Select the Visual Basic Application Wizard icon and click on OK. The wizard will display the first of its dialog boxes (an example is shown in Figure 5.11).
While the details of each wizard dialog box differ, they all have the following buttons:

•  Next—Proceeds to the next wizard step. If you are at the last step, this button is not available.
•  Back—Returns to the previous wizard step, enabling you to change entries you made. If you are at the first step, this button is not available.
•  Cancel—Terminates the wizard without creating the application.
•  Finish—Closes the wizard and creates the application. If you click on Finish before going through all of the wizard steps, the wizard will create the application using the default settings for those dialog boxes that you did not visit.
•  Help—Displays online help information related to the current wizard dialog box and its choices.

Once the wizard has completed its work, you will have the basis for your Visual Basic application with all of the selected elements in place. A wizard-created application is the same as one that you created yourself—just a lot easier. One nice touch is that the wizard can insert “to do” comments in the code, reminding you of the code that needs to be added for various functions.


Figure 5.11  One of the Application Wizard dialog boxes.

What Now?
With the completion of this chapter, you have finished the first part of the book. You’ve come a long way and learned a lot. The material we have covered so far has enabled you to do a great deal with Visual Basic, but we haven’t even touched on a lot of important stuff: menus, common dialogs, class modules, and much more. From here on, however, the approach will be much less general. Each chapter will delve into a specific area where you might want to apply Visual Basic—text processing and multimedia are two examples. We’ll deal with the remaining Visual Basic tools as we go along.




Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.



Wyszukiwarka

Podobne podstrony:
Sonnax multiple applications 05 09
05 09 2012 INTERNA(1)
TI 02 05 09 B pl(1)
Rachunkowosc zadania 05 09
Pytania 3 termin 05 09 12
laborki cwiczenia  05 09
Test z neurologii 29 05 09
egzamin 05 09 07
v 05 09

więcej podobnych podstron