Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Basic Chapter 1 Mr. Wangler.

Similar presentations


Presentation on theme: "Visual Basic Chapter 1 Mr. Wangler."— Presentation transcript:

1 Visual Basic Chapter 1 Mr. Wangler

2 Visual Basic Windows Programming
Visual Basic is used to create Windows, Web, and command line applications. An application makes the computer a useful tool by enabling the user to perform a task, such as word processing. Buttons, check boxes, and text boxes are common objects in a Windows application.

3 Object Oriented Programming Language (OOP)
Visual Basic language is an object oriented programming language Objects – appear on the screen (buttons, check boxes, ….)

4 Event-Driven Applications
Performing tasks with objects is the basis of an OOP application. A Windows application is event-driven. Event-Driven application – executes code in response to events. Event – can occur when the user interacts with an object, such as clicking a button.

5 Projects Project – contains all files required to execute an application. Design Window (Form) – displays the application interface where objects are added, deleted, and sized. Toolbox – contains controls that are used to create objects. Solution Explorer Window – is used to switch between the Design and Code Window

6 Projects continued… Properties Window – lists the properties of a selected object. Properties – defines its appearance, behavior, position, and other attributes.

7 Windows Form A Windows application interface includes at least one form. A form is a graphical object that contains a title bar, a system menu, and Minimize, Maximize, and Close buttons. A new Visual Basic Windows application automatically includes on Form object.

8 Windows Form continued…
A Form object has properties just like a tool that define its appearance, behavior, position, and other attributes. The Text property of a form defines what is displayed in its title bar. Pressing Enter or clicking outside the Properties window applies the new Text property value to the Form.

9 Control Objects The Toolbox in Visual Basic contains controls.
Control – is used to add objects to a form. Control Objects – display information or get user input.

10 The Label Control Properties
Name – identifies a control for the programmer. It is good programming style to begin Label object names with lbl. Text – is the text displayed in the label. Font – controls the font style and size of the text. Text Alignment – is the alignment of text in a label.

11 Good Programming Style
For most objects, the Name property should always be set to a descriptive name. A proper name begins with the appropriate prefix and then describes the purpose of the object. Following proper naming conventions is GOOD PROGRAMMING STYLE.

12 Saving an Application After the first time selecting Save from the File menu or clicking on the Save button will save your project. An application should be saved frequently to avoid losing changes.

13 Running an Application
To run an application click the Start button (Play button) on the toolbar or select Start from the Debug menu. To terminate a running application, click the Stop Debugging button or select Stop Debugging from the Debug menu. Running an application means that a program is first converted to a language the computer understands in a process called compiling.

14 Main Menu Control Prefix for Main Menu: mnu
Windows applications typically include menus that contain commands. A menu is modified in the Design window by clicking a MenuItem object and typing a new name.

15 Program Code Applications contains sets of instructions called program code. Program Code – tells the computer how to perform tasks. Each line of code is called a statement. In Visual Basic some code is automatically generated for a form and the objects on the form.

16 Event Procedure Procedure - is a block of code written to perform specific tasks. Event Procedure – is a type of procedure that performs tasks in response to user interaction with an object.

17 Assignment Statements
Assignment Statement – used in a procedure to change a value at run time. One use of assignment statements is to set an object property at run time.

18 Assignment Statements cont…
Object.Property = Value Object = the control object name Property = the name of a property for that object Value = is a valid property setting

19 Assignment Statements cont…
A dot(.) is required between Object and Property to access the property. The equal sign (=) assigns the property on the left of the equal sign the value on the rights of the equal sign. Assignment Statements allow a single label to display different text at run time.

20 AutoList When a dot (.) is typed in a statement, an AutoList of options is displayed. The options displayed in an AutoList depend on what was typed just before the dot. Me is used in the assignment statement so that object names are displayed when a dot is typed. Me refers to the Form object. Selecting from an AutoList can reduce typing errors in code. AutoList is also a good way to choose values in an assignment statement.

21 RadioButton Control A group of radio buttons is often used in an application to enable the user to choose from a set of options. Name = prefix = rad Text = text displayed next to the button Checked = can be set to either True or False to display the radio button as selected or not.

22 RadioButton cont… Only one radio button in a group can be checked at any given time. Therefore, changing the Checked value of one button to True automatically changes the other buttons in the group to False. The click event procedure executes when the user clicks a button.

23 GroupBox A GroupBox is used to group related radio buttons.
A GroupBox object must be added to a form before adding RadioButton objects. Radio buttons are then added to the group box by clicking the RadioButton control and the clicking the group box.

24 GroupBox cont… Dragging a group box moves it and all the controls within it together. Name = prefix = grp Text = is the text displayed at the top of the group box.

25 Commenting Code Comments are used to explain and clarify program code for other programmers. Comments have no effect on the way an application runs. The single quotation mar (‘) must begin a comment. Anything after the single quotation mark is considered a comment for that line of the program only.

26 Commenting Code cont… Multiline comments can be created by placing a quotation mark at the beginning of each line. Comments are good programming style and should be used wherever code may be confusing.

27 Arithmetic Operators Visual Basic.NET includes a set of built-in arithmetic operators for: Exponentiation (^) Multiplication (*) Division (/) Addition (+) Subtraction (-)

28 Numeric Expressions Arithmetic operators are used to form a numeric expression. A numeric expression is not enclosed in quotation marks because quotation marks indicate text. Since a label displays text, the value is automatically converted to text.

29 Operator Precedence Visual Basic evaluates a numeric expression using a specific order of operations, or operator precedence. 1. Exponentiation 2. Multiplication and Division 3. Addition and Subtraction

30 Operator Precedence cont…
Two operators of the same precedence, for example + and -, are evaluated in order from left to right. The operators within parentheses are evaluated first. It is good programming style to include parentheses when there is any confusion or question about the numeric expression.

31 ButtonControl The button is commonly used in Windows application interfaces. Name = prefix = btn Text = is the text displayed on the button A click event procedure is usually coded for a Button object and executes when the user clicks the button.

32 THE END.


Download ppt "Visual Basic Chapter 1 Mr. Wangler."

Similar presentations


Ads by Google