135x Filetype PDF File size 2.66 MB Source: www.csh.k12.ny.us
Chapter 3. Fundamentals of Programming in Visual Basic Page 1 of 114 [Page 41] Chapter 3. Fundamentals of Programming in Visual Basic (This item omitted from WebBook edition) 3.1 Visual Basic Controls 42 z Starting a New Visual Basic Program z A Text Box Walkthrough z A Button Walkthrough z A Label Walkthrough z A List Box Walkthrough z The Name Property z A Help Walkthrough z Fonts z Auto Hide z Positioning and Aligning Controls 3.2 Visual Basic Events 60 z An Event Procedure Walkthrough z Properties and Event Procedures of the Form z The Header of an Event Procedure 3.3 Numbers 73 z Arithmetic Operations z Variables z Incrementing the Value of a Variable z Built-In Functions: Math.Sqrt, Int, Math.Round z The Integer Data Type z Multiple Declarations file:///C:/Users/CTESORIERO14/AppData/Local/Temp/~hh50C3.htm 9/11/2013 Chapter 3. Fundamentals of Programming in Visual Basic Page 2 of 114 z Parentheses z Three Types of Errors 3.4 Strings 88 z Variables and Strings z Using Text Boxes for Input and Output z Concatenation z String Properties and Methods: Length Property and ToUpper, ToLower, Trim, IndexOf, and Substring Methods z The Empty String z Initial Value of a String z Option Strict z Internal Documentation z Line-Continuation Character 3.5 Input and Output 105 z Formatting Output with Format Functions z Formatting Output with Zones z Reading Data from Files z Getting Input from an Input Dialog Box z Using a Message Dialog Box for Output z Using a Masked Text Box for Input Summary 127 Programming Projects 128 [Page 42] 3.1. Visual Basic Controls file:///C:/Users/CTESORIERO14/AppData/Local/Temp/~hh50C3.htm 9/11/2013 Chapter 3. Fundamentals of Programming in Visual Basic Page 3 of 114 Visual Basic programs display a Windows-style screen (called a form) with boxes into which users type (and in which users 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 also known as applications, solutions, or projects. Each program is saved (as several files and subfolders) in its own folder. Before starting a new program, you should use Windows Explorer to create a folder to hold the folders for your programs. The process for invoking Visual Basic 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 button, hover over All Programs, and then click on Microsoft Visual Basic 2005 Express Edition. With the other editions of Visual Basic, hover over All Programs, hover over Microsoft Visual Studio 2005, and then click on Microsoft Visual Studio 2005 in the short list that is revealed. The window that appears after Visual Basic is invoked has a menu bar whose first 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 Basic contain a pane identifying a Project type. You should select "Visual Basic" as the Project type.) Figure 3.1. The Visual Basic Express New Project input dialog box. (This item is displayed on page 43 in the print version) [View full size image] Note: The number of project types and icons showing will vary depending on the version of Visual Basic you are using. Figure 3.1 was created from the Express Edition. file:///C:/Users/CTESORIERO14/AppData/Local/Temp/~hh50C3.htm 9/11/2013 Chapter 3. Fundamentals of Programming in Visual Basic Page 4 of 114 The name of the program, initially set to WindowsApplication1, can be specified at this time. Since we will have a chance to change the name later, let's just call the program WindowsApplication1 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 somewhat, from Figure 3.2. The Visual Basic programming environment is often referred to as the IDE (Integrated Development Environment). Figure 3.2. The Visual Basic programming environment. (This item is displayed on page 43 in the print version) [View full size image] The Menu bar of the IDE displays the commands you use to work with Visual Basic. 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 clicked. For example, you can use the fifth icon, which looks like a stack of three diskettes, to save the files associated with the current program. To reveal the purpose of a Toolbar icon, hover the mouse pointer over the icon for a few seconds. The little information rectangle that pops up is called a tooltip. In Figure 3.2, the Main area currently holds the Windows Form Designer. The rectangular Form window, or form for short, becomes a Windows window when a program is executed. Most information displayed by the program appears on the form. The information usually is displayed in controls that the programmer has placed on the form. [Page 44] The Solution Explorer window is used to display various parts of a program. The Properties window is used to change how objects look and react. The Toolbox holds icons representing controls that can be placed on the form. These controls are file:///C:/Users/CTESORIERO14/AppData/Local/Temp/~hh50C3.htm 9/11/2013
no reviews yet
Please Login to review.