Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 1 Writing Software Kashef Mughal

2 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 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 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 5 Sample TOE Chart

6 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 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 8 Selecting a Data Type for a Variable TypeSize (Bytes)TypeSize (Bytes) Byte1Short2 Char2Integer4 Boolean4Long8 Decimal12Single4 Double8StringVaries Date8ObjectAnything

9 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 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 11

12 12

13 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 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 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 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 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 & sngSales2001000 intUnits + sngSales1200

18 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 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 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 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 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 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 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 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 = 3.141593  Public Const conMaxAge as Integer = 65

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

27 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 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 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 30 Debugging an Application  Errors are common in computer applications  Two kinds of Errors  Compile Error  Run-time Error  More in Chapter 11

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


Download ppt "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."

Similar presentations


Ads by Google