learn visual basic in 24 hours

By Virginia Murphy,2014-12-30 22:50
11 views 0
learn visual basic in 24 hours

    Learn Visual Basic in 24 hours

     Hour 1 Visual Basic at Work

     Hour 2 Analyzing Visual Basic Programs

     Hour 3 Controls and Properties

     Hour 4 Examining Labels, Buttons, and Text Boxes

     Hour 5 Putting Code into Visual Basic

     Hour 6 Improving Code: Message and Input Boxes

     Hour 7 Making Decisions

     Hour 8 Visual Basic Looping

     Hour 9 Combining Code and Controls

     Hour 10 List Boxes and Data Lists

     Hour 11 Additional Controls

     Hour 12 Dialog Box Basics

     Hour 13 Modular Programming

     Hour 14 Built-in Functions Save Time

     Hour 15 Visual Basic Database Basics

     Hour 16 Printing with Visual Basic

    Hour 1 Visual Basic at Work

    ; Visual Basic at Work

    ; Whats Visual Basic About?

    ; Languages

    ; Visual Basics Three Editions

    ; The VB Programming Process

    ; Starting Visual Basic

    o Figure 1.1.

    o Figure 1.2.

    ; Stopping Visual Basic

    ; Mastering the Development Environment

    o Figure 1.3.

    ; Standards: The Menu Bar and Toolbar

    o The Form Window: Where It All Happens

    ; Figure 1.4.

    ; Figure 1.5.

    o The Toolbox Supplies Controls

    ; Figure 1.6.

    o The Form Layout Window Places Forms

    o The Project Explorer Window

    ; Figure 1.7.

    o The Properties Window

    ; Help Is at Your Fingertips

    ; Summary

    ; Q&A

    ; Workshop

    o Quiz

    o Exercise

    Hour 1

    Visual Basic at Work Welcome to Visual Basic! You possess one of the most powerful and enjoyable

    Windows development tools available today. Visual Basic really is fun, as you'll see

    throughout this 24-hour tutorial. In this hour you will become familiar with the big

    picture of Visual Basic 5. The highlights of this hour include

    ; What Visual Basic does

    ; How to start Visual Basic

    ; How to stop Visual Basic

    ; When to use the different Visual Basic windows

    ; How the system windows work together for you

    Whats Visual Basic About?

    Controls are tools on the Toolbox window that you place on a form to interact with the user and control the program flow.

    Microsoft Visual Basic 5.0, the latest and greatest incarnation of the old BASIC language, gives you a complete Windows application development system in one package. Visual Basic (or VB, as we often call it) lets you write, edit, and test Windows applications. In addition, VB includes tools you can use to write and compile help files, ActiveX controls, and even Internet applications. New Term: A program is a set of instructions that make the computer do something such as perform accounting. (The term program is often used synonymously with application.)

    Visual Basic is itself a Windows application. You load and execute the VB system just as you do other Windows programs. You will use this running VB program to create other programs. VB is just a tool, albeit an extremely powerful tool, that programmers (people who write programs) use to write, test, and run Windows applications.

    New Term: A project is a collection of files you create that comprises your Windows application.

    Although programmers often use the terms program and application interchangeably (as will be done throughout this 24-hour course), the term application seems to fit the best when you're describing a Windows program because a Windows program typically consists of several files. These files work together in the form of a project. The project generates the final program that the user loads and runs from Windows by double-clicking an icon or by starting the application with the Windows Start menu. New Term: An application is a collection of one or more files that compile into an executable program.

    The role of programming tools has evolved over the past 45 years along with hardware. A programming language today, such as Visual Basic, differs greatly from programming languages of just a few years ago. The visual nature of the Windows operating system requires more advanced tools than were available a few years ago. Before windowed environments, a programming language was a simple text-based with which you wrote programs. Today you need much more than just a language; need a graphical development tool that can work inside the Windows system and applications that take advantage of all the graphical, multimedia, online, and multiprocessed activities that Windows offers. Visual Basic is such a tool. More than language, Visual Basic lets you generate applications that interact with every aspect today's Windows operating systems.

    NOTE: Although Visual Basic is a comprehensive programming tool, VB retains its BASIC language heritage. Designers in the late 1950s developed the BASIC programming language for beginning programmers. BASIC was easier to use than other programming languages of the time, such as COBOL and FORTRAN. never forgot VB's roots when developing Visual Basic. Newcomers to programming can learn to create simple but working Windows programs in just a short time. You be using Visual Basic to write Windows programs before the next hour is complete.

    New Term: Wizards are question-and-answer dialog boxes that automate tasks.

    New Term: A compiler is a system that converts the program you write into a computer-executable application.

    If you've taken a look at Visual Basic in the past, you'll be amazed at today's Visual Basic system. VB now sports a true compiler that creates standalone that execute more quickly than previous VB programs. VB also includes several wizards that offer step-by-step dialog box questions that guide you through the of applications. VB's development platform, a development environment called the

    Developer Studio, now supports the same features as the advanced Visual C++ and Visual J++ compilers. Therefore, once you learn one of Microsoft's Visual programming products, you will have the skills to use the other language products without a long learning curve ahead of you.

    New Term:The Developer Studio is Visual Basic's development environment.


    Programming languages today are not what they used to be. The language itself has not gotten less important; rather, the graphical interfaces to applications have gotten more important.

    A computer cannot understand any person's spoken language. A spoken language, such as Italian or English, is simply too general and ambiguous for computers to understand. Therefore, we must adapt to the machine and learn a language that the computer can understand. VB's programming language is fairly simple and uses common English words and phrases for the most part. The language is not ambiguous, however. When you write a statement in the Visual Basic language, the statement never has multiple meanings within the same context.

    New Term: Code is another name for the programming statements you write.

    As you progress through the next 24 hours, you will learn more and more of the Visual Basic language's vocabulary and syntax (grammar, punctuation, and spelling rules). You will use the VB programming language to embed instructions within applications you create. All the code you write (code is the program's instructions) must work together to instruct the computer. Code is the glue that ties all the graphics, text, and processes together within an application. Code tells a checkbook application, for example, how to be a checkbook application and not something else. The program code lets the application know what to do given a wide variety of possible outcomes and user actions.

    Visual Basics Three Editions

    Visual Basic 5 comes in three flavors: the Standard Edition, the Professional Edition, and the Enterprise Edition. Although this book primarily deals with the Professional Edition, the Standard Edition is called the learning edition and provides the least expensive approach to using Visual Basic. The Standard Edition gives you a complete development environment, programming language, and many of the same tools the

    other editions offer. If you use the Standard Edition, you have a powerful tool. Some people develop only with the Standard Edition and never need anything Although this course targets the Professional Edition in an attempt to hit common ground, you will be able to utilize virtually the entire 24-hour course if you use the Standard Edition; you will find additional tools in the Standard Edition that this does not even get to.

    The Professional Edition offers a few more tools, including extra ActiveX add-in tools, better Internet programming support, a help file compiler, and improved database access tools. Most professional programmers use the Professional Edition. The Enterprise Edition provides the client/server programmer with extended tools for remote computing and application distribution. Microsoft enhanced VB's performance for Enterprise Edition users working in a networked, distributed environment.

    TIP:Most programmers need only the Standard or Professional Edition. The Enterprise Edition is aimed at developers who write network-intensive client/server applications. The Enterprise Edition is enhanced to aid such programmers who work within the special client/server environments.

    If you want to create your own ActiveX controls, you will need the VB 5 Custom Control Edition that comes with the Professional and Enterprise Editions. If you use the Standard Edition, you're still in luck because the CD-ROM that comes with this book includes the VB 5 Custom Control Edition, which you can add to your Visual Basic folder and use to create ActiveX controls. Hour 21, "Visual Basic and ActiveX," describes more about the VB 5 Custom Control Edition.

    The VB Programming Process

    When you want to use Visual Basic, you'll follow these basic steps:

    1. Start Visual Basic.

    2. Create a new application or load an existing application. When you create a

    new application, you might want to use Visual Basic's VB Application Wizard

    to write your program's initial shell, as you'll do in the next hour.

    New Term: A bug is a program error that you must correct (debug) before your program executes properly.

    3. Test your application with the debugging tools Visual Basic supplies. The

    debugging tools help you locate and eliminate program errors (called bugs)

    that can appear despite your best efforts to keep them out.

    4. Compile your program into a final application.

    5. Quit Visual Basic.

    6. Distribute the application to your users.

    Rarely will you perform all these steps sequentially in one sitting. The six steps are not sequential steps, but stages that you go through and return to before completing your application.

    Starting Visual Basic

    You start Visual Basic from the Windows Start menu. The Visual Basic development environment itself usually appears on a submenu called Microsoft Visual Basic 5.0, although yours might be called something different due to installation differences. You will see additional programs listed on the Microsoft Visual Basic 5.0 submenu, but when you select Visual Basic 5.0 from the submenu, Visual Basic loads and appears on your screen.

    On most systems, Figure 1.1's dialog box appears as soon as you start Visual Basic. The dialog box lets you start the VB Application Wizard, edit an existing VB project, or select from a list of recent projects you've worked on, depending on the dialog box tab you click.

    As you can see at the bottom of the dialog box, you don't have to see the dialog box every time you start Visual Basic. If you click the option labeled Don't show this

    box in the future, Visual Basic will not display the opening dialog box when you start Visual Basic.

Figure 1.1. The New Project dialog box often appears when you start VB.

    NOTE:If you decide not to show the New Project dialog box for subsequent start-ups, you will still be able to access the dialog box's operations from VB's File menu.

    Once you close the dialog box, the regular Visual Basic screen appears. As Figure 1.2 shows, VB's opening screen can get busy! Figure 1.2 shows the Visual Basic development environment, the environment with which you will become intimately familiar soon. From this development environment you will create Windows

Figure 1.2. VB's screen looks confusing at first.

    Although the screen can look confusing, you can fully customize the Visual Basic screen to suit your needs and preferences. Over time, you will adjust the screen's window sizes and hide and display certain windows so that your Visual Basic screen's start-up state might differ tremendously from that of Figure 1.2.

    New Term: A dockable window is a window that you can resize and move to the sides of the screen and connect to other windows.

    TIP:Most of VB's windows are sizable and dockable, meaning you can connect them together, move them, and hide them.

    This hour's section titled "Mastering the Development Environment" explains the of the development environment and how to maneuver within it.

    Stopping Visual Basic

    You'll exit from Visual Basic and return to Windows the same way you exit most Windows applications: Select File|Exit, click Visual Basic's main window close button, press Alt+F4, or double-click VB's Control menu icon that appears in the upper-left corner of the screen.

    If you have made changes to one or more files within the currently open project (remember that a project is the collection of files that comprise your application), Visual Basic gives you one last chance to save your work before quitting to Windows.

    WARNING: Never power-off your computer without completely exiting Visual or you might lose some or all of your work for the current session.

    Mastering the Development Environment

    Learning the ins and outs of the development environment before you learn Visual Basic is somewhat like learning the parts of an automobile before you learn to drive; you might have a tendency to skip the terms and jump into the foray. If, however, you take the time to learn some of the development environment's more fundamental principles, you will be better able to learn Visual Basic. You then will be more comfortable within VB's environment and will have a better understanding of the related words when subsequent lessons refer to the windows and tools in the development environment.

    Figure 1.3 shows the Visual Basic development environment with many of the more important screen components labeled. As you can see from the menu and toolbar, Visual Basic looks somewhat like other Windows programs on the market. Many of Visual Basic's menu bar commands work just as they do in other applications such as Microsoft Word. For example, you can select Edit|Cut and Edit|Paste to cut and paste text from one location to another. These same menu bar commands appear on almost every other Windows program on the market today.

Figure 1.3. Getting to know the development environment.

    NOTE: Figure 1.3 shows only a portion of the development environment's windows and components. As you need additional tools, such as the Menu Editor, this tutorial describes how you access those tools.

    Standards: The Menu Bar and Toolbar

    Visual Basic's menu bar and toolbars work just as you expect them to. You can click or press a menu bar option's hotkey (for example, Alt+F displays the File menu) to see a pull-down list of menu options that provides either commands, another level of menus, or dialog boxes. Many of the menu options have shortcut keys (often called accelerator keys) such as Ctrl+S for the File|Save option. When you press an accelerator key, you don't first have to display the menu to access the option. The toolbar provides one-button access to many common menu commands. Instead of selecting Edit|Paste, for example, you could click the Paste toolbar button. As with most of today's Windows applications, Visual Basic supports a wide range of toolbars. Select View|Toolbars to see a list of available toolbars. Each one that is currently showing will appear with a checkmark by its name.

    TIP:As you begin to work with Visual Basic, pay attention to the form location and form size coordinates at the left of the toolbar buttons. These measurements, in twips (a twip is 1,440th of an inch, the smallest screen measurement you can adjust), determine where the Form window appears and its size. Twip values usually appear in pairs. The first location value describes the x-coordinate (the number of twips from the top of the screen) and the second value describes the y-coordinate (the number of twips from the left of the screen), with 0,0 indicating the upper-left corner of the screen. The first size value describes the width of the form, and the second size value describes the height of the form. Therefore, the size coordinate pair 1000,3000 indicates that the Form window will be 1,000 twips wide and 3,000 twips tall when the program runs. As you'll learn in the next section, the Form window is the primary window for the applications you write. The location and size coordinates describe the form's location and size when you run the application.

Report this document

For any questions or suggestions please email