outline (2/2) lesson 1: a first look at visual...
TRANSCRIPT
Dr. Adriana Badulescu Kallas Beginning Programming I
1
Session 2
Dr. Adriana Kallas
Outline (1/2)Session Lesson Unit
1
Course Orientation Orientation
Lesson 1: Introducing Programming Logic and Languages
Unit 1: Introducing Programming Logic and Languages
2Lesson 1: A First Look at Microsoft Visual Basic
Unit 2: Introduction to Visual Basic
Lesson 2: Forms, Controls and PropertiesLesson 3: Events and Code
3
Lesson 4: Mathematical OperatorsLesson 5: Exponentiation, Order of Operations, and Error HandlingLesson 6: Data Types and Variables
4
Lesson 7: Strings and Decimal TypesLesson 8: If StatementsLesson 9: Nested If Statements and Option Buttons
Outline (2/2)Session Lesson Unit
5
Lesson 10: Do Loops Unit 2: Introduction to Visual Basic
Lesson 11: For Next Loops and Multiple Forms
6Lesson 1: Entering, Compiling, and Running a C++ Program
Unit 3: Introduction to C++
Lesson 2: Variables and ConstantsLesson 3: Math Operations
7Lesson 4: How Data Types Affect CalculationsLesson 5: Strings and the String Class
8Lesson 6: Input and OutputLesson 7: Building Blocks of Decision Making
9Lesson 8: Selection StructuresLesson 9 : Loops
10Lesson 10: Building Programs with FunctionsLesson 11: Passing Data and Using Library Functions
Lesson 1: A first Look at Visual Basic
Explains the purpose of Microsoft Visual Basic
Describe the types of projects and templates
How to start the Visual Basic compiler
Open an existing project
Run a program
Position a form in a Visual Basic program
Visual Basic Programming EnvironmentTitle BarTitle Bar
Menu BarMenu Bar
ToolbarToolbar
ToolboxToolboxSolution Solution ExplorerExplorer
Properties Properties WindowWindow
FormForm
Open and Run an Existing Project
OpenOpen BuildBuild DebugDebug RunRun
Menus
Toolbar
Dr. Adriana Badulescu Kallas Beginning Programming I
2
Open and Run an Existing ProjectTitle BarTitle Bar
Menu BarMenu Bar
ToolbarToolbar
ToolboxToolboxSolution Solution ExplorerExplorer
Properties Properties WindowWindow
FormForm
Open and Run an Existing Project
Upgrade Projects from Previous Versions Projects from older versions needs to be
upgraded to Visual Basic 2010 before they can be open
Lesson 2: Forms, Controls, and Properties Create a new Visual Basic project
Save a project
View and modify form properties
Create controls and command buttons
Move and resize objects
Set some additional properties
Creating a New Project
BuildBuild DebugDebug RunRun
Menus
Toolbar
NewNew SaveSave
Project Types in Visual Basic Visual Basic enables you to create several types of
applications. This includes Windows Forms applications, Windows Presentation Foundation applications, console applications, and class libraries. Each application that you create is contained in its own project, and project templates are provided to help you get started. When you create a new project, icons in the New Project dialog
box and Add Project dialog box represent the available project types and their templates. The following project templates are available when you open a new project in Visual Basic Express.
Dr. Adriana Badulescu Kallas Beginning Programming I
3
Project Templates in Visual Basic Windows Application Template
Used to create Windows-based applications that run locally on users' computers. The applications can be anything from simple single-window tools like Windows Calculator to advanced multiple windows applications.
WPF (Windows Presentation Foundation) Application Used to create stand-alone WPF applications.
Console Application Template Used to create command-line applications, programs that run from a Windows
command prompt and have no visual interface.
Class Library Template Used to create reusable classes or components that can be shared with multiple
projects.
WPF Browser Application Used to create browser-hosted WPF applications.
Project Templates in Visual Basic
Windows Application Windows-based applications that run locally on
users' computers.
The applications can be anything from simple single-window tools like Windows Calculator to advanced multiple windows applications.
Console Application Are typically designed without a graphical user interface and
compiled into a stand-alone executable file. A console application is run from the command line with input
and output information being exchanged between the command prompt and the running application.
Projects, Forms, and Controls To create your own Visual Basic program, you must
create a new project. The Standard EXE project type allows you to create a program from scratch. Every program has at least one form. All other objects
must be contained within forms. Controls are the command buttons, text boxes, scroll
bars, and other objects that make up the user interface.
A Form With Controls and Properties
Dr. Adriana Badulescu Kallas Beginning Programming I
4
Control Toolbox ControlsFunction Control Description
Data display DataGridViewThe DataGridView control provides a customizable (cells, rows,columns, and borders) table for displaying data.
Text editing
TextBoxDisplays text entered at design time that can be edited by usersat run time, or changed programmatically.
RichTextBoxEnables text to be displayed with formatting in plain text orrich-text format (RTF).
MaskedTextBox Constrains the format of user input
Informationdisplay
Label Displays text that users cannot directly edit.
LinkLabelDisplays text as a Web-style link and triggers an event when theuser clicks the special text. Usually the text is a link to anotherwindow or a Web site.
StatusStripDisplays information about the application's current state usinga framed area, usually at the bottom of a parent form.
ProgressBar Displays the current progress of an operation to the user.Web pagedisplay
WebBrowser Enables the user to navigate Web pages inside your form.
ControlsFunction Control Description
Selectionfrom a list
CheckedListBoxDisplays a scrollable list of items, each accompanied by a checkbox.
ComboBox Displays a drop-down list of items.
DomainUpDownDisplays a list of text items that users can scroll through with upand down buttons.
ListBox Displays a list of text and graphical items (icons).
ListViewDisplays items in one of four different views. Views include textonly, text with small icons, text with large icons, and a detailsview.
NumericUpDownDisplays a list of numerals that users can scroll through with upand down buttons.
TreeViewDisplays a hierarchical collection of node objects that canconsist of text with optional check boxes or icons.
Graphicsdisplay
PictureBox Displays graphical files, such as bitmaps and icons, in a frame.
ControlsFunction Control Description
Graphicsstorage
ImageListServes as a repository for images. ImageList controls and theimages they contain can be reused from one application to thenext.
Valuesetting
CheckBoxDisplays a check box and a label for text. Generally used to setoptions.
CheckedListBoxDisplays a scrollable list of items, each accompanied by a checkbox.
RadioButton Displays a button that can be turned on or off.
TrackBarAllows users to set values on a scale by moving a "thumb" alonga scale.
Datesetting
DateTimePickerDisplays a graphical calendar to allow users to select a date or atime.
MonthCalendarDisplays a graphical calendar to allow users to select a range ofdates.
ControlsFunction Control Description
Dialogboxes
ColorDialogDisplays the color picker dialog box that allows users to set thecolor of an interface element.
FontDialogDisplays a dialog box that allows users to set a font and itsattributes.
OpenFileDialogDisplays a dialog box that allows users to navigate to andselect a file.
PrintDialogDisplays a dialog box that allows users to select a printer andset its attributes.
PrintPreviewDialogDisplays a dialog box that displays how a controlPrintDocument component will appear when printed.
FolderBrowserDialog
Displays a dialog that allows users to browse, create, andeventually select a folder
SaveFileDialog Displays a dialog box that allows users to save a file.
Menucontrols
MenuStrip Creates custom menus.
ContextMenuStrip Creates custom context menus.
ControlsFunction Control Description
Commands
Button Starts, stops, or interrupts a process.
LinkLabelDisplays text as a Web-style link and triggers an event when theuser clicks the special text. Usually the text is a link to anotherwindow or a Web site.
NotifyIconDisplays an icon in the status notification area of the taskbarthat represents an application running in the background.
ToolStrip
Creates toolbars that can have a Microsoft Windows XP,Microsoft Office, Microsoft Internet Explorer, or custom lookand feel, with or without themes, and with support foroverflow and run-time item reordering.
User Help
HelpProvider Provides pop-up or online Help for controls.
ToolTipProvides a pop-up window that displays a brief description of acontrol's purpose when the user rests the pointer on thecontrol.
Dr. Adriana Badulescu Kallas Beginning Programming I
5
ControlsFunction Control Description
Groupingothercontrols
Panel Groups a set of controls on an unlabeled, scrollable frame.
GroupBoxGroups a set of controls (such as radio buttons) on a labeled,nonscrollable frame.
TabControlProvides a tabbed page for organizing and accessing groupedobjects efficiently.
SplitContainer Provides two panels separated by a movable bar.
TableLayoutPanelRepresents a panel that dynamically lays out its contents in agrid composed of rows and columns.
FlowLayoutPanelRepresents a panel that dynamically lays out its contentshorizontally or vertically.
Audio SoundPlayerPlays sound files in the .wav format. Sounds can be loaded orplayed asynchronously.
Form with Controls
A Form With Controls
ButtonButton
PanelPanel
PictureBoxPictureBox
LabelLabel
Properties Properties are the
characteristics of Visual Basic objects. Properties can be modified in
the Properties window. Example: Caption - controls what the
user sees in the title bar of a form and other objects such as command buttons.
Name property - allows us to refer to the object using a meaningful name.
A Form With Controls and Properties
Name
Text
Image
BackColor
ForeColor
pbSmiley
pGame
bStart bStop bQuit
bUp
bDown
bLeft bRight
Lesson 3: Events and Code
Events in Visual Basic
Access the Code Windows
Add code to a command button
Set image properties
Create a standalone Windows applications
Dr. Adriana Badulescu Kallas Beginning Programming I
6
Examine Events and Code Windows is an event-driven environment. In an event-driven
system, the user triggers events that control the work. To control what happens when an event occurs, you must write
event procedures for each event that you want to handle. To access the Code window, double-click an object such as a
command button. The code you write in Visual Basic is written in sections called subroutines.
Using the Name property, you can give an image control a name. That name will be used when you refer to the control in code.
Setting properties from code is one of the most common uses for Visual Basic code. Setting properties from code allows you to change properties while a program runs. To change an object's properties from code, you send a message to the object.
Examine Events and Code
A Form With Controls, Properties, and Events
Click eventClick event
Event CodePrivate Sub bStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bStart.Click
pbSmiley.Visible = True
pGame.Visible = True
bUp.Visible = TruebDown.Visible = True
bLeft.Visible = True
bRight.Visible = True
End SubPrivate Sub bStop_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bStop.Click
pbSmiley.Visible = FalsepGame.Visible = False
bUp.Visible = False
bDown.Visible = False
bLeft.Visible = FalsebRight.Visible = False
End Sub
Private Sub bQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bQuit.Click
End
End Sub
bDown
Event CodePrivate Sub bUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bUp.ClickIf (pbSmiley.Top < 100)
Then pbSmiley.Top = 5
Else pbSmiley.Top = pbSmiley.Top – 100End If
End Sub
Private Sub bLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bLeft.Click
If (pbSmiley.Left < 100) Then pbSmiley.Left = 5Else pbSmiley.Left = pbSmiley.Left – 100
End IfEnd Sub
Event CodePrivate Sub bDown_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bDown.ClickIf (pbSmiley.Top + 50 >= 400 - pbSmiley.Height - 5)
Then pbSmiley.Top = IndentMax - pbSmiley.Height – 5
Else pbSmiley.Top = pbSmiley.Top + 50End If
End Sub
Private Sub bRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bRight.Click
If (pbSmiley.Left + 50 >= 400 - pbSmiley.Width - 5) Then pbSmiley.Left = IndentMax - pbSmiley.Width – 5Else pbSmiley.Left = pbSmiley.Left + 50
End IfEnd Sub
Dr. Adriana Badulescu Kallas Beginning Programming I
7
Visual Studio Download
Visual Studio Express is a set of freedevelopment tools Visual Basic Express
Visual C++ Express Visual C# Express
Visual Web Developer Express
http://www.microsoft.com/express/Windows/
Register your product within 30 days from installation.
Additional Learning Resources MSDN Introduction to the Visual Basic Programming
Language http://msdn.microsoft.com/en-us/beginner/bb308733.aspx This beginner's guide is designed for people with little or no prior
knowledge of computer languages, who want to learn to program by using the Visual Basic language .
In this guide you will learn how to create a simple program. Your program will include basic but essential programming techniques such as methods, variables, controlling program flow, and how to create your own classes – the fundamental structural units of a Visual Basic computer program.
Summary Using Microsoft Visual Basic, types of projects
and templates, Visual Basic compiler, opening and running a projects
Create and saving a new Visual Basic project, view, modify, and create objects, controls, and properties
Working with events, code, and
Create a standalone Windows applications
Additional learning resources