Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.

Slides:



Advertisements
Similar presentations
Pemrograman VisualMinggu …2… Page 1 MINGGU Ke Dua Pemrograman Visual Pokok Bahasan: Console Application Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
Advertisements

Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved. - edited by Maysoon Al-Duwais1.
Lecture 2 Introduction to C Programming
Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CMT Programming Software Applications
 2002 Prentice Hall. All rights reserved. 1 Outline 3.1Introduction 3.2Simple Program: Printing a Line of Text 3.3Another Simple Program: Adding Integers.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Introduction to C Programming
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Chapter 3 – Introduction to Visual Basic Programming
 2002 Prentice Hall. All rights reserved. 1 Outline 3.2Simple Program: Printing a Line of Text 3.3Another Simple Program: Adding Integers 3.7Using a Dialog.
Jozef Goetz,  2009 Pearson Education, Inc. All rights reserved.  2002 Prentice Hall. All rights reserved. expanded by J. Goetz, 2012.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2009 Pearson Education, Inc. All rights reserved Introduction to Visual Basic Programming.
 Simple C# program  Console applications input and output text in a console window, which in Windows XP and Windows Vista is known as the Command Prompt.
Ch 6: JavaScript Introduction to scripting part 2.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to Visual Basic Programming Introduction to Visual Basic Programming Ch3 – Deitel’s Book.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved. - edited by Maysoon Al-Duwais1.
Introduction to Visual Basic Programming Chapter 3 – Introduction to Visual Basic Programming.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
 2007 Pearson Education, Inc. All rights reserved Introduction to Visual Basic Programming.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Introduction to Visual Basic
Chapter 6 JavaScript: Introduction to Scripting
Chapter 2 - Introduction to C Programming
2.5 Another Java Application: Adding Integers
Introduction to C# Applications
Chapter 2 - Introduction to C Programming
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Advanced Programming Lecture 02: Introduction to C# Apps
JavaScript: Introduction to Scripting
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 3 – Introduction to C# Programming
Chapter 2 - Introduction to C Programming
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Introduction to C Programming
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

Introduction to Visual Basic Programming

Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts Arithmetic Decision Making: Equality and Relational Operators Outline

Introduction – Visual Basic programming examples that illustrate several important features of the language examples that illustrate several important features of the language – Console applications Applications that contain only text output Applications that contain only text output Output is displayed in a command window Output is displayed in a command window – Windows Applications Applications that contain GUI Applications that contain GUI

Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text Simple program that displays a line of text Simple program that displays a line of text When the program is run When the program is run – output appears in a command window It illustrates important Visual Basic features It illustrates important Visual Basic features – Comments – Modules – Sub procedures

Outline Welcome1.vb Program Output 1 ' Fig. 3.1: Welcome1.vb 2 ' Simple Visual Basic program. 3 4 Module modFirstWelcome 5 6 Sub Main() 7 Console.WriteLine("Welcome to Visual Basic!") 8 End Sub ' Main 9 10 End Module ' modFirstWelcome Welcome to Visual Basic! Single-quote character ( ' ) indicates that the remainder of the line is a comment Visual Basic console applications consist of pieces called modules The Main procedure is the entry point of the program. It is present in all console applications The Console.WriteLine statement displays text output to the console A few Good Programming Practices – Comments: Every program should begin with one or more comments – Modules: Begin each module with mod to make modules easier to identify – Procedures: Indent the entire body of each procedure definition one “level” of indentation

Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text Now a short step-by-step explanation of how to create and run this program using the features of Visual Studio.NET IDE…

1.Create the console application – Select File > New > Project … – In the left pane, select Visual Basic Projects – In the right pane, select Console Application – Name the project Welcome1 – Specify the desired location 2.Change the name of the program file – Click Module1.vb in the Solution Explorer window – In the Properties window, change the File Name property to Welcome1.vb Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text

Fig. 3.2Creating a Console Application with the New Project dialog. Left paneRight pane Project name File location Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text

Fig. 3.3IDE with an open console application. Editor window (containing program code) Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text

Fig. 3.4Renaming the program file in the Properties window. Solution Explorer File Name property Click Module1.vb to display its properties Properties window Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text

3.Change the name of the module – Module names must be modified in the editor window – Replace the identifier Module1 with modFirstWelcome 4.Writing code – Type the code contained in line 7 of Fig. 3.1 between Sub Main() and End Sub Note that after typing the class name and the dot operator the IntelliSense is displayed. It lists a class’s members. Note that when typing the text between the parenthesis (parameter), the Parameter Info and Parameter List windows are displayed Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text

5.Run the program – To compile, select Build > Build Solution This creates a new file, named Welcome1.exe – To run, select Debug > Start Without Debugging Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text

Fig. 3.5IntelliSense feature of the Visual Studio.NET IDE. Partially-typed memberMember list Description of highlighted member Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text

Fig. 3.6Parameter Info and Parameter List windows. Up arrowDown arrow Parameter List window Parameter Info window Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text

Fig. 3.7Executing the program shown in Fig Command window prompts the user to press a key after the program terminates Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text

Fig. 3.8IDE indicating a syntax error. Omitted parenthesis character (syntax error) Blue underline indicates a syntax error Task List window Error description(s) Simple Program: Printing a Line of Text Simple Program: Printing a Line of Text

Outline Welcome2.vb Program Output 1 ' Fig. 3.9: Welcome2.vb 2 ' Writing line of text with multiple statements. 3 4 Module modSecondWelcome 5 6 Sub Main() 7 Console.Write("Welcome to ") 8 Console.WriteLine("Visual Basic!") 9 End Sub ' Main End Module ' modSecondWelcome Welcome to Visual Basic! Method Write does not position the output cursor at the beginning of the next line Method WriteLine positions the output cursor at the beginning of the next line

Another Simple Program: Adding Integers Another Simple Program: Adding Integers User input two integers – Whole numbers Program computes the sum Display result a) Using Console Application

Outline Addition.vb 1 ' Fig. 3.10: Addition.vb 2 ' Addition program. 3 4 Module modAddition 5 6 Sub Main() 7 8 ' variables for storing user input 9 Dim firstNumber, secondNumber As String ' variables used in addition calculation 12 Dim number1, number2, sumOfNumbers As Integer ' read first number from user 15 Console.Write("Please enter the first integer: ") 16 firstNumber = Console.ReadLine() ' read second number from user 19 Console.Write("Please enter the second integer: ") 20 secondNumber = Console.ReadLine() ' convert input values to Integers 23 number1 = firstNumber 24 number2 = secondNumber sumOfNumbers = number1 + number2 ' add numbers ' display results 29 Console.WriteLine("The sum is {0}", sumOfNumbers) End Sub ' Main End Module ' modAddition Declarations begin with keyword Dim Short for Dimension. These variables store strings of characters These variables store integers values First value entered by user is assigned to variable firstNumber Method ReadLine causes program to pause and wait for user input Implicit conversion from String to Integer Sums integers and assigns result to variable sumOfNumbers Format indicates that the argument after the string will be evaluated and incorporated into the string

Outline Addition.vb Please enter the first integer: 45 Please enter the second integer: 72 The sum is 117

Fig. 3.11Dialog displaying a run-time error. If the user types a non-integer value, such as “ hello,” a run-time error occurs Another Simple Program: Adding Integers Another Simple Program: Adding Integers

Memory Concepts Memory Concepts Variables Variables – correspond to actual locations in the computer’s memory – Every variable has a Name Name Type Type Size Size value value – A value placed in a memory location replaces the value previously stored – When value is read from a memory location, it is not destroyed

Arithmetic Arithmetic Arithmetic operators – Visual Basic use various special symbols not used in algebra Asterisk ( * ), keyword Mod – Binary operators Operates using two operands – sum + value – Unary operators Operators that take only one operand – +9, -19

Arithmetic Arithmetic Integer division – Uses the backslash, \ – 7 \ 4 evaluates to 1 Floating-point division – Uses the forward slash, / – 7 / 4 evaluates to 1.75 Modulus operator, Mod – Yields the remainder after Integer division – 7 Mod 4 yields 3

Arithmetic Arithmetic Fig. 3.14Arithmetic Operators.

Arithmetic Arithmetic Rules of operator precedence 1.Operators in expressions contained within parentheses 2.Exponentiation 3.Unary positive and negative 4.Multiplication and floating-point division 5.Integer division 6.Modulus operations 7.Addition and subtraction operations

Arithmetic Arithmetic Fig. 3.15Precedence of arithmetic operators.

Arithmetic Arithmetic Fig. 3.16Order in which a second-degree polynomial is evaluated. Step 1. Step 2. Step 5. Step 3. Step 4. Step 6. y = 2 * 5 * * * 5 is 10 (Leftmost multiplication) y = 10 * * * 5 is 50 (Leftmost multiplication) y = * * 5 is 15 (Multiplication before addition) y = is 65 (Leftmost addition) y = is 72 (Last addition) y = 72 (Last operation—place 72 into y )

Decision Making: Equality and Relational Operators Decision Making: Equality and Relational Operators If / Then structure – Allows a program to make decision based on the truth or falsity of some expression – Condition The expression in an If / Then structure – If the condition is true, the statement in the body of the structure executes – Conditions can be formed by using Equality operators Relational operators

Fig. 3.17Equality and relational operators. Decision Making: Equality and Relational Operators Decision Making: Equality and Relational Operators

Outline Comparison.vb 1 ' Fig. 3.19: Comparison.vb 2 ' Using equality and relational operators. 3 4 Module modComparison 5 6 Sub Main() 7 8 ' declare Integer variables for user input 9 Dim number1, number2 As Integer ' read first number from user 12 Console.Write("Please enter first integer: ") 13 number1 = Console.ReadLine() ' read second number from user 16 Console.Write("Please enter second integer: ") 17 number2 = Console.ReadLine() If (number1 = number2) Then 20 Console.WriteLine("{0} = {1}", number1, number2) 21 End If If (number1 <> number2) Then 24 Console.WriteLine("{0} <> {1}", number1, number2) 25 End If If (number1 < number2) Then 28 Console.WriteLine("{0} < {1}", number1, number2) 29 End If If (number1 > number2) Then 32 Console.WriteLine("{0} > {1}", number1, number2) 33 End If Variables of the same type may be declared in one declaration The If/Then structure compares the values of number1 and number2 for equality

Outline Comparison.vb Program Output If (number1 <= number2) Then 36 Console.WriteLine("{0} <= {1}", number1, number2) 37 End If If (number1 >= number2) Then 40 Console.WriteLine("{0} >= {1}", number1, number2) 41 End If End Sub ' Main End Module ' modComparison Please enter first integer: 1000 Please enter second integer: <> < <= 2000 Please enter first integer: 515 Please enter second integer: <> > >= 49 Please enter first integer: 333 Please enter second integer: = <= >= 333

Fig. 3.19Precedence and associativity of operators introduced in this chapter. Decision Making: Equality and Relational Operators Decision Making: Equality and Relational Operators

Continuation Lines Use when statement will not fit on a line Use when statement will not fit on a line Underscore (_) is the continuation character Underscore (_) is the continuation character Rules for use Rules for use – Space must precede the continuation character. – Comment following continuation character is not allowed. – Do not break up words. – Multiple continuation lines allowed.

Continuation Lines (Example) The following statement appears on two lines: mdblInterestRate = _ System.Convert.ToDouble(txtInterestRate.Text) / 100