|
Lars P. Linden MIS Dept. University of Central Florida |
loop example
This is a loop example that takes a given string and displays each character of the string.
Note, that the first argument of the Substring is the
startindex, which is zero-based. This is:
(a) why the
For loop's control variable starts at 0,
and
(b) why the intHighestIndex is assigned a value that is
one less than the length of the given string.
' loop through each letter of a string
Dim strLetter As String
Dim strCity As String
Dim intLengthOfString As Integer
Dim intHighestIndex As Integer
' given string
strCity = "Orlando"
' get length
intLengthOfString = strCity.Length
' compensate for zero-based counting
intHighestIndex = intLengthOfString - 1
Dim i As Integer
For i = 0 To intHighestIndex
' get letter
strLetter = strCity.Substring(i, 1)
' display
MessageBox.Show(strLetter)
Next
<< back to course home
