












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Shows “building blocks”, not their use
1 Unit 3a Intro to Visual Basic average^ Class Get grade and number of gradesCompute sum Calculate average Display average
2 Unit 3a Intro to Visual Basic Average program Get Input Compute average of two inputs Display average Get first number Get second number Unit 3a Intro to Visual Basic CS 106 Computing Fundamentals II Intro to Visual Basic
4 Unit 3a Intro to Visual Basic
Full programming power
Sequence of instructions that execute is controlled by events triggered by activities on the GUI. This is called Event Driven Programming
Interface design, Coding, Testing & Debugging Visual Basic Introduction
5 Unit 3a Intro to Visual Basic
it will take hundreds of lines of code to generate such a GUI. Visual Basic Introduction
Unit 3a (^6) Intro to Visual Basic
Developed at Dartmouth in early 1960s, to provide non-science students access to computers Beginner's All-purpose Symbolic Instruction Code No GUI -- everything done at the command line Much like the “Toy C Program” from last lecture
Created by Microsoft in 1991 Visual Basic 2005 is similar to original VB, but more powerful History
10 Unit 3a Intro to Visual Basic Getting Started – New Project
11 Unit 3a Intro to Visual Basic Getting Started – New Project Step 1: Select New Project from File menu
Unit 3a (^12) Intro to Visual Basic Getting Started – New Project Step 2: select windows app. Step 3: Give your project a name (e.g., homework2); Don’t put spaces in the name. Step 4: Click OK.
13 Unit 3a Intro to Visual Basic Getting Started – New Project Step 5: Save your project using the Save All option from the File menu. Very Very important to do this!
14 Unit 3a Intro to Visual Basic Getting Started – New Project Step 6: Choose where to store your project. Use the Browse… button to find your CS106 folder and your homework subfolder. Step 7: Checkmark this box if it is not checkmarked. Step 8: Click the Save button.
Unit 3a (^15) Intro to Visual Basic Getting Started – New Project CS106 subfolder you created for homework 2 Solution folder created by VB Contents of solution folder Project folder created by VB Contents of project folder
19 Unit 3a Intro to Visual Basic
Provides controls to program execution Facilitates input and output Moving Around in the IDE
20 Unit 3a Intro to Visual Basic Contains a complete list of controls that can be used. Frequently used controls:
Moving Around in the IDE
Unit 3a Intro to Visual Basic 21
Moving Around in the IDE
22 Unit 3a Intro to Visual Basic
VB Controls Example: Form Window with Four Controls 23 Unit 3a Intro to Visual Basic To select a control, click on it. Sizing handles will appear when a control is selected. Text box Button Label List box VB Controls
Unit 3a (^24) Intro to Visual Basic Proximity line VB Controls
28 Unit 3a Intro to Visual Basic
Example: if you click on a text box, a cursor appears in the text box, and you can type into the text box. The text box is said to have the focus
VB Controls
29 Unit 3a Intro to Visual Basic Text Autosize Font ForeColor BackColor ReadOnly VB Controls Each control has a set of properties
Some often used properties are:
Unit 3a (^30) Intro to Visual Basic
display the Properties window for the selected control. VB Controls Categorized View Alphabetical View
31 Unit 3a Intro to Visual Basic Properties (^) Settings Selected control VB Controls
32 Unit 3a Intro to Visual Basic
(in Properties Window).
Unit 3a (^33) Intro to Visual Basic
But as programmers we want descriptive names like txtInputIncome to indicate a text box control that will be used to input income
Easier for programmer to reference control by descriptive name rather than generic name VB Controls
Unit 3a Intro to Visual Basic 37 VB Controls
Now pressing the “ Alt + C ” key has the same effect as pressing the button. Unit 3a Intro to Visual Basic 38 VB Controls The character that follows the ampersand
Unit 3a (^39) Intro to Visual Basic Used to identify the contents of a text box. Text property specifies caption. By default, label automatically resizes to accommodate caption on one line. When the AutoSize property is set to False, label can be resized manually. Used primarily to obtain a multi-rowed label. VB Controls
40 Unit 3a Intro to Visual Basic
VB Controls
41 Unit 3a Intro to Visual Basic
Add controls to the Form Window Set properties Configure the appearance of the controls
Software Development in VB
Unit 3a (^42) Intro to Visual Basic Method Name box Class Name box Page tab Get to the code window by double clicking on a control in the form design window Software Development in VB
46 Unit 3a Intro to Visual Basic Public Class frmDemo Private Sub txtFirst_TextChanged(...) Handles txtFirst.TextChanged ... End Sub End Class VB Events Event Procedure Outline:
47 Unit 3a Intro to Visual Basic Private Sub objectName_event(...)Handles objectName.event statements End Sub
(ByVal sender As System.Object, ByVal e As System.EventArgs) VB Events Header
Unit 3a (^48) Intro to Visual Basic Private Sub btnRed_Click(…) Handles btnRed.Click
can be changed. Private Sub Button_Press(…) Handles btnRed.Click VB Events
procedure changed But name of control did not change
49 Unit 3a Intro to Visual Basic Public Class frmDemo Private Sub txtFirst_TextChanged(...) Handles txtFirst .TextChanged txtFirst .ForeColor = Color.Blue End Sub End Class VB Events
50 Unit 3a Intro to Visual Basic
VB Events
Unit 3a (^51) Intro to Visual Basic Automatically pops up to give the programmer help in selecting properties and names. VB Events
Coding the Button Click Event (cont.) 55 Unit 3a Intro to Visual Basic VB Events Public Class frmDemo Private Sub txtFirst_TextChanged(...) Handles txtFirst.TextChanged txtFirst.ForeColor = Color.Blue End Sub Private Sub btnRed_Click(...) Handles btnRed.Click txtFirst.ForeColor = Color.Red End Sub End Class Final Event Procedure Code for Example 56 Unit 3a Intro to Visual Basic Private Sub txtFirst_Leave(...) Handles txtFirst.Leave txtFirst.ForeColor = Color.Black End Sub Private Sub txtFirst_TextChanged(...) Handles txtFirst.TextChanged txtFirst.ForeColor = Color.Blue End Sub Private Sub btnRed_Click(...) Handles btnRed.Click txtFirst.ForeColor = Color.Red End Sub VB Events
Unit 3a (^57) Intro to Visual Basic Private Sub Button_Click(...) Handles btnRed.Click, txtSecond.Leave txtFirst.ForeColor = Color.Red End Sub Event procedure can be invoked by two events. VB Events
58 Unit 3a Intro to Visual Basic
frmDemo.Text = "Demonstration"
VB Events