1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.

Slides:



Advertisements
Similar presentations
Chapter 3: Using Variables and Constants
Advertisements

Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 11: Classes and Objects
1.
1.
VBA Modules, Functions, Variables, and Constants
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Introduction to a Programming Environment
1 Pertemuan 03 Representing Data Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Chapter 1 Program Design
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Apply Sub Procedures/Methods and User Defined Functions
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
Variables and Constants
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Tutorial 11 Using and Writing Visual Basic for Applications Code
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
CHAPTER THREE Representing Data: Constants and Variables.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Chapter 12: How Long Can This Go On?
Input, Output, and Processing
Representing Data: Constants and Variables CHAPTER THREE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Introduction to Programming with RAPTOR
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Applications Development
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
CHAPTER THREE Representing Data: Constants and Variables.
Controlling Program Flow with Decision Structures.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Making Interactive Programs with Visual Basic .NET
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Chapter 3 Vocab By: Christopher Schaffer 1B. Convert Class  The Convert class contains methods that return the result of converting a value to a specified.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Representing Data: Constants and Variables
Unit 2 Technology Systems
Egyptian Language School Computer Department
Chapter 9: Value-Returning Functions
A variable is a name for a value stored in memory.
Data Types, Arithmetic Operations
Chapter 3: Using Variables and Constants
The Selection Structure
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
2. Understanding VB Variables
Variables and Arithmetic Operations
Microsoft Visual Basic 2005 BASICS
CIS16 Application Development and Programming using Visual Basic.net
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS16 Application Development Programming with Visual Basic
Variables and Constants
Presentation transcript:

1 Writing Software Kashef Mughal

2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm describes the program in a step by step manner  In order to solve a business problem using a program, we have two choices  Procedure-Oriented approach  Object-Oriented approach

3 Solving the Problem Using a Procedure-Oriented Approach  Emphasis of a program is on how to accomplish a task  A flowchart uses standardized symbols to show the steps needed to solve a problem  Pseudocode uses English phrases to describe the required steps  User has little, if any, control

4 Solving the Problem Using an Object-Oriented/Event-Driven (OOED) Approach  Object-oriented/Event-driven  Emphasis of a program is on the objects included in the interface and the events that occur on those objects  You will use a TOE (Task, Object, Event) chart to assist you in planning your object-oriented/event- driven programs  User has a lot of control  Users can enter information in any order, change what they entered at any time, and calculate a subtotal whenever they like

5 Sample TOE Chart

6 Using Variables to Store Information  Besides storing data in the properties of controls, a programmer also can store data, temporarily, in memory locations inside the computer  The memory locations are called variables, because the contents of the locations can change as the program is running  You can enter and store data in the box, but you cannot actually see the box

7 Using Variables to Store Information  You can also store the data contained in a control’s property in a variable  All variables have:  Data type – kind of data the variable can contain  Name – An identifier the programmer creates to refer to the variable  Value – Every variable refers to a memory location that contains data. This value can be specified by the programmer. This process is called assignment

8 Selecting a Data Type for a Variable TypeSize (Bytes)TypeSize (Bytes) Byte1Short2 Char2Integer4 Boolean4Long8 Decimal12Single4 Double8StringVaries Date8ObjectAnything

9 Choose the Correct Data Type Short, Integer, LongUsed to store whole numbers Single, DoubleStore floating-point numbers DecimalStores numbers with a decimal point BooleanStores True and False CharStores one Unicode character ByteStores 8-bits of data DateStores date and time information StringStores a sequence of characters

10 Selecting a Name for a Variable  You should assign a descriptive name to each variable used in an application  The name should help you remember the variable’s data type and purpose  Hungarian Notation is a common standard for variable names. The figure below lists the three characters typically associated with the Visual Basic.NET data types using Hungarian Notation

11

12

13 Declaring a Variable  To declare a VB.NET variable, write:  Keyword “Dim”  Name to be used for identifier  Keyword “As”  Data type  Example: ' declare a variable Dim intA As Integer

14 Assigning Data to an Existing Variable  A value can be assigned by the programmer to a variable  Assignment operator (=) assigns the value on the right to the variable named on the left side  Example: ' populate the variable intA = 1

15 In-Class Exercises  Try the following exercises  Pages 45,46  Pages 49, 50  Page 52  Page 54  Review the results with me  Any questions?

16 Working with Strings  A String is a collection of characters  We use double quotes to mark its beginning and end (delimit)  For example dim s as string used to declare it  Concatenation means combining data  Substring is a subset of any string  Formatting of strings is a big concern especially from a user stand point

17 Concatenating Strings  Connecting strings together is called concatenating  You use the concatenation operator, which is the ampersand (&), to concatenate strings in Visual Basic.NET  When concatenating strings, you must be sure to include a space before and after the concatenation operator ExampleResult “Hello “ & strFirstNameHello Mary strFirstName & “ sold $“ & sngSales & “.”Mary sold $1000. intUnits & sngSales intUnits + sngSales1200

18 String Operations .Length - gets the number of characters in the string .Substring - retrieves a substring from the string .Format - Replaces each format item in a specified string .Replace - Replaces all occurrences of a specified string with another String .Trim - Removes all occurrences of white space characters from the beginning and end of the string

19 Working with Dates  This data type has the most properties and methods out of all the data types  When assigning to a variable, should qualify with # like for today it would be #1/14/2004#  Date.Now - Gets date time that is the current local date and time on this computer .DatePart - Returns an Integer value containing the specified component of a given Date value  Dates also have a number of methods for formatting as these can vary from one region

20 The Scope of a Variable  A variable’s scope indicates which procedures in an application can use the variable  The scope is determined by where the Dim, Public or Private statement is entered  When you declare a variable in a procedure, the variable is called a local variable and is said to have procedure scope  When you declare a variable in the form’s Declarations section, the variable is called a form- level variable and is said to have module scope  Module includes all the procedures

21 Creating a Local Variable  Created with the Dim statement  The Dim statement is entered in an object’s event procedure e.g. Private Sub...  Only the procedure in which it is declared can use the variable  Removed from memory when the procedure ends  Preferred way of coding

22 Creating a Form-level Variable  Created with the Private statement  Entered in a form’s General declarations section  Can be used by any of the procedures in the form  Removed from memory when the form is destroyed  Should be used on a limited basis

23 Creating a Global Variable  Created with the Public statement  Best place for this is in a new module like basMain  This can be used by any procedure in any module  Removed from memory when the application ends  Should also be used on a limited basis. An example would be connection to a database

24 Constants  It refers to a memory location whose contents cannot be changed while the program is running  Constants are usually declared globally  Examples:  conPi  conRate

25 Creating a Constant  A memory location whose value cannot change during run time  Syntax: [Public|Private] Const constname [As datatype] = expression  Examples:  Const conPi As Single =  Public Const conMaxAge as Integer = 65

26 In-Class Exercises  Try the following exercises  Pages 56 through 75 labeled “Try It Out”  Review any problems with me  Any questions?

27 Number Systems  Humans use Base-10 number system  Computers prefer Base-2 number system  Review the differences on Page 77  A memory slot in a computer is called a bit  8 bits make up a byte  Everything is in terms of power of 2, so 1 KB is really 2 10 which is equal to 1024 bytes  Review the conversions shown in the book

28 Methods  A method is a block of code that does something  Helps to break up a program into pieces  Lets you re-use the code  We pass data (parameters) to a method which in turn returns (results) back to us  Two types of methods  Sub (sub procedure or sub routine)  Function

29 Sub vs. Function  A function is used when we need a block of code to do something and then return a value back. For example a function to calculate area  A sub is used when we do not need a return value. For example if user clicks on a button do something.  We have been working with a sub already  Private Sub.. End Sub

30 Debugging an Application  Errors are common in computer applications  Two kinds of Errors  Compile Error  Run-time Error  More in Chapter 11

31 In-Class Exercises  Try the following exercises  Pages 85  Pages 87  Page 89  Page 91  Page 93  Review Questions on Page 95