Introductions To Programming and Visual Basic
Introductions To Programming and Visual Basic
Sciences
FSC 113
* Term assignment.
LECTURE 1
LECTURE 1
codes.
FSC 113 NOT FOR SALE PLEASE
• Computer Programming is the act of writing code
which can be executed by a computing system to
perform a meaningful task or give a desired result.
– Calculating or computing
– Comparing and testing
– Shifting operation
– Jumping operations
Problem
Documentation
Analysis
Development
or Design / Model
Implementation
L
FSC 113 NOT FOR SALE PLEASE
Class Programming Example
• Problem Definition:
– Program to find the sum of the first 10 natural
numbers
– Output = Pension
1. i 1
2. SUM 0
3. SUM SUM + i
4. i i + 1
5. If i > 10 GOTO Step 7
6. Else GOTO step 3
7. STOP
START / STOP
PROCESS
DECISION
INPUT / OUTPUT
PREDEFINED PROCESS
CONNECTOR
LOGIC FLOW
FSC 113 NOT FOR SALE PLEASE
Class Programming Example
Flowchart for Summing first 10 natural numbers
START
i = 1, SUM = 0
Is i > YES
STOP
10
NO
SUM = SUM + i
i=i+1
START
CHECK CUSTOMER
STATUS
Order
NEW
YES >
CUSTOME
R? N5000
?
NO NO YES
* To be demonstrated in class
Example
amount = 10000
fName
Ikeja
FSC 113 NOT FOR SALE PLEASE
DATA TYPES IN VB
• Data type is the attribute of a variable or field
which determines the kind of data it can hold.
Example: 2 * 8 + 10
– Relational Operators
These operators result in either True or False.
These can also be classified as Boolean operation
FSC 113 NOT FOR SALE PLEASE
• Relational Operators include
greater than (>), less than (<), not equals to
(<>), less than or equals to (<=) etc.
• Logical Operators
– These include AND, NOT, XOR, OR, EQV
^ Exponential 2
NOT Negation 3
* and / Multiplication & Division 4
\ Integer Division 5
Mod Modulus 6
+ and - Addition or Subtraction 7
• Example
1. If logical expression is true then execute this
Else execute something else
End If
• The
loops to be done is known before hand
Do Until Do While
Example Example
a = 100, b = 10 a = 100, b = 10
Do Until ( a < b) Do While ( a > b)
b= a b b= a b
loop loop
These two loop statement accomplish the same thing and are examples
of PRE-TEST loop statements.
That is the test condition is tested first before executing the body of the loop
FSC 113 NOT FOR SALE PLEASE
Do Until Do While
Example Example
a = 100, b = 10 a = 100, b = 10
Do Do
b= a b b= a b
Loop Until ( a < b) Loop While ( a > b)
•
use index, hence variables MUST be assigned
values before commencing the loop.
Tool Bar
• Menu Bar
– Provides access to most of the commands that control the
programming environment (IDE), such as File, View, Tools etc.
• Tool Bar
– Collection of buttons that serve as shortcuts for executing commands
and controlling the VB IDE. It includes icons such as OPEN File, SAVE,
New Project etc
• Tool Box
– This gives easy access to common VB controls or tools such as
textbox, command button, list box, etc.
• Properties Explorer
– The properties window allows you to view and edit properties associated with
any particular form or control element.
• Project Window
– The project window shows all the files and folders included within the
project.
• Code Editor
– The code editor window is used to manually write codes / program
instructions for a control. There is a separate code editor window associated
with each form and control element.
• Problem Analysis:
– Input = radius of the circle
– Output = area & circumference
– Procedure:
• Area = Pi * radius * radius
• Circumference = 2 * Pi * radius
Stop
Flowchart
FSC 113 NOT FOR SALE PLEASE
Implementation & Documentation
• Implementation & programming to be done in
the lab and submitted in your lab workbooks.
IT WILL BE GRADED AS YOUR TERM ASSIGNMENT
• Documentation
Dim result = 0
TextBox3.Text = result
End Sub