Vous êtes sur la page 1sur 87
Fundamentals of Programming in Visual Basic 3A 32 33 34 35 Visual Basic Controls 42 + Starting a New Visual Basic Progeam # A Text Box Walkthrough # A Button Walkthrough + A Label Walkthrough + A List Box Walkthrough « The Name Property + A Help Walkthrough ¢ Fonts « Auto Hide + Positioning and Aligning Controls Visual Basic Events 60 + An Bvent Procedure Walkthrough « Properties and Event Procedures of the Form + The Header of an Event Procedure Numbers 73 + Arithmetic Operations © Variables # Incrementing the Value of a Variable + Built-In Functions: Math.Sqrt, Int, Math.Round ¢ The Integer Data Type + Multiple Declarations # Parentheses « Three Types of Errors Strings 88 + Variables and Strings + Using Text Boxes for Input and Ourpur ¢ Coneatenation + String Properties and Methods: Length Property and ToUpper, ToLower, Trim, IndexO¥, and Substring Methods « The Empty String # Initial Value of a String + Option Strier « Internal Documentation « Line-Continuation Character Input and Output 105 + Formatting Output with Format Functions + Formatting Output with Zones + Reading Data from Files ¢ Getting Input from an Input Dialog Box Using a Message Dialog Box for Output ¢ Using a Masked Text Box for Input Summary 127 2 Chapter 3 Fundamentals of Programming in Visual Basic 1 ual Basic Controls ‘Visual Basic programs display a Windows-style screen (called a form) with boxes into which users type (and in which usets edit) information and buttons that they click to initiate actions. The boxes and buttons are ‘referred to as controls, In this section, we ‘examine forms and four of the most useful Visual Basic controls, @ Starting a New Visual Basic Program For our purposes, Visual Basic programs are alko known as applications, solutions, or projects. Each program is saved (as several files and subfolders) in its own folder. Before Farting a new program, you should use Windows Explorer to create a folder ro hold the folders for your programs. “The proces for invoking Visual Basie varies slightly with the edition of Visual Basic installed on the computer. To invoke Visual Basic from a computer that has Visual Basic Express installed, click the Windows Start burton, hover over All Programs, and then lick on Microsoft Visual Basic 2005 Express Edition. With the other editions of Visual Basic, hover over All Programs, hover over Microsoft Visual Stulio 2005, and then click con Microsoft Visual Studio 2005 in the shore list that is revealed. “The window that appears after Visual Basic is invoked has a menu bar whose fist item is “File”, Click on File, and then click on New Project to produce a New Project input dialog box. Figure 3.1 shows the New Project input dialog box produced by Visual Basic Express. The “Windows Application” icon should be selected as the installed template. If this is not the case, click on “Windows Application” to select it. (The Other editions of Visual Basie contain a pane identifying a Project type. You should se- lect “Visual Basic” as the Project type-) Note: The number af project types and icons showing will vary depending on the ver- ‘ion of Visual Basie you are using, Figure 3.1 was created from the Express Edition. ‘The name of the program, initially set to WindowsApplicationl, can be specified at this time. Since we will have a chance to change the name later, lets just call the program WindowsApplication] for now. Click on the OK button to invoke the Visual Basic programming environment. See Figure 3.2, Note: Your screen will resemble, but may differ somewhar, from Figure 3.2. The Visual Basic programming environment is often teferred to as the IDE (Integrated Development Environment). “The Menu bar of the IDE displays the commands you use to work with Visual Basie. Some of the menus, like File, Edit, View, and Window, are common to most Windows applications. Others, such as Project, Build, and Debug, provide commands specific to programming in Visual Basic. The Toolbars hold a collection of icons that carry out standard operations when licked. For example, you can use the fifth icon, which looks like a stack of three Slskettes, to save the files associated with the current program. To reveal the purpose of 4 Toolbar icon, hover the mouse pointer over the icon for a few seconds. The little information rectangle that pops up is called a tooltip. Tn Figure 3.2, the Main area currently holds the Windows Form Designer. The rec- 3.1 Visual Basic Controls #43 FIGURE 3.1. ‘The Visual Basic Express New Project input dialog box.

Vous aimerez peut-être aussi