Array Properties Upper Bound The value of array

Array Properties Upper Bound: The value of array. Name. Get. Upper. Bound(0) is the upper bound of array. Name(). Then What is the Lower Bound ? Ans: 0 Chapter 7 1

Example Dim team. Name() As String = {"Packers", _ "Packers", "Jets", "Chiefs"} txt. Box. Text = CStr(team. Name. Get. Upper. Bound(0)) Output: 3 Chapter 7 2

Out of Bounds Error The following code references an array element that doesn't exist. This will cause an error. Dim trees() As String = {"Sequoia", _ "Redwood", "Spruce"} txt. Box. Text = trees(5) Chapter 7 3

Lab sheet 7. 2: Using an Array as a Frequency Table Chapter 7 4

Lab sheet 7. 2 : Code Private Sub btn. Analyze_Click(. . . ) Handles btn. Analyze. Click 'Count occurrences of the various letters in a sentence Dim sentence, letter As String Dim index, char. Count(25) As Integer 'Examine and tally each letter of the sentence = (txt. Sentence. Text). To. Upper For letter. Num As Integer = 1 To sentence. Length letter = sentence. Substring(letter. Num - 1, 1) If (letter >= "A") And (letter <= "Z") Then index = Asc(letter) - 65 'The ANSI value of "A" is 65 char. Count(index) += 1 End If Next Chapter 7 5

Example 4: Code Continued 'List the tally for each letter of alphabet lst. Count. Items. Clear() For i As Integer = 0 To 25 letter = Chr(index + 65) If char. Count(index) > 0 Then lst. Count. Items. Add(letter & " " & _ char. Count(i)) End If Next End Sub Chapter 7 6

Lab sheet 7. 2: Output Chapter 7 7

Copying Arrays If array. One() and array. Two() have been declared with the same data type, then the statement array. One = array. Two makes array. One() an exact duplicate of array. Two(). It will have the same size and contain the same information. Chapter 7 8
- Slides: 8