Date: Thu, 22 Jun 2006 17:05:33 -0500 (CDT) From: Mark Jacobson To: 810-030-01@uni.edu Subject: Code from today - SABIN HALL 225 We will meet in SABIN 225 Computer Lab again on Friday. Here is the code from today's hands on class. Split() function, arrays, ListBox controls, Functions with arrays as arguments, global variables, keeping or obtaining a sum... Exercise: Write a function that returns the average of the numbers. The average of the integers 3, 4 and 6 would be 13 / 3 which would be about 4.333 The average should be a SINGLE or a DOUBLE, i.e. a REAL number and not an integer... Dim a() As String Function sum(ByVal theList() As String) As Integer Dim theSum As Integer 'theSum = 0 'sum = 0 For i As Integer = 0 To theList.GetLength(0) - 1 theSum = theSum + Val(theList(i)) 'sum = sum + Val(theList(i)) Next Return theSum End Function Private Sub btnMakeArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMakeArray.Click If chkClear.Checked = True Then lstNumbers.Items.Clear() End If a = txtNums.Text.Split(",") For i As Integer = 0 To a.GetLength(0) - 1 lstNumbers.Items.Add(a(i)) Next MsgBox("The sum is " & sum(a)) End Sub We will meet in SABIN 225 again tommorrow (Friday). We'll meet in Wright Hall again next week on Monday. We have a midterm test on Friday. The Neko cat racing program will be due on next Thursday, one week from today. Mark