Professional Documents
Culture Documents
Chapter 11
Data Type
Visual Basic supports a vast array of data types. Each data types
has limits to the kind of information and the minimum and
maximum values it can hold.
Exercise #1
Kindly specify the
appropriate Data type
for each fieldname in
the Bio-data form at
the right side.
START / END
Create a flowchart that will ask the user to enter the score of a
student for each of the 5 Quizzes having a perfect score of 10 each.
Using Totalling get the sum of the scores of the 5 Quizzes.
Example:
Create a flowchart to compute for the score of a student answering
a quiz with 10 questions and for every correct answer the student
gets 2 points. Display the total score of the student for the final
result.
Assignment
https://bettersolutions.com/vba/functions/complete-list.htm
These functions are already defined in the system libraries. Programmer will reuse the already
present code in the system libraries to write error free code. But to use the library functions, user
must be aware of syntax of the function.
A pre-defined function is built into the software and does not need to be created by a programmer. Pre-defined
functions often exist to carry out common tasks, such as:
• End sub()
• Print
• Clear screen
Libraries: DLL, in full dynamic link library, file containing code for commonly
used program functions on personal computers (PCs) that run the Microsoft Corporation’s
Windows operating system.
= Equal
AND
NAND
NOR
XOR
XNOR
Array:
A store of data values that are all related and are of the same data type.
Element:
Student_name[0] = Andy
:
:
Student_name[5] = Joshua
Example 1:
Dim Student_name(5) As String
Student_name[0] = Yesika
Student_name[1] = Nikolas
Student_name[2] = Robert Print Student_name[2]
Student_name[3] = Chelsea
Student_name[4] = Bellezza
Student_name[5] = Rivallen
Example 2:
Dim Highscore(9) As Integer
Highscore ← [83, 75, 77, 82, 95, 99, 84, 70, 91, 80]
2. Set the number of elements that array will hold. This is called specifying
the dimension or size of the array. The number of data it may store in
each memory location of an array. It must be enclosed with a
parentheses (n).
3. Define the type of data the array will hold. This is called specifying the
data type.
Dim Highscore(9) As Integer
Dim Student_name_10C2(29) As String
Creating an Array
What? the array is going to be used for, so it can be given a
meaningful name.
How? many items are going to be stored, so the size of the array
can be determined.
Highscore ← [83, 75, 77, 82, 95, 99, 84, 70, 91, 80]
Highscore ← [83, 90, 77, 82, 95, 99, 84, 70, 91, 80]
Highscore ← [83, 90, 77, 82, 95, 99, 84, 70, 91, 80]
Write - store or input data into an element of an
array to store it.
INPUT highscore[1] ← 90
Highscore ← [83, 75, 77, 82, 95, 99, 84, 70, 91, 80]
QuizScore ← [90, 92, 88, 85, 97, 91, 93, 98, 95, 99]
QuizScore[0] = 90
:
:
:
QuizScore[9] = 99
Hands-On Activities
Create a program that will determine the size of an Array.
Create a program that will allow you to enter 5 names in an Array and
display the names in the Listbox.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For num = 0 To 5
CusName(num) = InputBox("Enter the customer name", "Enter Name")
ListBox1.Items.Add(CusName(num))
Next
End Sub
End Class
Highscore ← [83, 75, 77, 82, 95, 99, 84, 70, 91, 80]
FOR count = 0 to 9
Index variable use to move
PRINT HighScore(count) from one element in the array
NEXT to the next
Using a variable as an Index
Dim Highscore(9) As Integer
Highscore ← [83, 75, 77, 82, 95, 99, 84, 70, 91, 80]
FOR count = 0 to 9
PRINT HighScore(count)
NEXT
Highscore ← [83, 75, 77, 82, 95, 99, 84, 70, 91, 80]
FOR count = 0 to 3
PRINT HighScores(count)
NEXT
Examples: PRINT HighScores(count) -> 83
PRINT HighScores(count) -> 75 OUTPUT
PRINT HighScores(count) -> 77
PRINT HighScores(count) -> 82
Write data to an array using the index variable
Dim Highscore(9) As Integer
Highscore ← [83, 75, 77, 82, 95, 99, 84, 70, 91, 80]
FOR count = 0 to 3
The first four values in the element of the array
INPUT HighScores(count) will be replaced with the new values entered.
NEXT
Highscore ← [75, 77, 90, 99, 95, 99, 84, 70, 91, 80]
Examples: INPUT HighScores(count) <- 75
INPUT HighScores(count) <- 77 INPUT / STORE
FOR count = 2 to 7 You may not necessarily start with 0 when using
an index variable because you may point the
PRINT HighScores(count) variable to the desired position in the array.
However, the array still starts with 0 to 9 based on
NEXT the example above.
Highscore ← [75, 77, 90, 99, 95, 99, 84, 70, 91, 80]
Create an Array that will use an index variable.
For num = 0 To 9
HighScore(num) = InputBox("Enter the High Score", "Enter Scores")
ListBox1.Items.Add(HighScore(num))
Next
End Sub
End Class
For count= 7 to 9
Print HighScore(count)
Next
For num = 0 To 9
HighScore(num) = InputBox("Enter the High Score", "Enter Scores:")
ListBox1.Items.Add(HighScore(num))
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim num As Integer
Dim HighScore(9) As Integer
For num = 0 To 5
HighScore(num) = InputBox("Enter the High Score", "Enter Scores:")
ListBox2.Items.Add(HighScore(num))
Next
For num = 3 To 5
ListBox3.Items.Add(HighScore(num))
Next
End Sub
End Class
OUTPUT save@Filename: rw_index_Array
VB6.0 directly display on the Form 1
Private Sub cmdDisplay_Click()
Dim HighScore(6) As Integer
For num = 0 To 5
HighScore(num) = InputBox("Enter the High Score", "Enter Scores")
Print HighScore(num)
Next
End Sub
VB6.0 Display on the List1
Private Sub cmdDisplay_Click()
Dim HighScore(6) As Integer
Dim num As Integer
For num = 0 To 5
HighScore(num) = InputBox("Enter the High Score", "Enter Scores")
List1.AddItem (HighScore(num))
Next
End Sub
MULTI-DIMENSIONAL ARRAY
Create a multi-dimensional Array that will store the following names of
students. Using row-by-row layout