Dr. Adriana Badulescu Kallas Beginning Programming I Outline (1/ - - PDF document

dr adriana badulescu kallas beginning programming i
SMART_READER_LITE
LIVE PREVIEW

Dr. Adriana Badulescu Kallas Beginning Programming I Outline (1/ - - PDF document

Dr. Adriana Badulescu Kallas Beginning Programming I Outline (1/ 2) Session Lesson Unit Course Orientation Orientation Unit 1: Introducing 1 Lesson 1: Introducing Programming Logic and Programming Logic Languages and Languages Session


slide-1
SLIDE 1
  • 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 2 Lesson 1: A First Look at M icrosoft Visual Basic Unit 2: Introduction to Visual Basic Lesson 2: Forms, Controls and Properties Lesson 3: E vents and Code 3 Lesson 4: M athematical Operators Lesson 5: Exponentiation, Order of Operations, and Error Handling Lesson 6: Data Types and Variables 4 Lesson 7: Strings and Decimal Types Lesson 8: If Statements Lesson 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 M ultiple Forms 6 Lesson 1: Entering, Compiling, and Running a C++ Program Unit 3: Introduction to C++ Lesson 2: Variables and Constants Lesson 3: M ath Operations 7 Lesson 4: How Data Types Affect Calculations Lesson 5: Strings and the String Class 8 Lesson 6: Input and Output Lesson 7: Building Blocks of Decision M aking 9 Lesson 8: Selection Structures Lesson 9 : Loops 10 Lesson 10: Building Programs with Functions Lesson 11: Passing Data and Using Library Functions

Lesson 1: A first Look at Visual Basic

  • Explains the purpose of M icrosoft 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 Environment

Title Bar Title Bar Menu Bar Menu Bar T

  • olbar

T

  • olbar

T

  • olbox

T

  • olbox

S

  • lution

S

  • lution

Explorer Explorer Properties Properties Window Window Form Form

Open and Run an Existing Project

Open Open Build Build Debug Debug Run Run

Menus Toolbar

slide-2
SLIDE 2
  • Dr. Adriana Badulescu Kallas

Beginning Programming I 2

Open and Run an Existing Project

Title Bar Title Bar Menu Bar Menu Bar T

  • olbar

T

  • olbar

T

  • olbox

T

  • olbox

S

  • lution

S

  • lution

Explorer Explorer Properties Properties Window Window Form Form

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
  • M ove and resize objects
  • Set some additional properties

Creating a New Project

Build Build Debug Debug Run Run

Menus Toolbar

New New S ave S ave

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.

slide-3
SLIDE 3
  • 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.

  • Controlsare the command buttons, text boxes, scroll

bars, and other objects that make up the user interface.

A Form With Controls and Properties

slide-4
SLIDE 4
  • Dr. Adriana Badulescu Kallas

Beginning Programming I 4

Control Toolbox Controls

Function Control Description Data display DataGridView The DataGridView control provides a customizable (cells, rows, columns, and borders) table for displaying data. T ext editing T extBox Displays text entered at design time that can be edited by users at run time, or changed programmatically. RichT extBox Enables text to be displayed with formatting in plain text or rich-text format (RTF). M askedT extBox Constrains the format of user input Information display Label Displays text that users cannot directly edit. LinkLabel Displays text as a Web-style link and triggers an event when the user clicks the special text. Usually the text is a link to another window or a Web site. StatusStrip Displays information about the application's current state using a framed area, usually at the bottom of a parent form. ProgressBar Displays the current progress of an operation to the user. Web page display WebBrowser Enables the user to navigate Web pages inside your form.

Controls

Function Control Description Selection from a list CheckedListBox Displays a scrollable list of items, each accompanied by a check box. ComboBox Displays a drop-down list of items. DomainUpDown Displays a list of text items that users can scroll through with up and down buttons. ListBox Displays a list of text and graphical items (icons). ListView Displays items in one of four different views. Views include text

  • nly, text with small icons, text with large icons, and a details

view. NumericUpDown Displays a list of numerals that users can scroll through with up and down buttons. TreeView Displays a hierarchical collection of node objects that can consist of text with optional check boxes or icons. Graphics display PictureBox Displays graphical files, such as bitmaps and icons, in a frame.

Controls

Function Control Description Graphics storage ImageList Serves as a repository for images. ImageList controls and the images they contain can be reused from one application to the next. Value setting CheckBox Displays a check box and a label for text. Generally used to set

  • ptions.

CheckedListBox Displays a scrollable list of items, each accompanied by a check box. RadioButton Displays a button that can be turned on or off. TrackBar Allows users to set values on a scale by moving a "thumb" along a scale. Date setting DateTimePicker Displays a graphical calendar to allow users to select a date or a time. M onthCalendar Displays a graphical calendar to allow users to select a range of dates.

Controls

Function Control Description Dialog boxes ColorDialog Displays the color picker dialog box that allows users to set the color of an interface element. FontDialog Displays a dialog box that allows users to set a font and its attributes. OpenFileDialog Displays a dialog box that allows users to navigate to and select a file. PrintDialog Displays a dialog box that allows users to select a printer and set its attributes. PrintPreviewDialog Displays a dialog box that displays how a control PrintDocument component will appear when printed. FolderBrowserDial

  • g

Displays a dialog that allows users to browse, create, and eventually select a folder SaveFileDialog Displays a dialog box that allows users to save a file. M enu controls M enuStrip Creates custom menus. ContextM enuStrip Creates custom context menus.

Controls

Function Control Description Commands Button Starts, stops, or interrupts a process. LinkLabel Displays text as a Web-style link and triggers an event when the user clicks the special text. Usually the text is a link to another window or a Web site. NotifyIcon Displays an icon in the status notification area of the taskbar that represents an application running in the background. T

  • olStrip

Creates toolbars that can have a M icrosoft Windows XP , M icrosoft Office, M icrosoft Internet Explorer, or custom look and feel, with or without themes, and with support for

  • verflow and run-time item reordering.

User Help HelpProvider Provides pop-up or online Help for controls. T

  • olTip

Provides a pop-up window that displays a brief description of a control's purpose when the user rests the pointer on the control.

slide-5
SLIDE 5
  • Dr. Adriana Badulescu Kallas

Beginning Programming I 5

Controls

Function Control Description Grouping

  • ther

controls Panel Groups a set of controls on an unlabeled, scrollable frame. GroupBox Groups a set of controls (such as radio buttons) on a labeled, nonscrollable frame. T abControl Provides a tabbed page for organizing and accessing grouped

  • bjects efficiently.

SplitContainer Provides two panels separated by a movable bar. T ableLayoutPanel Represents a panel that dynamically lays out its contents in a grid composed of rows and columns. FlowLayoutPanel Represents a panel that dynamically lays out its contents horizontally or vertically. Audio SoundPlayer Plays sound files in the .wav format. Sounds can be loaded or played asynchronously.

Form with Controls A Form With Controls

Button Button Panel Panel PictureBox PictureBox Label Label

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 pbS miley pGame bS tart bS top 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
slide-6
SLIDE 6
  • 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 event Click event

Event Code

Private Sub bStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bStart.Click pbSmiley.Visible = True pGame.Visible = True bUp.Visible = True bDown.Visible = True bLeft.Visible = True bRight.Visible = True End Sub Private Sub bStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bStop.Click pbSmiley.Visible = False pGame.Visible = False bUp.Visible = False bDown.Visible = False bLeft.Visible = False bRight.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 Code

Private Sub bUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bUp.Click If (pbSmiley.Top < 100) Then pbSmiley.Top = 5 Else pbSmiley.Top = pbSmiley.Top – 100 End 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 = 5 Else pbSmiley.Left = pbSmiley.Left – 100 End If End Sub

Event Code

Private Sub bDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bDown.Click If (pbSmiley.Top + 50 >= 400 - pbSmiley.Height - 5) Then pbSmiley.Top = IndentMax - pbSmiley.Height – 5 Else pbSmiley.Top = pbSmiley.Top + 50 End 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 – 5 Else pbSmiley.Left = pbSmiley.Left + 50 End If End Sub

slide-7
SLIDE 7
  • Dr. Adriana Badulescu Kallas

Beginning Programming I 7

Visual Studio Download

  • Visual Studio Express is a set of free

development 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

  • M SDN 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. Y
  • ur

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 M icrosoft 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