IT 236 -- Practice Final -- Summer 2005 Part A. 1. d 2. b 3. b 4. b 5. a. Part B. x y s t u Return Value ------+-----+-----+-----+-----+--------------- 5 22 3 7 18 19 1. Output: 25 2. Public Sub Main() WriteLine(BeginsAndEndsWithA("apple") WriteLine(BeginsAndEndsWithA("Asia") WriteLine(BeginsAndEndsWithA("aa") WriteLine(BeginsAndEndsWithA("a") WriteLine(BeginsAndEndsWithA("a") End Sub Public Function BeginsAndEndsWithA( _ word As String) As String Dim n As Integer = word.Length If n = 0 Then Return False End If Dim b As String = word.Substring(0, 1) Dim e As String = word.Substring(n - 1, 1) Return b.IndexOfAny("aA") = 0 And e.IndexOfAny("aA") = 0 End Function 3. Public Sub cb_SelectedIndexChanged(sender As Object, _ e As EventArgs) Dim d As String = {"Sunday", "Monday", "Tuesday", _ "Wednesday", "Thursday", "Friday", "Saturday"} Dim i As Integer = cb.SelectedIndex MessageBox.Show(d(i)) End Sub 4. To appear soon. Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load c = New OleDbConnection c.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=c:\weekdays.mdb" c.Open() s = New OleDbCommand s.Connection = c s.CommandType = CommandType.Text s.CommandText = "SELECT * FROM DaysOfWeek" da = New OleDbDataAdapter da.SelectCommand = s ds = New DataSet da.Fill(ds, "DaysOfWeek") End Sub Private Sub cb_SelectedIndexChanged( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles cb.SelectedIndexChanged s.CommandText = "SELECT * FROM DaysOfWeek " & _ "WHERE Abbreviation = '" & cb.SelectedItem & "'" ds.Clear() da.Fill(ds, "DaysOfWeek") txtDay.Text = ds.Tables(0).Rows(0).Item("Name") End Sub 5. Public Sub picDisplay_Paint(sender As Object, _ e As PaintEventArgs) Dim g As Graphics = e.Graphics Dim b As New SolidBrush(Color.Red) g.FillRectangle(b, 20, 20, 80, 20) g.FillRectangle(b, 20, 40, 20, 40) g.FillRectangle(b, 20, 60, 80, 20) g.FillRectangle(b, 80, 80, 20, 20) g.FillRectangle(b, 20, 100, 80, 20) End Sub