0% found this document useful (0 votes)
49 views2 pages

Basic Loop Structure : Code (Program)

Loops are used to repeatedly execute statements as long as a condition is true. The document discusses for loops and arrays in Visual Basic. It provides examples of applications that use loops to display numbers from 1 to a user-input value, store 10 user-input numbers in an array and display them in reverse order, and get an unknown number of values based on a user-input array size. Code snippets demonstrate how to structure the for loops and arrays to implement the examples.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views2 pages

Basic Loop Structure : Code (Program)

Loops are used to repeatedly execute statements as long as a condition is true. The document discusses for loops and arrays in Visual Basic. It provides examples of applications that use loops to display numbers from 1 to a user-input value, store 10 user-input numbers in an array and display them in reverse order, and get an unknown number of values based on a user-input array size. Code snippets demonstrate how to structure the for loops and arrays to implement the examples.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

ONLINE CLASS: COMPUTER FUNDAMENTALS AND PROGRAMMING

MODULE 3

BASIC LOOP STRUCTURE ► used to execute statements until a certain condition is met. A variable
number is initialized to 1 and then the Loop starts. First, the condition is tested; if condition is
True, then the statements are executed. When it gets to the Loop it goes back to the Do and
tests condition again.
EX: Develop an application that will display all numbers from 1 to the number read from the
user.

INPUT

OUTPUT
(Display)

CODE (PROGRAM):
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim x As Integer
Dim y As Integer
If KeyAscii = 13 Then KeyAscii = 13 is equivalent to the enter key.
List1.Clear
y = Val (Text1.Text) End count designated by the input number in textbox.
For x = 1 To y
List1.AddItem (x) Range
Next x
End If
End Sub

ARRAYS ► Local arrays are declared in a procedure using Dim or Static. Array must be
declared explicitly with keyword "As". There are two types of arrays in Visual Basic namely:
Fixed-size array. The size of array always remains the same-size doesn't change during the
program execution.
EX: Make an application that is capable of getting 10 numbers. The application must be able to
display these numbers in a listbox in reverse order on how they are read.

TRIGGER

5
4
3 OUTPUT
2 (Display)
1
CODE (PROGRAM): Starting Count
Option Base 1
Dim no (5) As Integer End Count
Private Sub Command1_Click()
For x = 1 to 5 Number of Inputs
Getting the input
no (x) = InputBox(“Enter Number” & x, “Read Number”,0) numbers (Any number
Next x
will do)
List1.clear
For x = 5 to 1 Step -1 Numbers are displayed from
List1.AddItem ( no (x) )
last input to first input since the
Next x
End Sub negative (-) sign is used

EX: Design an application that will get a number of values from the user. The number of values
to be read depends on the array size read from the user.

End Count (Range)

Input

Display
Output

Exit (End Program)

Dim no() As Integer


Dim x As Integer Getting the input. End Count (Any number will do; to be
specified by the user)
Private Sub Command1_Click()
ReDim no(Val(Text1.Text))
For x = 1 To Val(Text1.Text) Range
no(x) = InputBox(“Enter number” & x,”Read Numbers”,0) Getting the
Next x numbers
End Sub
Private Sub Command2_Click()
List1.Clear
For x = 1 To Val(Text1.Text)
List1.AddItem(no(x)) Displaying the Output
Next x
End Sub
Private Sub Command3_Click()
Unload Me
End Sub Exit

You might also like