0% found this document useful (0 votes)
74 views22 pages

Visual Basic Programming: By: Rzgar Ali

Computer programming involves writing code that provides instructions for computers to perform tasks. Programmers take design specifications and create software programs using programming languages. They write code, debug programs by testing for and fixing errors, and update existing programs. A programming language allows humans to write programs for computers in a language that is easier for people to understand compared to machine code.

Uploaded by

Gtr Fif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views22 pages

Visual Basic Programming: By: Rzgar Ali

Computer programming involves writing code that provides instructions for computers to perform tasks. Programmers take design specifications and create software programs using programming languages. They write code, debug programs by testing for and fixing errors, and update existing programs. A programming language allows humans to write programs for computers in a language that is easier for people to understand compared to machine code.

Uploaded by

Gtr Fif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

visual basic

Programming
By : Rzgar Ali

Computer programming, simply put, is the


process of writing code and creating software
programs that tell computers what to do.
More specifically, computer programmers
take the designs and work of engineers and
software developers and, through the use of
any number of computer languages, author
the instructions that a computer can follow.
Computer programmers also update and
expand on existing programs and debug
programs by testing and fixing coding errors.
They additionally reference code libraries and
develop software to automate or simplify

A computer is a tool for solving problems with data.


A program is a sequence of instructions that tell a
computer how to do a task. When a computer follows
the instructions in a program, we say itexecutesthe
program. You can think of it like a recipe that tells you
how to make a peanut butter sandwich. In this model,
you are the computer, making a sandwich is the task,
and the recipe is the program that tells you how to
execute the task.
Activity: Come up with a sequence of instructions to tell
someone how to make a peanut butter sandwich. Don't
leave any steps out, or put them in the wrong order.
Was that easy? Did you remember all the steps? Maybe
you forgot to tell me to use a knife to spread the peanut
butter. Now I've got peanut butter all over my hands!

Of course, you say, a person wouldn't be that dumb. But


a computeristhat dumb. A computer will only do what
you tell it to do. This might make programming
frustrating at first, but it's relieving in a way: if you do
everything right, you know exactly what the computer is
going to do, because you told it.
Of course, computers don't understand recipes written
on paper. Computers are machines, and at the most
basic level, they are a collection of switcheswhere 1
represents "on" and 0 represents "off". Everything that a
computer does is implemented in this most basic of all
numbering systemsbinary. If you really wanted to tell a
computer what to do directly, you'd have to talk to it
inbinary, giving it coded sequences of 1s and 0s that tell
it which instructions to execute. However, this is nearly

with algorithm and flowchart for solving


problem:

What is a programming
Aprogramming
language? languageis, as the name would suggest,

a language developed to express programs. All computers


have a native programming language that they understand,
commonly referred to asmachine code. However, machine
code is a difficult language for us to follow: amongst a
number of difficulties, it is typically expressed in the binary
number system, and it is unique to a particular computer
architecture (thus two different computers could potentially
use two different versions of machine code). Other
programming languages, such asAssembly,BASIC,Javaand
C++exist to provide a better interface between us, as the
programmers, and the computer, by allowing programs to be
expressed in a language that is easier for us to understand
and potentially common to a number of computer
architectures, but which can still be translated into machine
code. In order for this to happen, a computer must
eithercompileorinterpretprograms written in one of

The difference between an interpreter and a compiler is given below:


Interpreter

Compiler

Translates program one


statement at a time.

Scans the entire program and


translates it as a whole into
machine code.

It takes less amount of time to


analyze the source code but the
overall execution time is slower.

It takes large amount of time to


analyze the source code but the
overall execution time is
comparatively faster.

No intermediate object code is


generated, hence are memory
efficient.

Generates intermediate object


code which further requires
linking, hence requires more
memory.

Continues translating the


program until the first error is
met, in which case it stops.
Hence debugging is easy.

It generates the error message


only after scanning the whole
program. Hence debugging is
comparatively hard.

Programming language like

Programming language like C, C+

data type
a particular kind of data item, as defined by

the values it can take, the programming


language used, or the operations that can be
performed on it
In computer science and computer

programming, adata typeor simplytypeis


a classification ofdatawhich tells the
compiler or interpreter how the programmer
intends to use thedata

The following table shows the Visual Basic data types, their supporting
common language runtime types, their nominal storage allocation, and
their value ranges.

1 bit
0=0
1=1
2 bit
00 =
0
01 =
1
10 =

VARIABLES
Variables are inserted as code statements.

These are temporary named storage area


inside the programs memory that will hold
data. Variable names are important in a
program; they hold a value for as long as
the user doesnt change the value. Unlike
with a control (txtname.text=Visual Basic)
which does not hold values for long. This
means that variables are memory locations
which are used to store values temporarily.

VARIABLE Declarations
It is advisable to declare all variables before
they are used in a program.
Using the DIM statement to declare variables by
assigning them a name and a data type. Below
is the format of the DIM statement in a variable
declaration.

Dim Varname as Data Type


Varname is the name you assign to a variable
and the
Data type is the type of data that the variable
will hold.

Error Types (Visual Basic)


In Visual Basic, errors (also called exceptions) fall into
one of three categories:
syntax errors
run-time errors
and logic errors.

Syntax Errors

Run-Time Errors

Logic Errors

Syntax errors are those that appear while you write code. Visual Basic
checks your code as you type it in the Code Editor window and alerts you if
you make a mistake, such as misspelling a word or using a language
element improperly. Syntax errors are the most common type of errors. You
can fix them easily in the coding environment as soon as they occur.
System_CAPS_ICON_note.jpg Note
The Option Explicit statement is one means of avoiding syntax errors. It
forces you to declare, in advance, all the variables to be used in the
application. Therefore, when those variables are used in the code, any
typographic errors are caught immediately and can be fixed.
Run-time errors are those that appear only after you compile and run your
code. These involve code that may appear to be correct in that it has no
syntax errors, but that will not execute. For example, you might correctly
write a line of code to open a file. But if the file is corrupted, the application
cannot carry out the Open function, and it stops running. You can fix most
run-time errors by rewriting the faulty code, and then recompiling and
rerunning it.
Logic errors are those that appear once the application is in use. They are
most often unwanted or unexpected results in response to user actions. For
example, a mistyped key or other outside influence might cause your
application to stop working within expected parameters, or altogether. Logic
errors are generally the hardest type to fix, since it is not always clear

You might also like