KEMBAR78
Applications To Arrays | PDF | Data Type | Variable (Computer Science)
0% found this document useful (0 votes)
9 views34 pages

Applications To Arrays

Uploaded by

bisna.p007
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)
9 views34 pages

Applications To Arrays

Uploaded by

bisna.p007
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/ 34

1.

Applications
2. Variable
3. Data Types & modules
4. Procedure & Control structure
5. Arrays
Variable Stores a single piece of data in memory.

Data Type Specifies the kind of data a variable holds.

Module A container for shared procedures and variables.

Procedure Reusable block of code (Sub or Function).

Structure Groups related variables into one unit.


1. Developing an Application in
Visual Basic
➤ Definition:

Application development in VB involves creating software that

interacts with users through a graphical user interface (GUI) using

Windows Forms.
 An application can be created with the project.
 A project is a collection of files that are used to build an application
 Writing Visual Basic programs involves the following two steps:
 Visual programming step
 Code programming step
1. Developing an Application in
Visual Basic

Visual programming step:


• Visual programming step involves designing an application with
various tools that come along with the Visual Basic

Code programming step:


• Code programming step involves writing programs using a text
editor.
• This section involves writing the first Visual Basic program.
• Before writing the program its specifications have to be viewed.
1. Developing an Application in
Visual Basic

Steps in Application Development:


 Planning – Define purpose, inputs,

outputs, and structure.


 Designing – Create forms and layout

using Visual Basic 6.0.


 Coding – Add logic using VB syntax.

 Testing – Check for errors and bugs.

 Deployment – Package and distribute the

application.
1. Developing an Application in
Visual Basic
1. Developing an Application in
Visual Basic
Modules
 Code in Visual Basic is stored in the form
of modules.
 Modules are containers for code,
providing a way to organize and reuse
procedures, functions, and variables.
 They are fundamental for structuring
applications and are broadly categorized
into Form Modules, Standard Modules,
and Class Modules.
Types of Modules:

 Form Modules:
A simple application may contain a single form
and the code resides in that form modules itself.
 Standard Modules:
 As the application grows additional Forms are

added and there may be a common code to be


executed in several Forms.
 To avoid this duplication of a code a separate

module containing a procedure is created that


implements the common code.
 This is standard module.
Types of Modules:
 Class Modules:
 Class module (.CLS filename

extension) are the building blocks of


object-oriented programming in VB.
 They define classes which are

blueprints for creating objects with


their own properties and methods.
Data Types:
Data Types: VB supports various data types,
including:

 Integer: Whole numbers (e.g., 10, -5, 0)


 String: Text (e.g., "Hello", "VB")
 Boolean: True or False values
 Double: Floating-point numbers (e.g.,
3.14, -2.5)
 Date: Dates and times
Data Types:
 In Visual Basic (VB), data types define
the kind of value a variable can hold,
such as numbers, text, or logical values.
 They dictate how much memory is

allocated for the variable and how the


data is interpreted by the compiler.
 VB supports various data types, broadly

categorized into value types and


reference types.
Value Types:

 Numeric: These types store numerical


values. Examples include:
 Byte: Stores unsigned 8-bit integers (0 to 255).
 Short, Integer, Long: Store signed integers of varying
sizes (2, 4, and 8 bytes, respectively).
 Single, Double: Store single-precision and
double-precision floating-point numbers,
respectively.
 Decimal: Stores decimal numbers with high
precision (128-bit).
 Boolean: Stores True or False values.
 Char: Stores a single Unicode character.
 Date: Stores date and time information.
List of Data Types
Data Types
What is a Variable?

A variable is a named memory location used to


store data temporarily during the execution of a
program. You can think of a variable as a container that
holds a value which can change (or vary) as the program
runs.

Purpose of Variables
Variables allow programmers to:
 Store input from users.

 Perform calculations.

 Hold intermediate results.

 Control program flow (e.g., with conditionals and

loops).
 In Visual Basic (VB), variables are used
to store data values that can be modified
during the execution of a program.
 They are essentially named memory
locations that hold information.
 Variables in VB have a specific data type,
which determines the kind of data they
can store (e.g., numbers, text, dates),
and a name, which is used to refer to the
stored value.
 There are many ways of declaring
variables in Visual Basic.
 Depending on where the variables are
declared and how they are declared, we
can determine how they can be used by
our application.
 The different ways of declaring variables
in Visual Basic are.
1. Explicit Declaration

2. Using Option explicit declaration


Implicit Declaration:
 Declaring a variable tells Visual Basic to
reserve space in memory.
 It is not a must that a variable should be
declared before using it.
 Automatically whenever Visual Basic
encounters a new variable it assigns the
default variable type and value.
 This is called Implicit declaration.
Explicit Declaration:
 Thought Explicit type of declaration is
easier for the user to have more control
over the variable it is advisable to
declare them Explicitly.
 The variable are declared with a Dim
statement to name the variable and its
type.
 The As type clause in the Dim statement
allows to define the data type or object
type of variable.
 This is called Explicit declaration.
 Syntax:
Dim variable [As type]

 For Example:
Dim strname As String
Dim intCounter As Integer
Using Option explicit declaration:

 The option explicit statement checks in the module for usage


of any undeclared variables and reports an error to the user.
 The user can thus rectify the error on seeing this error
message.
 The option explicit statement can be explicitly placed in the
general declaration section of each module using the
following steps.
 Click option menu in the tool menu.

 Click the Editor tab in the Option Dialog box.

 Check required variable declaration option and

then click the OK button


Scope of Variables:
 A variables is scoped to a procedure
level(local) or module level variable
depending on how it is declared.
 The scope of a variable, procedure or
object determines which parts of the code
in our application are aware of the
variables existence.
 A variable is declared in general
declaration section of a Form and hence is
available to all the procedures.
 Local variables are recognized only in the
Local variable:
 A local variable is one that is declared
inside a procedure.
 This variable is only available to the
code inside the procedure and can be
declared using the Dim statement as
given below.
Dim intTemp As Integer
 The local variables exist as long as the
procedure in which they are declared is
executing.
Local variable:
 Once a procedure is executed the value
of its local variables are lost and the
memory used by these variable is freed
and can be reclaimed.
 Variables that are declared with keyword
Dim exist only as the procedure is being
executed.
Static Variable:
 Static variable are not reinitialized each
time Visual Basic invokes a procedure
and thus retains or preserves value even
when a procedure ends.
 In case we need to keep track of the
number of times a CommandButton in as
application is clicked a static counter
variable has been declared.
 Example:
Static intPermanant As Integer
Module level Variable:

 A module level variable is available to all


the procedures in the module.
 They are declared using the Public and
Private keyword.
 Example:
Public intPermanant A Integer
private intTemp As Integer
Scope of Variables:
 They can be declared with Dim and
static Keyboard.
 If we want a variable to be available to
all of the procedures within the same
module or to all the procedures in an
application, a variable is declared with
broader scope.
procedures and control
structures
Procedures and control structures are fundamental
concepts for structuring and managing the flow of a
program.
 Procedures are blocks of code that perform

specific tasks,
while control structures determine the order in
which those tasks are executed.
Procedures
 Definition:

 Procedures are named blocks of code that perform a

specific task. They are reusable components that can


be called from other parts of the program.
Types:
VB has three main types of procedures:
 Sub procedures: These procedures

perform actions but don't return a


value.
 Function procedures: These

procedures perform actions and


return a value.
 Property procedures: These

procedures are used to access and


modify properties of objects.
control structures

 control structures are used to manage


the flow of program execution.
 They allow you to make decisions,
repeat actions, and handle resources.
 Key control structures include selection
statements (like If...Then...Else) for
decision-making and looping statements
(like For and While) for repeating
actions.
Arrays
 An array stores a fixed-size sequential
collection of elements of the same type.
An array is used to store a collection of
data, but it is often more useful to think
of an array as a collection of variables of
the same type.
 All arrays consist of contiguous memory
locations. The lowest address
corresponds to the first element and the
highest address to the last element.
Why Use Arrays?

To store a list of values (e.g.,


scores, names).
To avoid declaring multiple
variables.
To loop through multiple items

You might also like