Visual Basic Programming FLOWCHART Construction CODING.
-
Upload
alban-waters -
Category
Documents
-
view
278 -
download
5
Transcript of Visual Basic Programming FLOWCHART Construction CODING.
Visual Basic Visual Basic ProgrammingProgramming
FLOWCHART ConstructionFLOWCHART Construction
CODINGCODING
OBJECTIVES:OBJECTIVES:
Define the three control structures Define the three control structures clearly;clearly;
Construct program flowcharts and Construct program flowcharts and source codes that portray different source codes that portray different control structures; andcontrol structures; and
Appreciate the features of Appreciate the features of flowchart as a tool in program flowchart as a tool in program logic formulationlogic formulation..
CONTROL STRUCTUREcontrols the logical sequence
in which computer program instructions are executed.
Also known as Logic Structure3 TYPES:– SEQUENCE– SELECTION– ITERATION
What is Sequence Logic ?What is Sequence Logic ?
instructions are instructions are executed in order, executed in order, from top to bottom.from top to bottom.
No decisions to make, No decisions to make, no choices between no choices between “yes or no”“yes or no”
Sample Problem 1:Make a program that will solve for the grade of a student in Computer III using the following:
• Quizzes 20%• CS 15%• Lab 30%• PT 35%
SEQUENCE
Steps in Creating Simple VB Applications
Create the User Interface (GUI) Set the Properties of the
Objects Enter the appropriate Source
Code Run the Program
Elements of a GUI Control
Property– characteristics or parameters of a control
Event– an action or occurrence to which a program responds
Method– function of the control
Variables
Variable – a named memory location capable of storing values based on its definition– Numeric: used to store a value which is
numeric in nature– String: used for storing strings
**Variable Conventions
Data TypesData Type – an element of a
variable that verifies the kind of data it can store.
- Boolean - Short - Integer (9) - Long (17)- Single - Double- String
Variable DeclarationsSYNTAX:
Dim <variablename> as <data type>
OR:
Dim <variablename><suffix>
Suffixes:
Integer ( % ) Double ( # )Single ( ! ) Long ( & )String ( $ )
Sample Variable Declarations
Ex 1. X and Y are of integer data type.Dim X as integerDim Y%
Ex 2. Name is of string data type. Dim Name$
The Assignment Statement(INPUT)
SYNTAX:
Variable =
ObjectName.PropertyNameWHERE:
ObjectName – name of the control
PropertyName – property of the control Variable - variable / identifier
Ex: Name = txtSN.Text
The Assignment Statement(OUTPUT)
SYNTAX:
ObjectName.PropertyName = Value
WHERE:
ObjectName – name of the control
PropertyName – property of the control Value - a constant or a variable
Ex: lblDisplay.text = “Hello!”
Sample Problem 2 and 3:Construct a flowchart that will solve for the Area and Perimeter of a rectangle.
A program that accepts 2 numbers, solve for the sum, difference, quotient and product of the entered numbers.
SEQUENCE
What is Selection Logic?What is Selection Logic?
A structure that A structure that represents a choice.represents a choice.
Enables the computer to make Enables the computer to make decisions based on a given set decisions based on a given set of choicesof choices
SELECTION LOGIC2 TYPES:
– SingleSingle AlternativeDouble Alternatives
– CompoundMultiple Alternatives
refers to an operation that is refers to an operation that is carried out on variables that can carried out on variables that can only have two possible values: only have two possible values: TRUE and FALSETRUE and FALSE
uses relational and / or logical uses relational and / or logical operatorsoperators
BOOLEAN ExpressionBOOLEAN Expression
Sample Problem 1:Make a program that will solve for the grade of a student in Computer III using the following:
•Quizzes 20%• CS 15%• Lab 30%• PT 35%
Determine whether the grade is passing or failing
SELECTION
Write a program that will assist a teacher in calculating student’s grade at the end of the grading period. The program will accept a numerical grade as input, then it will display the character grade as output based on the given scale: 90 and above A
80 – 89 B70 – 79 C69 and below D
EXERCISE 1 (Seatwork Size 2
CW)
Guidelines in Constructing Flowcharts
1. Flowchart symbols represent various operations
2. A flowchart starts with BEGIN / START and is completed by END / STOP.
3. Flow lines interconnect symbols.4. The arrowhead of a flow line indicates
the direction to be followed. It is optional when the flow is from top to bottom or from left to right
Guidelines in Constructing Flowcharts
5. The sequence of symbols is important. It indicates the step-by-step logic to follow.
6. The terminal, Input/Output, Process and connector symbols must have only one arrow branching out, but may have more than one arrow branching in.
7. The decision symbol must have two exit points (True/Yes and False/No).
Guidelines in Constructing Flowcharts
8. Use connector symbols to reduce the number of flow lines. Avoid intersecting flow lines to make it more effective and easier to follow.
9. There may be varied flowcharts to solve one problem. There is no ONE correct flowchart.
10. It is always useful to test the validity of the flowchart by passing through it with a simple test data.
What is Iteration Logic?What is Iteration Logic? involves loops or cyclesinvolves loops or cyclesthere are two types:there are two types:
– WHILEWHILE– DO UNTILDO UNTIL
Provides a means of Provides a means of repeating a part of repeating a part of instruction without instruction without rewriting the part again rewriting the part again and againand again
Two Parts of Iteration StructureTwo Parts of Iteration Structure
Body of the LoopBody of the Loop– Set of instructions Set of instructions
which are repeatedwhich are repeated
Loop-Exit ConditionLoop-Exit Condition– Condition to be tested Condition to be tested
before each repetitionbefore each repetition
WHILE / DO UNTILWHILE / DO UNTILThe loop-exit The loop-exit
condition is placed condition is placed at the beginning of at the beginning of the loopthe loop– WHILE it is not WHILE it is not
yet the end-of-yet the end-of-file, read and file, read and process student process student recordsrecords
The exit from the The exit from the loop is done at the loop is done at the end of the loopend of the loop
– DO read and DO read and process student process student records UNTIL it records UNTIL it is already the is already the end-of-fileend-of-file
COUNTERCOUNTER
**Counter **Counter – Used to literally count the number of Used to literally count the number of
times a portion of the flowchart is times a portion of the flowchart is traced.traced.
Format:Format:CT = CT + 1CT = CT + 1
– Where CT is any variableWhere CT is any variableCT 1
New
Value
Current
Value
Increment
Value
CT= +
AccumulatorAccumulatorA numeric variable which collects the A numeric variable which collects the
results of a repeated mathematical results of a repeated mathematical operationoperation
Used to keep a running total of an Used to keep a running total of an item.item.
– Format:Format: S = S + NS = S + N
** SUM = SUM + N** SUM = SUM + N
** TotalScore = TotalScore + ** TotalScore = TotalScore + ScoreScore