0% found this document useful (0 votes)
4 views

Writing Software

Uploaded by

Aya Kim
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Writing Software

Uploaded by

Aya Kim
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 68

WRITING SOFTWARE

Programming Language
is anything capable of
making a decision
ALGORITHM
step-by-step description of how the
problem is going to be solved.
list or “Is 10 greater than 4?”
diagram no o r
or e
u e r 0
es t r s 1 o
y fa l
Programming Structure
VB code is stored in modules. The three
kinds of modules are:
1.Form- is the most common kind with a
file name extension .FRM
2. Standard- is used for modules
shared by other modules with a file
name extension .BAS
. Class –is used for user-defined objects wit
a file extension .CLS

a. Properties- provide access to


information. For example: name,
location, size of a file, company
name, address, country, telephone,
etc.
b. Method-or procedure is a self-
contained block of code that does
something or performs an action.
Methods break a program and make it
more understandable. For example:
create, move, delete a file, save
customer information, place an order,
Two sections in each module:
1.Declarations
2.Procedures-have two main
structures for building procedures:
a.Sub
b.Function
Control Structure

1.Sequence-series of steps or process

2. Decision-test the condition, True or


False
a. If...Then
b. If...Then...Else
c. Select Case
3. Iteration
a. Do...Loop
b. For...Next
c. For Each...Next
=IF(AK9>=90, "A", IF(AK9>=85, "P", IF(AK9>=80, "AP",
IF(AK9>=75, "D", "B"))))

Grading sheet.xlsx
Writing the code: The code must be entered
between Private Sub........End Sub.
(Refer to page 169)

writing a code\writing a code.sln

Using Methods\Using Methods.sln


METHODS AND EVENTS
Event is triggered by the action of the
user,
for example:
vent-each click of
user action a button
causes an event to occur
Method is a behavior that an object can
perform, for example: textbox can send
the focus to itself.
Event Procedures- are codes written by
the programmer to react to events-VB
will ignore events for which you do not
write code.
VB is an object-oriented and event-driven
programming language.
OMMON CONTROL EVENTS
EVENT OCCURS WHEN
Activate Form gets the attention
Click User clicks anywhere on the form or control
Initialize Form is first generated
Load Form is loaded into the computer’s memory
and displayed on the screen
Dblclick User double clicks the form or control
Deactivate Another form gets the attention
Unload Form is terminated from the computer’s
memory
Resize Users changes the size of the form
A variable stores data while an
application is executing.
Variables can be named, which the
programmer will create.
The name is sometimes called
IDENTIFIER
The contents of a variable may change
every now and then

3 components of a variable:
1. Data type –number, string, date
2. Name – to distinguish from one
another
3. Value – information stored in the
variable
Naming Variables

A variable must be named so that


its function and purpose is clear.
Its name should be descriptive and
with reasonable length.
. It must begin with an alphabetic
haracter or an underscore.
It must obtain only alphabetic character
umbers or underscore.
3. It must contain at least one
alphabetical character or number if
it begins with an underscore.
It must be less than 1023 characters.

Do not use period or spacing.


se capital letters to separate words.

It must not begin with a number.


Example 1

A = B * 1.10 this is not


descriptive, you don’t know what
variable A or variable B
represents
Example 2
EmployeeSalaryAfterRaise =
EmployeeSalaryBeforeRaise *
1.10
this is too long
Example 3
NewSalary = OldSalary * 1.10
descriptive and short
MPORTANCE OF VARIABLES
Variables allow the program to be
written so that no matter what the
actual data is, the algorithm or
solution still works.
For example: unknown number
plus unknown number equals
Declaring Variables [Dim Statement]
In VB, one needs to declare
variables before using them by
assigning names and data types. If
you fail to do so, the program will
show the error. They are normally
declared a variable and allocate
Use the As clause to specify the
variable’s data type. Examples are as
follows:
Dim counter1 As Integer - -
holding numeric values with a value of
0
Dim counter2 As Integer = 100 - -
holding or storing a numeric value of 100
Dim message1, message2, message3
As String - - holding three empty string
variables
Dim message2 = “” - - holding an
empty string
Dim message3 = “Hello” - - holding a
Dim Statement
Scope of variable
Public Class or general declaration
area – variable is available to the
entire form or class
Private Sub - - variable is available
within a specific procedure or local
available.
Variable’s lifetime is the length of
time it is available. Variable
declared in a method will be in
memory while method is running.
Local

Variable
ASSIGNING VALUES TO VARIABLES
After declaring various variables using
the DIM Statements, you can assign
values to those variables.
The general format of an
assignment is:
Variable = Expression
The variable can be declared
variable or a control property
value. The expression could be
mathematical expression, a
number, a string, a Boolean value
(true or false), etc.
The following are some examples: Assigning Values to Variables\Assigni
ng Values to Variables.sln

Variable=Expression
firstNumber=100
secondNumber=firstNumber-99
username=”Agnes Marie”
userpass.Text=password
Label1.Visible=True
Command1.Visible=false
ThirdNumber=Val (userum1.Text)
Total=firstNumber+secondNumber+ThirdNumber
If there is computation, start Dim
declaration
What is Constant?
a representation of data that remains the
me throughout the program.

Constant are declared and have


specific data type like variables. But
unlike variables, their values will not
change while an application in
ules to follow when naming constants

1.It must begin with an alphabetic character or an


underscore. It must not begin with a number.

. It must contain only alphabetic character or an


underscore.

3. Do not use period or spacing. Use capital


letters to separate words or camel casing.
4. Avoid special symbols.

5. It cannot be a keyword (property or method).

6. To avoid conflicts with keywords, include the


data type at the end of the name. This also
explicitly clarifies the data type of the variable
when referenced in codes.
Declaring a Constant
Examples of declaring a constants are as
follows:
Const Pi As Single = 3.142
Const Temp As Single = 37
Const Score As Single = 100
Const date = 2012
Const tax = 12%
Const temp = 32
Using a Constant
Page 180
Activity 1
Giordano is having a 20% off sale on all
items. Create an application that requires
the cashier to enter the original price of the
item, then compute the discount and the
new price.
Activity 2
CalNatSci Business Center charges P1.25
per page for photocopying. Create an
application that requires the cashier to
compute the bill by entering the customer’s
name, number of pages copied, price per
page and amount due.
Activity 3
De Chavez Management Consulting
charges P2,500 for training fee and
P250 per person for registration fee.
Create an application to help the
accountant make a billing statement
showing the customer’s name, address,
number of participants, training fee
and total amount due.
Activity 4
CNSTHS University charges the students for the
following:
P200.00 per unit (tuition fee)
P100.00 for the laboratory fee
P500.00 energy fee
P 50.00 library fee

Create an application to help the cashier make


assessment showing the student’s name, grade
and section, total number units enrolled and the
total amount due.
DATA TYPE
VB classifies the information into
two major data types :
1.Numeric data type
2.Non-numeric data type
Numeric data types can be
divided into two categories:

1.some have a decimal point


2.some store integer values
(simply values, whole
numbers, no decimal point)
xt data is referred to as a string of
haracters
 Data entered by users is text data
 Used to display output(result of a
calculation, even if it is a number if it
displays dollar, comma)
 Strings are not using calculations
Tips: Different data types are
treated differently by
computer’s memory and
processor; therefore, use the
correct data type
COMMONLY USED VISUAL BASIC DATA
TYPES
Integer Whole numbers, no decimal, can be used
in calculation ex. Dim Cat% Cat%=24
Long Much larger range of whole numbers,
require more memory and slower
processing time, can be used in
calculation ex. Loan&=2,300,000
String Alphanumeric data (letters, numbers, special
symbols) address name. If data will be used
in calculation, it should not be treated as
COMMONLY USED VISUAL BASIC
DATA TYPES
Decimal Used for numbers or money requiring
decimal fractions, require more memory
Single Used for decimal numbers up to 6 digits
of accuracy ex. Dim Price! Price!=899.99
Date Capable of storing dates ex.
Birthday=#2-15-16#
Boolean Special data type that represents only
two values (true or false) ex. Dim Flag As
Boolean
even (7) Types of Numeric Data
depending on the range of values they can store)
TYPE STORAGE RANGE OF VALUES

Byte 1 byte 0 to 255


Integer 2 bytes -32,768 to 32,767
Long 4 bytes -2,147,483,648 to 2,147,483,648

Single 4 bytes -3.402823E+38 to -1.401298E-45 for


negative values
1.401298E-45 to 3.402823E+38 for
positive values
TYPE STORAGE RANGE OF VALUES

Double 8 bytes -1.79769313486232E+308 to -


4.94065645841247E-324 for
negative values
4.94065645841247E-324 to
1.79769313486232E+308 for
positive values
Currency 8 bytes -922,337,203,685,477.5808 to
922,337203,685,477.5807
Decimal 12 bytes +/-
79,228,162,514,264,337,593,950
e VB list of VB2010 arithmetic operators
own in the following table:
Operator Sig Function
n
Arithmetic Performs basic arithmetic on one
operators + or more variables
- Adds two or more
* Subtracts two or more
/ Multiplies two or more
Mo Divides two or more
d Modulus(returns the remainder
String Changes the value of string
operators & Concatenates two strings
+ Adds two strings together to
form a new string
Assignment Assigns a value of variable
operators += Adds two numbers
-= Subtracts two numbers
*= Multiplies two numbers
/= Divides two numbers
Relational Compares variables
operators = Returns true if two values are equal

<> Returns true if two values are not equal

> Returns true if the first value is greater


than the second
<
Returns true if the first value is less than
>= the second

Returns true if the first value is greater


<= than or equal to the second
Logical Group expressions
operator A And Returns true if both A and B are
s B true
A Or B Returns true if either A or B is
Not A true
A X or Returns true if A is not true
B Returns true if either A or B is
A true but both of them are not
AndAls true
oB Returns true if both A and B are
true (does not evaluate B if A is
A not true)
Type Determines variables of
operators a certain type (tests
whether an object is of
a particular data type)
hree steps to perform a calculation

1. Declare the variable


2. Convert the contents of the textbox to the
appropriate data type (example: integer or decimal)
3. Perform the actual calculation

Using Mathematical Operations\Using Mathematical Operations\Using Mathematical Operations.vbproj


NON NUMERIC DATA TYPES
These are data that cannot be
manipulated mathematically using
standard arithmetic operators.
The non-numeric data comprises text or string
data types, the Date data types, the Boolean
data types that store only two values (true or
false), Object data type and variant data type.
Data type Storage Range
String(fixed Length 1to65,400 char
length) of string
String(varia Length 0to2billion char
ble length) +
10bytes
Date 8 bytes January 1, 100 to
December 31,
Boolean 2 bytes True or false
Object 4 bytes Any embedded
object
Variant(numeri 16 bytes Any value as
c) large as Double
Variant (text) Length+22byt Same as
es variable-length
string
STRINGS
-is a sequence of characters that
tells the user what happened and
what needs to happen next.
It displays information to users. Data like
names, addresses, email address and
telephone numbers are stored in strings.
Use double quotes (“ “) to mark the
beginning and the end of a string.
Tasks that you can accomplish
when working with strings:
Separate first and last names from a strin
presenting a person’s full name.

Convert string to all upper case.


3. Concatenate or join two strings
representing first and last names and
create a string containing last name
followed by comma followed by first
name. Concatenation operators are +
and &.
4. Display a number in currency format,
for example P9,999.99.

Replace some of the string with another


ing.
BOOLEAN

-important when its time to start


making decision. It is a variable
can be either True or False.
PERFORMING CALCULATIONS
1. Performing Calculations- pages 185-186
2. Using Common Integer – pages 188-189
3. Using Numeric Operator : Less than or
equal to– pages 191-192
4. Boolean- page 200
ASSIGNMENT
Answer the following :
1.What is the difference between
flowchart and Pseudocode?
2.What is the importance of Pseudocode?
3.What is the proper sequence in the
program development life cycle?

You might also like