Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Computer

Lesson 10
Dim:
● stands for dimension; used to declare variables in visual basic with proper data type definition
Identifiers:
● a name used to identify a class, variable, function, or any other user-defined item
Static:
● used to define a local variable in a program
Variable:
● has a name and data type
Data:
● refers to qualitative or quantitative attributes of a variable or set of variables.
Datum:
● Data in its plural form
● Is typically the results of measurements and can be the basis of graphs, images, or observations of a set
of variables.
Data structure:
● Is a way of collecting and organizing data in such a way that it can perform operations in an effective way.
Data types:
● refer to an extensive system used for declaring variables or functions of different types
Two major data types:
1. Numeric data types:
● are data that consist of numbers which are used in various operations such as arithmetic
operators.
● Boolean is not a numeric type


2. Non-Numeric data types:
● are data that cannot be manipulated mathematically using standard arithmetic operators.
● it comprises of data types like string, date, boolean that store only two values (true or false),
object, and variant

Variables:
● are like mailboxes in post office
● the contents of the variables change every now and then
● In terms of VB, variables are the areas allocated by the computer memory to hold the data
● Each variable in VB.NET has a specific type, which determines the size and layout of the variable's
memory, the range of values that can be stored within that memory, and the set of operations that can be
applied to variable.
The following are the rules when naming variables in Visual Basic:
● it must be less than 255 characters
● no spacing is allowed
● it must not begin with a number or any character other than the letters of the alphabet (A-Z or a-Z) and
underscore (_)
● period is not permitted
● do not use reserved keyword
● it cannot have the same name as any other variable
Valid name: My_Car , this year , Long_Name_Can_Be_USED
Invalid name: My.Car . 1NewBoy , He&HisFather *& Not allowed

Variable names:
● Play a big part in writing a code, logic flow of the program will depend on how the programmer names the
identifiers.
Different naming conventions:
● Naming conventions are not compulsory, cannot be enforced, and generally, up to the programmers if
they will use it. The Hungarian Notations aims coders to remember the type of variable used while Camel
Case Notation is easier and quicker to type than other notations. That is why they are commonly used
naming conventions in VB.
● Hungarian Notations:
○ It is the most commonly used convention in VB. It uses the first three letters of the data type as
the prefix of the variable's name to distinguish the sub type. The fourth letter of the variable is
typed in uppercase to indicate that this is where the actual variable name starts.


● Camel Case Notation:
○ It is the practice of writing compound words or phrases in which words are joined without spaces
and are capitalized within the compound, thus, looking like the humps of a camel. It is the general
term for using lowercase letters except for the starting letter of a syllable.

● Is an association of a variable name with a data type.


● Variables are declared by using the Visual Basic Dim keyword.
○ Dim
○ variableName
○ AS
Dim statement- used for variable declaration, storage allocation for one or more variables

● The syntax for a simple declaration of a variable is as follows:


○ Dim variableName As variableType
○ In the above statement:
■ Dim:
● is a keyword that indicates that a variable is being declared.
■ variableName:
● is the name assigned to the variable. Use a descriptive variable.
■ As: precedes the declaration of the Variable type (String, Date, and Integer)
○ For example: Dim intInterestRate As Integer

● It is also possible to declare multiple variables on the same line by separating each variable with a
comma. When the variables are of the same types, the type of declaration only needs to be made once at
the end of the declaration.
● For example:
○ Dim intInterestRate, intExchangerate As Integer
Assigning values to variables:
● After declaring various variables using the Dim statements, the programmer can assign values to those
variables.
● The syntax of an assignment is:
○ Variable = Expression
● The variable can be declared variable or a control property value.
● The expression could be a mathematical expression, a number, a string, or a Boolean value (true or
false).
● The following are the examples of variable assignment:
○ intAge = 50 username = “John Lyan” userpass.Text = password Label1.Visible = True
Label4.Caption = textbox.Text X = (3.14159 / 180) * A
Scope of variable:
● Sometimes referred as accessibility of a variable, indicates whether variable can be read from or written
to, and the variable’s lifetime, or how long it stays in memory.
● Dim:
○ Used to declare variables in a procedure
● Static:
○ Used to declare variables in procedures; each time the procedures are called, the data stored in
the variables declared with this keyword are retained
● Public:
○ Used to declare variable within modules; the variable is available to all procedures in the project
● Private:
○ Used to declare variables within the modules but only available to procedures within the project
● ReDim:
○ Used to re-dimension an array
○ A programmer can declare variables at two different locations in the programs. The location of the
variables determines the scope of the variable. The following table provides the general rules for
scope. Be aware that the rules may vary slightly depending on how the program or declares the
variable
● Procedure:
○ The programmer can declare a variable within a procedure, but not outside of any If statement,
the scope is until the End Sub or End Function. The lifetime of the variable is until the procedure
ends.
● Module/Class:
○ The programmer can declare a variable outside of any procedure, but it must be within a
Class...End Class or Module... End or Module statement. The scope is any procedure within this
module. The lifetime for a variable defined within a class is until the object is cleaned up. The
lifetime for a variable defined within a module is until the program ends.
● Variables used within the procedure:
○ Procedure-level variables are recognized only in the procedure in which they are declared. This is
also known as local variables it is declared using the keyword dim or static.
○ For example:
■ Dim intTemp As Integer or Static intPermanent As Integer
● Variables used within a Module:
○ By default, a module-level variable is available to all procedures in the module but not in other
modules. To create a module-level variable, declare the variable with the Private keyword in the
declaration section at the top of the module.
○ For example:
■ Private intTemp As Integer
○ In module-level, there is no difference between Private and Dim. The only reason why the Private
keyword is using module-level is that it readily contrasts with Public and makes the code easier to
understand.
● Variables used by all Modules:
○ To make a module-level variable available to other modules, use the Public keyword to declare
the variable. The values in Public variables are available to all procedures in the application.
Public variables are also declared in the declarations section at the top of the module.
○ For example:
■ Public intTemp as Integer
Constant:
● Is different from variables in the sense that their values do not change while the program is running.
2 sources of constants:
● Intrinsic or System-defined constants:
○ Are provided by applications and controls
● Symbolic or User defined constants:
○ Are declared using the Const statement
Guidelines on how and when to declare a constant:
● A Const statement can represent a mathematical or date/time quantity
● The Const statement can also be used to define string constants
● A programmer can also declare more than one constant declaration on a single line by separating them
with commas
Expression:
● Often represents a number or a literal string, but it can also be an expression that results in a number or
string
Array:
● Is a data structure that contains a group of elements.
One-dimensional Array:
● It stores all the elements of an array in a single row starting with the index until the end of the array
Multi-dimensional Array:
● It is an array in which each element acts as an array that are represented as row and columns. Indexes
for multi-dimensional array must be separated by commas.
Structure:
● Is a data type in programming that refers to a named collection of related data
● The default structure is declared as public
● It can be used in private, protected, and friend
Lesson 11
Debug- locating and correcting code errors
Decision structure- allows the program to decide and change its behavior based on its decision
execute- process of running computer software program/command
syntax- grammar, structure/order of the elements in a language statement

Decision structure:
● Are program element that control the flow of the application based on the decision made by the
programmer about the value of variables or events
● They are an important part of the programming because they help solve practical problems intelligently. In
order to control the program, the programmer needs to use the conditional operators and the logical
operators together with the IF control structure.

Syntax:
● Is the order in which phrases, words, or coding symbols and terms are placed to produce commands.
● Normally, statements in a program are executed one after another. This process is called sequential
execution.
● However, various Visual Basic statements enable the programmer to specify the next statement to be
executed.
● There are different types of decision structure, namely:
○ If Then Structure
○ If Then Else Structure
○ If Then Else If Structure
○ Select case
If Then Structure:
● It is the simplest and most important statement in the program. If Then structure is a control which
executes a set of code only when the given condition is true.
● Syntax:
○ If condition Then
Executable statements when the condition is True
End If
If Then Else Structure:
● The If Then Else structure conditionally executes a group of statements, depending on the value of an
expression.
● Syntax:
○ If condition Then
Executable statements when the condition is True
Else
Executable statements when the condition is False
End If
If Then Else If Structure:
● This structure is an If statement followed by an optional Else If statement, which is very useful in testing
various conditions using single If Else If statement. It provides two or more conditions inside the program
● Syntax:
○ If condition Then
Executable statement
ElseIf
Executable statement
Else
Executable statement
End If
Select Case Structure:
● This is similar to If Else statement. A Select Case statement allows a variable to be tested for equality
against a list of values. Each value is called a case, and the variable being switch on is checked for each
Select Case.
● Syntax:
○ Select Case [expression]
Case [expression list]
Executable statement
Case Else
Executable statement
Exit Select
End Select
Loop Structure:
● The loop statement in a program is used to execute a block of program multiple times.
● The codes written inside the loop block are executed when the given condition is true, and the loop
automatically ends when the condition is false.
● Looping is a very useful feature of visual basic because it makes repetitive work easier.
● VB.Net supports several types of loop statements and loop control statements
● For Next Loop
● Do While Loop
● Do Loop While
● Do Loop Until
● While Wend
● Vb.Net also supports some control statements.
● Typically, the statement inside the loop execute one by one; control statements change the execution
from the typical sequence.
● The control statements in vb.Net are given below:
○ Exit statement
○ Continue statement
○ GoTo statement
For Next Loop:
● This statement executes a set of statements repeatedly in a loop for the given initial and final value range
with the specified step by step increment or decrement value.
● Syntax:
○ For counter = start To end Step [step]
Statement
Next counter
● In the syntax:
○ Counter is the variable declared using the Dim keyword.
○ Start-value is assigned to counter and increment by increment-value until it reaches the end-
value.
Do While Loop:
● The statement under Do While will run continuously as long as the Boolean expressions are true. This is
also known as Entry Controlled Loop.
● Syntax:
● Do While [condition]
● Statements
● Loop
Do Loop While:
● This statement is similar to Do While Loop, except that it does not check the condition before entering the
first iteration. It is also known as an Exit Controlled Loop. In a Do Loop While structure, the body of the
loop is always executed at least once.
● Syntax:
○ Do
○ Statements
○ Loop While [Conditions]
Do Loop Until:
● Do Loop Until statement executes a set of statements until a condition becomes false. This is an infinite
loop that can be terminated using Ctrl + Break.
● The syntax for this loop construct is below:
○ Syntax:
■ Do
■ Statements
■ Loop Until [Conditions]

Lesson 12
numeric functions: 
 provides various functions to be operated on integer or numeric variables to get the required result
parameter list:
 the part of the procedure definition that specifies the parameters
Procedure:
● Is a small program that is meant to solve a relatively small problem
● Sometimes it is called a sub-procedure
● a set of coded instructions that tells a computer how to run a program or calculation
2 categories of procedures used when creating a program:
● Those that have already been created thus made available for the programmer
● Those that need to be created by the programmer them self
4 types of procedures in VB.NET:
● Sub Procedure:
○ Performs a task and then returns a control to the calling code, but it does not return a value to the
calling code
● Function Procedure:
○ Performs a task and then returns a control to the calling code
● Property Procedure:
o is a series of Visual Basic statement that manipulate a custom property on a module, class or structure. It
uses two block known as Get and Set. A Get procedure returns the value of a property A Set procedure
sets a property to a value, including an object reference.
 Event Procedure:
o Whenever the user takes any action such as clicking the mouse, pressing a key, or passing out
on the keyboard, the action is called an event. The moment an event occurs, Visual Basic .NET
looks for a code to tell the program what to do. The code that responds to a specific event is
called an event-handling procedure or just an event handler.calling code:
When naming a sub procedure, it must begin with () end in sub statement

Body- used to define what and how the assignment should be carried

Calling code
 is a statement, or an expression within the statement that specifies the procedure by name and transfers
the control to it.
When naming a procedure, it must begin with a letter.
parameter: 
 allows the calling code to pass a value to the procedure when it calls it. 
argument: 
 represents the value supplied to a procedure parameter when the programmer calls the procedure. 
 argument list:
 part of the procedure call that specifies the arguments

2 ways of passing parameters to functions:


 Pass-by-value (ByVal):
o This argument means passing a copy of a variable to the Subroutine. The ByVal keywords
indicate that the arguments passed into the variable are passed by value. Any changes made to
the variable does not affect the actual variable.
 Pass-By-Reference (ByRef):
o In this case, the argument will be passed by reference. It means that a reference to the original
value will be sent to the function. It is almost like the original value is being directly used within
the function. Operations like equal sign = will affect the original value and be immediately visible
in the calling function.

Function:
 is a block of organized, reusable code that is used to perform a single and related action.
 provide better modularity for the application and a high degree of code reusing. 
 is enclosed by the Function and End Function statements.
 performs a task and then returns control to the calling code. When it returns control, it also returns a value
to the calling code.
Modifiers-specify the access level of the function
-FunctionName,indicates the name of the function
-ParameterList, specifies the list if parameters
-ReturnType,specifies the data type of the variable that the function returns.

Every Function procedure has a data type, just as every variable does. This data type is specified by the As
clause in the Function statement, and it determines the data type of the value the function returns to the calling
code.

Mathematical functions: 
 are very useful and important in programming especially when dealing with mathematical concepts in
programming such as chance and probability, variables, mathematical logics, calculations, coordinates,
time intervals, and etc.
o Abs: 
 function returns the absolute value of a given number. 
 The syntax is - Math.Abs(Number).
o Exp: 
 function returns the exponential value of a given number. 
 The syntax is Math.Exp(Number).
o Log: 
 function returns the natural logarithm of a number. 
 The syntax is Math.Log(Number).
o Fix: 
 function shortens the decimal part of a positive number and returns the largest integer
smaller than the number. However, when the number is negative, it returns the smallest
integer larger than the number. 
 The syntax is - Fix(number).
o Rnd: 
 function is used to write code that involves chance and probability, and returns a random
value between 0 and 1. 
 The syntax is - VBMath.Rnd()*Number.
o Round: 
 is the function that rounds up a number to a certain number of decimal places. 
 The syntax is- Math.Round(number, m).
o Sqrt: 
 returns the square root of a number. 
 The syntax is - Math.Sqrt(Number).
Date function: 
 reads the system clock and returns the current date as a string in the format MM/DD/YY.
 Now#, contains current date and time
 Today#, contains current date
 TimeOfDay# contains current time
Strings: 
 are not objects, so they do not have methods but there are a number of functions for string manipulation.
Some of the string manipulation functions are Len, Right, Left, Mid, Trim, Ltrim, Rtrim, Ucase, Lcase,
Instr, Val, Str, Chr, and Asc.

Input or Output functions: 


 allow the system to handle input from the user and output that is resulted from the code.
o InputBox function: 
 displays a message box where user can input data.
 Promp, message displayed prompting what is to be entered
 Title, title of the input box
 Default-text, appears inside the input box
 X and Y position, position of the coordinates of the input box
o MsgBox function: 
 produces a pop-up message box and prompts the user to click on a command button
before going to the next instruction.
 Prompt, message displayed in the message box
 Style Value, command buttons that will appear on the message box
 Title, title of the message box

Lesson 14
binding data source:
 a general technique that binds data sources from the provider and synchronizes them
method: 
 a programming procedure that is defined as part of a class and included in any object of that class
overloading: 
 ability to create multiple methods of the same name with different implementations
 overrides: 
 use one's authority to reject or cancel

Object-oriented programming (OOP): 


 is a method of software design and construction. It is the next logical progression, after structured
programming to improve the code reusability and maintainability.
 is a method of designing individual software components (classes) with associated behavior (methods)
and data limitation (properties) that help put components together to create a complete application.
Each object in Visual Basic is defined by a class. 
Class: 
 describes the variables, properties, procedures, and events of an object. 
Objects: 
 are instances of classes.
Object:
 is a combination of code and data that can be treated as a unit.
new:
 keyword is added to create an instance of a class.
Creating an Object from a Class:
1. Determine the class where to create an object.
2. Write a Dim Statement to create a variable which the user can assign a class instance.
3. Add the New Operator keyword to initialize the variable to a new instance of the class.
4. Programmer can now access the member of the class through the object variable.
method: 
 is something that an object does.
Add: 
 is a method of the ComboBox object that adds a new entry to a combo box. 
Event: 
 is an action recognized by an object such as clicking the mouse or pressing a key. 
 Can occur as a result of a user's action or program code, or can be caused by the system. 
Code that signals an event is said to raise the event while the code that responds to it is said to handle it. For
example, a form object has a click event that occurs when the user clicks the mouse on the form.

Constructors: 
 are a special kind of Sub procedure and they have the following properties below:
o It always has the name "New".
o Being a sub procedure, it does not return any value. 
o It is automatically called when a new instance or object of a class is created.
 Constructors can be quite useful because they allow the programmer to instantiate an object and initialize
some value in it. 

Overloading: 
 feature is used most frequently to overload the constructor. The programmer can overload the constructor
by defining more than one Sub New (). The only condition while overloading the constructor is that the
constructor should have a signature which is different from other constructors.
property: 
 is a member of a class that acts as an intermediary to a member variable of the class. 
 A property is used to "filter" access to a member of a class. To create a property, use the Property
keyword.
 A property is referred to us as read-only if it allows the programmer to make the value it represent
available. 
ReadOnly: 
 keyword is used to indicate that the property's value can be accessed but it cannot be changed.

Public,private/protected
-specify the level of access to the property

Public
-available to the member of the class
Declaration context
-must be in class, structure, module, cannot be source file, namespace, procedure.

Combined modifiers
-cannot specify ReadOnly together with static in the same declaration.

Assigning a Value
-codes consuming a ReadOnly property cannot set its value, but has access to the underlying storage can assign
or change the value anytime.

shared members
-used to access the class/structure
-belong to the whole class
-can be defined as shared

-declaration context

-combined modifiers

-accessing, can access shared element by qualifying it with its class or structure name, not with variable name

-Implicit sharing, cannot use the shared modifier in a const statement, but constants are implicitly shared. Users
can’t declare a member of a module of an interface to be share, but they are implicitly shared.

You might also like