Escolar Documentos
Profissional Documentos
Cultura Documentos
Eric J. Schwabe
IT 236 Spring 2008
=====
' ListOfNames.sln
' Eric J. Schwabe
' IT 236 Spring 2008
' Demonstrates various operations on a list box
' When the form first loads, displays the number of items in the list box
' in the text box below it (will be updated when it if changes)
' When the Add button is clicked, the string in the adjacent text box will be
' added to the end of the list of items in the list box
' When the Insert button is clicked, the string in the second text box will be
' inserted into the list of items in the list box at the position given by the
' value in the first text box -- if this value is not between 0 and Items.Count,
' an exception will generated and caught
' When the Lookup button is clicked, the list item in the position given by the value
' in the first text box will be displayed in the second text box; if the position is not
' between 0 and Items.Count-1, an exception will be generated and caught
' When the Set button is clicked, the list item in the position given by the value
' in the first text box will be changed to be the string given in the second text box --
' if position isn’t between 0 and Items.Count-1, exception will be generated and caught
Private Sub setButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles setButton.Click
Try
Dim position As Integer = Integer.Parse(setPositionTextBox.Text)
Dim newString As String = setStringTextBox.Text
outputListBox.Items(position) = newString
Catch
setPositionTextBox.Text = "OOB!"
End Try
End Sub
' When the RemoveAt button is clicked, the item in the position given by the value in the
' adjacent text box will be removed from the list of items in the list box; if position
' is not between 0 and Items.Count-1, an exception will be generated and caught
' When the Remove button is clicked, the first occurrence of the string given in the
' text box will be removed from the list of items in the list box; if it does not appear
' there, nothing will happen (no exception will be generated)
=====
=====
' IceCream.sln
' Eric J. Schwabe
' IT 236 Spring 2008
' Demonstrates various combo boxes
Option Strict On
' When the button is clicked, if something has been selected from the list (or another
' string has been typed in), that string is copied to the bottom text box. If a new
' string was typed in (so that the selected index is -1), that new string ia added to
' the list of choices
If (flavorsComboBox.Text <> "") Then ' if anything in the top text box...
End If
End Sub
End Class
=====
=====
' Accmulate.sln
' Eric J. Schwabe
' IT 236 Spring 2008
' Demonstrates a Do loop
Option Strict On
' Uses a Do loop to see how many years it will take for an initial
' investment to grow to a million dollars, given an annual rate of
' return.
money = Double.Parse(moneyTextBox.Text)
interest = Double.Parse(interestTextBox.Text)
outputListBox.Items.Clear()
year = year + 1
money = money * (1 + interest / 100)
Loop
End Sub
End Class
=====
=====
' Reprompt.sln
' Eric J. Schwabe
' IT 236 Spring 2008
' Demonstrates a Do-Until loop
Option Strict On
' Uses a Do loop (Do-Until) to prompt the user for a positive integer,
' and re-prompt until the user enters a positive value.
Do
Try
input = Integer.Parse(InputBox("Enter a positive integer:", _
"PROMPTING USER"))
MessageBox.Show("Your number is " & input, "ECHOING INPUT")
Catch
MessageBox.Show("Not a valid integer...", "INPUT ERROR")
End Try
numberTextBox.Text = input.ToString()
End Sub
End Class
=====
=====
' TryForLoops.sln
' Eric J. Schwabe
' IT 236 Spring 2008
' Demonstrates various For loops
Option Strict On
' Counts through a range of values using a For loop...with or without commentary
outputListBox.Items.Clear()
For count = 1 To 10
'outputListBox.Items.Add
'("Test is True -- Executing loop body... count is " & count.ToString())
outputListBox.Items.Add("*** " & count & " ***")
Next
End Sub
End Class
=====
=====
' ReverseString.sln
' Eric J. Schwabe
' IT 236 Spring 2008
' Uses a For loop to traverse the characters of a string
Option Strict On
' When the button is clicked, the string in the upper text box
' is stored in a variable, and a new string is constructed that is
' the reverse of the input string. The reversed string is displayed
' in the lower text box.
len = oldOne.Length
outTextBox.Text = newOne
End Sub
End Class
=====
=====
' ShowContents.sln
' Eric J. Schwabe
' IT 236 Spring 2008
' Demonstrates using a loop to traverse the contents of a list box
' When the button is clicked, uses a loop to retrieve the items in the list box and
' display them, one at at time, in message boxes
Dim i As Integer
Dim nextDay As String
i = 0
Do
nextDay = daysListBox.Items(i)
MessageBox.Show(nextDay, "Day " & i.ToString())
i = i + 1
Loop While i <= daysListBox.Items.Count - 1
'For i = 0 To daysListBox.Items.Count - 1
' nextDay = daysListBox.Items(i)
' MessageBox.Show(nextDay, "Day " & i.ToString())
'Next i
End Sub
End Class
=====
=====
' CeilingFunction.sln
' Eric J. Schwabe
' IT 236 Spring 2008
' Demonstrates a user-defined function to round numbers up
Option Strict On
' When the button is clicked, the value in the upper text box
' is stored in a variable, and the Ceiling function is called
' to round it up to the next integer. The result is displayed
' in the lower text box.
newNumber = Ceiling(oldNumber)
outTextBox.Text = newNumber.ToString()
End Sub
End Function
End Class
=====
=====
' PizzaPrice.sln
' Eric J. Schwabe
' IT 236 Spring 2008
' Demonstrates a user-defined function
Option Strict On
' When the button is clicked, read the pizza diameter and price
' from the two text boxes, and call the PricePerSquareInch function
' to compute the unit cost per square inch
outputListBox.Items.Add(output)
End Sub
' Given a diameter d and price p (given in dollars), computes the price
' per square inch (returned in cents)
End Function
End Class
=====