Hopefully I have some big things in store for me!
It seems every book, instructor, and course has different information of whatever subject matter is relevant,
and important.
Which begs the question , What exactly is?
Well, all of it!!!
I don't mind because I learn a range of things, but just find it interesting enough to mention!
Here is an exercise from:
here is a link for inexpensive purchase:
http://search.barnesandnoble.com/Microsoft-Visual-Basic-2008-Express-Programming-for-the-Absolute-Beginner/Jr-Jerry-Lee-Ford-Jerry-Lee/e/9781598639001
So the exercise starts of in MenuBar creation, and moves in to loops and conditions...
I went through it and added comments from the text and my own, with easy formatting to explain each sections purpose...
The program is designed to ask for lottery numbers, and picks, and then generates a sample for you...
Here is the "Beast" of the code:
Public Class ltaForm
Private Sub GetNumbersToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetNumbersToolStripMenuItem.Click
'Statements that are to be executed when the Get Numbers menu item is clicked between these two statements
'These statements define variables and an array used by the application to store and manipulate the data it needs to execute
Dim intForLoopCtr As Integer = 0
Dim blnFullSetComplete As Boolean = False
Dim intRndNo As Integer = 0
Dim strDisplayString As String = ""
Dim intNoOfValidPics As Integer = 0
Dim aintLotteryArray(10) As Array
Dim intNumberCount As Integer = 0
Dim strTestString As String = "_"
'These statements check to see if the player has supplied valid input into the first TextBox control
'and displays an error message if this is not the case
If txtFullSet.Text = "" Then
MessageBox.Show("You must specify how many numbers " & _
"make up a full set.")
Return
End If
'The next set of statements checks to ensure that that the player entered numeric data into the first TextBox control
'and displays an error message if this is not the case
If IsNumeric(txtFullSet.Text) = False Then
MessageBox.Show("You must specify numeric input when " & _
"specifying how many numbers make up a full set.")
Return
End If
'The next set of statements to be added check to see if the player entered a number greater than 10 in the first TextBox control
'and displays an error message if this is the case
If Int32.Parse(txtFullSet.Text) = 10 Then
MessageBox.Show("The maximum number of numbers in a full " & _
"set is 10. Please enter a number between 3 - 10.")
Return
End If
'The following statements check to make sure that the user specified a number of no less than 3 in the first TextBox control
If Int32.Parse(txtFullSet.Text) < 3 Then
MessageBox.Show("The minimum number of numbers in a full " & _
"set is 3. Please enter a number between 3 - 10.")
Return
End If
'These statements display error messages if the player fails to supply any text, if the player does not supply numeric input
'or if the player tries to specify a number less than 1 or greater than 10 in the second text box
If txtNoPics.Text = "" Then
MessageBox.Show("You must specify how many sets of " & _
"Lottery numbers you want.")
Return
End If
If IsNumeric(txtNoPics.Text) = False Then
MessageBox.Show("You must specify numeric input when " & _
"specifying how many sets of lottary numbers you want.")
Return
End If
If Int32.Parse(txtNoPics.Text) > 10 Then
MessageBox.Show("The maximum number of lottery tickets " & _
"that can be generated is 10. Please enter a number " & _
"between 1 - 10.")
Return
End If
If Int32.Parse(txtNoPics.Text) < 1 Then
MessageBox.Show("The minimum number of lottery tickets " & _
"That can be generated is 1. Please enter a number " & _
"between 1 - 10.")
Return
End If
'Program statements that validate the contents of the third TextBox control
'Display error messages if the player fails to supply any text, if the player does not supply numeric input
'or if the player tries to specify a number that is less than 9 or greater than 50
If txtNoRange.Text = "" Then
MessageBox.Show("You must specify the highest number " & _
"that can be picked.")
Return
End If
If IsNumeric(txtNoRange.Text) = False Then
MessageBox.Show("You must specify numeric input when " & _
"specifying the highest number that can be picked.")
Return
End If
If Int32.Parse(txtNoRange.Text) > 50 Then
MessageBox.Show("The maximum value for the highest number " & _
"is 50. Please enter a number " & _
"less than or equal to 50.")
Return
End If
If Int32.Parse(txtNoRange.Text) < 9 Then
MessageBox.Show("The minimum value for the highest number " & _
"that can be picked is 9. Please enter a number " & _
"greater than or equal to 9.")
Return
End If
'The For loop executes once for each set of lottery numbers that the player wants generated
'The Do loop executes repeatedly until a complete set of numbers has been generated
For intForLoopCtr = 1 To CInt(txtNoPics.Text)
Do Until blnFullSetComplete = True
Randomize()
intRndNo = _
FormatNumber(Int((txtNoRange.Text * Rnd()) + 1))
If InStr(strTestString, _
Convert.ToString("_" & intRndNo & "_")) = 0 Then
strDisplayString = strDisplayString & " " & _
intRndNo & ControlChars.Tab
intNoOfValidPics = intNoOfValidPics + 1
strTestString = strTestString & intRndNo & "_"
End If
If intNoOfValidPics = Int32.Parse(txtFullSet.Text) Then
blnFullSetComplete = True
strDisplayString = strDisplayString & _
ControlChars.NewLine & ControlChars.NewLine
strTestString = "_"
End If
Loop
blnFullSetComplete = False
intNoOfValidPics = 0
Next
'The basic logic used in the statements wrapped inside the Do loop is as follows:
'1) Get a randomly generated number.
'2) Add that number to a string representing a list of lottery numbers
'but don’t allow duplicate numbers to be added to the list.
'3) Format the display string so that a new line is generated for each set of lottery numbers.
'The last program statements added to the code that executes in response to the Get Numbers menu item’s click event is shown here:
txtOutput.Text = strDisplayString
GetNumbersToolStripMenuItem.Enabled = False
ClearNumbersToolStripMenuItem.Enabled = True
End Sub
Private Sub ClearNumbersToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearNumbersToolStripMenuItem.Click
'The first four statements clear out any text displayed in the four TextBox controls.
'The next statement places the cursor in the first TextBox control,
'and the last two statements enable the Get Numbers menu item and disable the Clear Numbers menu item
txtFullSet.Text = ""
txtNoPics.Text = ""
txtNoRange.Text = ""
txtOutput.Text = ""
txtFullSet.Focus()
GetNumbersToolStripMenuItem.Enabled = True
ClearNumbersToolStripMenuItem.Enabled = False
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub WhiteToolStripMenuItem_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles WhiteToolStripMenuItem.Click
'Menu item white background color
Me.BackColor = Color.White
WhiteToolStripMenuItem.Checked = True
YellowToolStripMenuItem.Checked = False
GrayToolStripMenuItem.Checked = False
End Sub
Private Sub YellowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YellowToolStripMenuItem.Click
'Menu item yellow background color
Me.BackColor = Color.Yellow
WhiteToolStripMenuItem.Checked = False
YellowToolStripMenuItem.Checked = True
GrayToolStripMenuItem.Checked = False
End Sub
Private Sub GrayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GrayToolStripMenuItem.Click
'Menu item gray background color
Me.BackColor = Color.LightGray
WhiteToolStripMenuItem.Checked = False
YellowToolStripMenuItem.Checked = False
GrayToolStripMenuItem.Checked = True
End Sub
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
'Makes fornt 8pt Microsoft Sans Serif
txtOutput.Font = New Font("Microsoft Sans Serif", 8)
ToolStripMenuItem1.Checked = True
ToolStripMenuItem1.Checked = False
ToolStripMenuItem2.Checked = False
End Sub
Private Sub ToolStripMenuItem2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
''Makes fornt 10pt Microsoft Sans Serif
txtOutput.Font = New Font("Microsoft Sans Serif", 10)
ToolStripMenuItem1.Checked = False
ToolStripMenuItem2.Checked = True
ToolStripMenuItem3.Checked = False
End Sub
Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
'Makes fornt 12pt Microsoft Sans Serif
txtOutput.Font = New Font("Microsoft Sans Serif", 12)
ToolStripMenuItem1.Checked = False
ToolStripMenuItem2.Checked = False
ToolStripMenuItem3.Checked = True
End Sub
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
MessageBox.Show("This Visual Basic application was created " & _
"by Jerry Lee Ford, Jr. " & _
"This code was hand entered, and comments placed and formatted " & _
"by Andrew Garbe for practice and learning purposes.")
End Sub
End Class
Got that?
I am entering in to the realm of XML tags next.
we are brushing on a few topics in my Database class such as:
-Datawarehouses
-Datamining
-Cookie Algorithms
and XML...
So, I will be sure to add some of my newly discovered XML tags and projects!
-A
No comments:
Post a Comment