Illuminating Computer Science CCIT 4-6Sep

Slides:



Advertisements
Similar presentations
Working with Intrinsic Controls and ActiveX Controls
Advertisements

Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Chapter 1 - VB 2008 by Schneider1 Chapter 1 - An Introduction to Computers and Problem Solving 1.1 An Introduction to Computers 1.2 Windows, Folders, and.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Using Visual Basic 6.0 to Create Web-Based Database Applications
CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Introduction to computers & Visual Basic School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 3, Monday 1/27/2003)
Introduction to Visual Basic What it is, and a simple program Mike Thelwall University of Wolverhampton, UK.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
1 Integrated Development Environment Building Your First Project (A Step-By-Step Approach)
Visual Basic Chapter 1 Mr. Wangler.
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Using Visual Basic 6.0 to Create Web-Based Database Applications
IE 411/511: Visual Programming for Industrial Applications
Lecture 8 Visual Basic (2).
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: An Introduction to Programming Using Visual Basic 2012, All Rights ReservedAn Introduction.
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., Visual Basic Projects Project Structure and VB’s Programming Tools chapter TWO.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
Chapter Two Creating a First Project in Visual Basic.
CC111 Lec7 : Visual Basic 1 Visual Basic(1) Lecture 7.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
I Power Higher Computing Software Development Development Languages and Environments.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Programming with Microsoft Visual Basic th Edition
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Controlling Program Flow with Decision Structures.
TOOLBOX. The Toolbox Intrinsic Controls - always included in the Toolbox ActiveX Controls - separate files with ocx file extension Insertable Objects.
Visual Basic.NET Programming for the Rest of Us Keith Mulbery Utah Valley State College.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
How Computers Solve Problems Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Introduction to Computer CC111 Week 10 Visual Basic 3 1.
ALMAJMA'AH UNIVERSITY College of Science and Humanitarians Studies in Alghat Information Technology Section (211Tal course)
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Visual Basic Fundamental Concepts
A variable is a name for a value stored in memory.
Introduction to Computer CC111
1. Introduction to Visual Basic
Chapter 1 - An Introduction to Computers and Problem Solving
An Introduction to Computers and Visual Basic
Visual Basic..
Chapter 2 – Introduction to the Visual Studio .NET IDE
CIS16 Application Development Programming with Visual Basic
CS285 Introduction - Visual Basic
An Introduction to Computers and Visual Basic
Chapter 3 Programming Fundamentals
Chapter 4 Enhancing the Graphical User Interface
Presentation transcript:

Illuminating Computer Science CCIT 4-6Sep

Introduction to Programming Concepts Visual Basic: an Introduction Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep The audience should be familiar with the Visual Basic Environment. The audience should be able to build simple Visual Basic Applications. The audience should learn the precedence rules for writing equations. The audience should be able to write programs using control structures

Illuminating Computer Science CCIT 4-6Sep Performing a Task on the Computer Determine Output Identify Input Determine process necessary to turn given Input into desired Output

Illuminating Computer Science CCIT 4-6Sep Problem-solving approach like algebra class How fast is a car traveling if it goes 50 miles in 2 hours? Output: a number giving the rate of speed in Km per hour Input: the distance and time the car has traveled Process: rate = distance/time

Illuminating Computer Science CCIT 4-6Sep Pictorial representation of the problem solving process

Illuminating Computer Science CCIT 4-6Sep Program Planning Tips Always have a plan before trying to write a program The more complicated the problem, the more complex the plan must be Planning and testing before coding saves time coding

Illuminating Computer Science CCIT 4-6Sep Simplified Program development cycle 1. Analyze: Define the problem. 2. Design: Plan the solution to the problem. 3. Choose the interface: Select the objects (text boxes, buttons, etc.).

Illuminating Computer Science CCIT 4-6Sep Program development cycle continued 4. Code: Translate the algorithm into a programming language. Try to avoid jumping straight to this step, which can result in a sloppy solution! 5. Test and debug: Locate and remove any errors in the program. 6. Complete the documentation: Organize all the material that describes the program.

Illuminating Computer Science CCIT 4-6Sep What is Visual Basic? High Level 4th Generation Programming Language Object and Event Driven Visual - Windows Based Integrated Development Environment or IDE

Illuminating Computer Science CCIT 4-6Sep What is VB Used For? Most Popular Programming Language Stand alone programs Applets that can be run on many different kinds of computers Customized specialized Applications –E- Commerce Web based shopping forms and inquiries User friendly Interface to applications

Illuminating Computer Science CCIT 4-6Sep  Used by a computer equipment retail outlet to record data regarding customer orders. Example Order Entry Screen Allows user to use a mouse to click on boxes for text entry. Also enables user to click on buttons to initiate processing steps.

Illuminating Computer Science CCIT 4-6Sep Generations of Computer Languages 1st - Machine language nd - Procedure-oriented languages –FORTRAN for scientists and engineers –COBOL for business applications –C for UNIX operating systems 3rd - Object-oriented languages 4th - Event-driven languages - i.e.VB 5th - Natural languages i.e. English

Illuminating Computer Science CCIT 4-6Sep Compiler Vs Interpreter Higher Languages are translated to Machine Language by: –Interpreter Translates instructions to machine code line-by-line. BASIC, Quick Basic, Visual Basic –Compiler Translates the entire program to machine code before running it. Fortran, C, C++, Visual Basic is also a compiler

Illuminating Computer Science CCIT 4-6Sep What are the Objects in VB? Pre-programmed Code for: –Command Buttons –Labels –Pictures –Text Boxes Have both data and procedures wrapped together

Illuminating Computer Science CCIT 4-6Sep What are the Events? –Visual Basic “watches” what the user does –A user activity is called an event –Events include mouse clicks and moves, menu selections, button presses, etc. –Sections of code are only executed in response to an event

Illuminating Computer Science CCIT 4-6Sep What is the Integrated Development Environment (IDE)?

Illuminating Computer Science CCIT 4-6Sep Visual Basic Environment GUI (Graphical User Interface) - forms and windows that the user sees Property - a characteristic or attribute of an object such as color and size Event - a user action such as clicking a button Code Editor window - editor specially designed to help you when writing code

Illuminating Computer Science CCIT 4-6Sep Visual Basic Environment Components of the VB design environment (Form view)

Illuminating Computer Science CCIT 4-6Sep Visual Basic Environment Components of the VB design environment (Code view)

Illuminating Computer Science CCIT 4-6Sep The Code Editor Window Object List Box Procedure List Box Auto List Members Full Module View button

Illuminating Computer Science CCIT 4-6Sep The Code Editor Window Help window Error message box Syntax error in Red Procedure view button

Illuminating Computer Science CCIT 4-6Sep VB Environment: Project Window The Project Window can be used to navigate between the code and form window for each form / window a project has

Illuminating Computer Science CCIT 4-6Sep VB Environment: Menu Bar The Menu Bar consists of 3 elements the –Title Bar, which holds the name of application, default if Microsoft Visual Basic [design] –Menu Bar, this is the link to Visual Basics menu facilities, each menu option drops down into sub-menus –Toolbar, contains icons which give access to the more commonly used commands (which are also available through the menu bar) Title barMenu BarToolbar

Illuminating Computer Science CCIT 4-6Sep VB Environment: Properties Window Used to set how a control looks and behaves Holds its default values

Illuminating Computer Science CCIT 4-6Sep VB Environment: Control Toolbox Pointer Label Group Frame Check Box Combo Box Horizontal Scroll Bar Timer Directory List Box Shape Image OLE Picture Text Box Command Button Option/Radio Button List Box Vertical Scroll Bar Drive List Box File List Box Line Data Control

Illuminating Computer Science CCIT 4-6Sep VB Environment: Context Sensitive Help Context sensitive help is very useful Select the item control that you want help on Press the F1 key F1

Illuminating Computer Science CCIT 4-6Sep The File Menu Project commands Make executable commands Most recent project list Exit command

Illuminating Computer Science CCIT 4-6Sep The File Menu New Project Open Project Add Project Remove Project Save Project Save Project As Save Component Save Component As Print Print Setup

Illuminating Computer Science CCIT 4-6Sep The File Menu Template - particular pattern for a project or a project element; start a project from a template saves time Existing tab - displays VB projects Recent tab - displays most recently accessed projects Project Groups - a collection of several projects

Illuminating Computer Science CCIT 4-6Sep Building Your First Application There are three primary steps in building a Visual Project: –Place (or draw) controls on the form. –Assign properties to the controls. –Write event procedures for the controls.

Illuminating Computer Science CCIT 4-6Sep Project Files vbp extension = Visual Basic Project – file that tracks all components frm extension = Form file –separate file for each form frx extension = Binary form file –cannot be read by humans vbw extension = Visual Basic workspace

Illuminating Computer Science CCIT 4-6Sep Starting Visual Basic

Illuminating Computer Science CCIT 4-6Sep Choosing Project Type

Illuminating Computer Science CCIT 4-6Sep Placing Controls on the Form: Image

Illuminating Computer Science CCIT 4-6Sep Assigning Properties to Controls

Illuminating Computer Science CCIT 4-6Sep Adding an Image

Illuminating Computer Science CCIT 4-6Sep Browse for an Image

Illuminating Computer Science CCIT 4-6Sep Image Displayed

Illuminating Computer Science CCIT 4-6Sep Buttons and Text Boxes

Illuminating Computer Science CCIT 4-6Sep Changing the Form Title

Illuminating Computer Science CCIT 4-6Sep Writing the Code (Events)

Illuminating Computer Science CCIT 4-6Sep Writing the Code (Events)

Illuminating Computer Science CCIT 4-6Sep Running the Application

Illuminating Computer Science CCIT 4-6Sep Running the Application

Illuminating Computer Science CCIT 4-6Sep More Complex Structures

Illuminating Computer Science CCIT 4-6Sep Syntax Boxes Syntax for a Visual Basic statement is shown in a syntax box Reserved words are shown in bold Programmer named words are shown in italics

Illuminating Computer Science CCIT 4-6Sep The Sub Statement Private Sub controlname_eventname( ) Statements End Sub Where Private is the default procedure type Sub indicates beginning of procedure controlname is name of associated control _ (underscore) required separator eventname is name of corresponding event ( ) set of parentheses is required End Sub indicates end of a procedure

Illuminating Computer Science CCIT 4-6Sep The Sub Statement Example Private Sub cmdCalcTriangle_Click Dim Base As Single Dim Height As Single Area = 1 / 2 * (Base * Height) End Sub

Illuminating Computer Science CCIT 4-6Sep Declarations, Variables, and Constants Variable - a uniquely named storage location that contains data that changes during program execution Constant - a uniquely named storage locations that contains data that does not change during program execution

Illuminating Computer Science CCIT 4-6Sep Declarations, Variables, and Constants Rules for Naming Variables –Must begin with an alphabetic character –Can’t contain a period or type-declaration characters such as %, &, !, or $ –Must be unique with same scope –Must be no longer than 255 characters –Should not reserved word (See Appendix A)

Illuminating Computer Science CCIT 4-6Sep Declaring Variables Declaration statement - nonexecutable code that sets aside storage locations for future use Local variables - declared within a procedure or function Global variables - declared in the general section of the application

Illuminating Computer Science CCIT 4-6Sep Declaring Variables Declare variables using the Dim or Static statements Dim statement - value of variable preserved only until procedure ends Static statement - value of variable preserved the entire time the application is running

Illuminating Computer Science CCIT 4-6Sep The Dim Statement Dim variablename As datatype Where Dim is required variablename should be a descriptive name As is required datatype is one of the following types: Boolean, Byte, Date, Integer, Long, Single, Double, Currency, String, Object or Variant

Illuminating Computer Science CCIT 4-6Sep Declaring Variables Data Types –Boolean - True or false –Date - From Jan 1, 100 to Dec 31, 9999 –Integer - Numbers without a decimal point –Long - Long integer –Single - Numbers with a decimal point –Double - Long Single –Currency - Dollar amounts –String - Character and alphanumeric data –Object - Any object reference such as Word document –Variant - default, can hold any data type

Illuminating Computer Science CCIT 4-6Sep Assigning Values to Variables Variablename = value Where variablename is the descriptive name of the variable = is the assignment operator value is the value the variable will contain Examples: Number1 = 5 FirstName = “Steve” LoanAmount = Length = 17.8 Note: Order is important. Variable name always on the left, and value on the right.

Illuminating Computer Science CCIT 4-6Sep Declaring Constants Const constantname As datatype = value Where Const is required constantname is the descriptive name of the constant As is required datatype is the type of data the constant will contain = is the assignment operator value is the value of the constant Examples: Const Pi As Single Const MaxNumber As Integer = 100

Illuminating Computer Science CCIT 4-6Sep Function - unit of code that returns a value Built-in Functions –Sqr - square root –Rnd - random number generator –Int - returns integer portion of a number –Val - converts a string to a value –Str - converts a value to a string

Illuminating Computer Science CCIT 4-6Sep Application 1: Calculate the area of a circle Inputs: radius of the circle r Output: area of the circle Process: Area=

Illuminating Computer Science CCIT 4-6Sep Application 1: Calculate the area of a circle (Form View)

Illuminating Computer Science CCIT 4-6Sep Application 1: Calculate the area of a circle (Code View)

Illuminating Computer Science CCIT 4-6Sep Application 1: Calculate the area of a circle (Run)

Illuminating Computer Science CCIT 4-6Sep Precedence Table Operator ( ) ^ *, / +,- If precedence of two following operators is equal, then the evaluation starts from left to right.

Illuminating Computer Science CCIT 4-6Sep Simple Examples of Equations Equation in normal form: –Y=3X –Y=X-10+3(X-Z) –Y=X^2*10 –Y= Equation in VB form: –Y=3*X –Y=X-10+3*(X-Z) –Y=X*X*10 –Y=SQR(X)

Illuminating Computer Science CCIT 4-6Sep Application 2: Convert from Fahrenheit Degree to Celsius Original formula: Celsius=5/9(Fahrenheit-32) Visual Basic formula: Celsius=5/9*(Fahrenheit-32) Input: Fahrenheit Output: Celsius Process: Celsius=5/9*(Fahrenheit-32)

Illuminating Computer Science CCIT 4-6Sep Application 2: Convert from Fahrenheit Degree to Celsius (Form View)

Illuminating Computer Science CCIT 4-6Sep Application 2: Convert from Fahrenheit Degree to Celsius (Code View)

Illuminating Computer Science CCIT 4-6Sep Application 2: Convert from Fahrenheit Degree to Celsius (Run)

Illuminating Computer Science CCIT 4-6Sep Application 3: The Wind Chill Application Write a program that calculates the wind chill temperature Inputs: Wind Speed and Temperature Outputs: Wind Chill Temperature

Illuminating Computer Science CCIT 4-6Sep Application 3:The Wind Chill Application Original formula –WC = (3.71(V **0.5) V)(T ) Visual Basic statement –WC = * (3.71 * Sqr(V) (0.25 * V)) * (T ) Output: Wind Chill (WC) Input 1 T: Temperature Input 2 V: Wind Speed

Illuminating Computer Science CCIT 4-6Sep Adding Controls and Changing their Properties

Illuminating Computer Science CCIT 4-6Sep Writing the Code

Illuminating Computer Science CCIT 4-6Sep Running the Application

Illuminating Computer Science CCIT 4-6Sep Control Structures

Illuminating Computer Science CCIT 4-6Sep Controlling your Application Sequence Selection –If...Then...Else statement –Select Case statement Repetition –For...Next Loop statement –For Each...Next statement –Do Loops

Illuminating Computer Science CCIT 4-6Sep Selection If..Then..Else If (condition) Then (statement[s]) [ElseIf (condition) Then (statement[s])] [Else (statement[s])]

Illuminating Computer Science CCIT 4-6Sep Selection Application: Convert from Numerical Grade to Letter Grade Input: a numeric grade between 0 and 100 Output: depends on input InputOutput 0  49F 50  52D 53  56D+ 57  60C- 61  64C 65  69C+ 70  74B- 75  79B 80  84B+ 85  89A- 90  100A

Illuminating Computer Science CCIT 4-6Sep Selection Application: Convert from Numerical Grade to Letter Grade (Form View)

Illuminating Computer Science CCIT 4-6Sep Selection Application: Convert from Numerical Grade to Letter Grade (Code View)

Illuminating Computer Science CCIT 4-6Sep Selection Application: Convert from Numerical Grade to Letter Grade (Run)

Illuminating Computer Science CCIT 4-6Sep For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if less than end. If so, repeat loop again. If not, go to statement after Next.

Illuminating Computer Science CCIT 4-6Sep Do While...Loop Structure Do While condition statements Loop Where The condition is tested, and if true the loop is repeated. When the condition is false, the loop statements are skipped the statement after Loop is executed.

Illuminating Computer Science CCIT 4-6Sep Do Until...Loop Structure Do Until condition statements Loop Where The condition is tested, and if false the loop is repeated. When the condition is true, the loop statements are skipped the statement after Loop is executed.

Illuminating Computer Science CCIT 4-6Sep Loops Application: Factorial Factorial (N)= N*(N-1)*(N-2)……….*(1)

Illuminating Computer Science CCIT 4-6Sep Factorial Flowchart (N>0)

Illuminating Computer Science CCIT 4-6Sep Factorial Application: Form View

Illuminating Computer Science CCIT 4-6Sep Factorial Application: Code View Using For..Next Loop

Illuminating Computer Science CCIT 4-6Sep Factorial Application: Code View Using Do..While..Loop

Illuminating Computer Science CCIT 4-6Sep Factorial Application: Code View Using Do..Until..Loop

Illuminating Computer Science CCIT 4-6Sep Factorial Application: Run

Illuminating Computer Science CCIT 4-6Sep After the completion of this lecture, the audience should be familiar with the visual basic environment and different controls. The audience should be able to write simple programs and generate simple VB applications.