Introduction to Computing Dr. Nadeem A Khan
Lecture 25-26
Chapter 7: Array Variables (Arrays)
► Array: A list of values can be assigned Collection of variables of the same type Array Variables (Arrays)
► Array Declaration: Dim arrayName (1 to n) As varType e.g: Dim names(1 To 3) as Strings Dim scores(1 To 10) as Single Array Variables (Arrays)
► Value assignment: Dim names(1 To 3) as Strings Let names(1)=“Aslam” Let names(2)=“Khalid” Let names(3)=“Akbar” Picture1.Print names(3), names(2),names(1) Array Variables (Arrays)
► What is what? Dim scores(1 To 3) as Single scores( ): name of the array scores(1): first element scores(2): second element scores(3): third element 1, 2, 3: subscripts Array Variables (Arrays)
► What are the ranges or dimensions? Dim scores(1 To 3) as Single Dim names(1 To 10) as String Array Variables (Arrays)
Debugging Tools
Sub Command1_Click ( ) Dim num As Integer, counter As Integer Let counter=1 Do While counter<=4 Let num=1 Let num=1 Do While num<=3 Debug.Print num; Let num=num+1 Loop Let counter=counter+1 Debug.PrintLoop End Sub Debugging Tools: Example 1
► The result: Debugging Tools: Example 1
► Reverses the input string Sub Command1_Click ( ) Picture1.Cls Debug.Print Reverse$((Text1.Text)) End Sub Debugging Tools: Example 2
Function Reverse$ (info As String) Dim m As Integer, j As Integer, temp As String Let temp = “” For j = Len(info) To 1 Step -1 Let temp = temp + Mid$(info, j, 1) Next Reverse$ = temp End Function Debugging Tools: Example 2
► Break points ► Single Step Execution Step Into (F8) Step Over (Shift+F8) Step Out (Ctl+Shift+F8) ► Watching Variables Immediate Window Watch Window Local Window Debugging Tools:
► Debug Object Debug.Print Debug.Assert Debugging Tools:
End