Today I am going to be looking at Michael Halvorson's tutorials, which are excellent so far. They are low-key and fun, which is really helpful. You read a short bio here if you wish.
The first tutorial is about using loops and timers.
Let's take a look at the syntax for a for loop
For variable = start to end
statements go here
Next [variable]
The first example Michael Halvorson gives is
Dim i As Integer
For i = 1 To 4
Beep()
Next i
I changed it to
Dim i As Integer
Dim CounterVariable As Integer
CounterVariable = 5
For i = 1 To CounterVariable
beep()
Next i
I then fooled around with it a bit more and created
Dim i As Integer
Dim CounterVariable As Integer
CounterVariable = 5
For i = 1 To CounterVariable
System.Console.Beep(200, 200)
Next i
I then wanted to disable the button while the beeps where playing
Enabled = False
Dim i As Integer
Dim CounterVariable As Integer
CounterVariable = 5
For i = 1 To CounterVariable
System.Console.Beep(200, 200)
Next i
Enabled = True
I then created a textbox so the user could define the number of times to beep and threw in some simple data validation
Dim NumberOfTimes As Integer
NumberOfTimes = Convert.ToInt32(txtNumberOfTimes.Text)
If NumberOfTimes < 20 Then
Enabled = False
Dim i As Integer
Dim CounterVariable As Integer
CounterVariable = txtNumberOfTimes.Text
For i = 1 To CounterVariable
System.Console.Beep(200, 200)
Next i
Enabled = True
Else
MessageBox.Show("That number is too high!")
End If
As with all of my personal projects i went beyond my ability limited by my lack of training and inexperience and didn't get quite what i wanted, but that's OK. Tomorrow I will do more tutorials.
Dim pitch As Integer
pitch = 200
Dim pitchLoopCounter As Integer
pitchLoopCounter = 0
Dim pitchUp As Boolean
pitchUp = True
Dim pitchLoopCounterMod As Double
Dim NumberOfTimes As Integer
If Not IsNumeric(txtNumberOfTimes.Text) Then
MessageBox.Show("Please be so kind as to enter a number.", "Holy tamole")
Exit Sub
Else
NumberOfTimes = Convert.ToInt32(txtNumberOfTimes.Text)
End If
If NumberOfTimes < 35 Then
btnBeepIt.Enabled = False
Dim i As Integer
i = 0
Do
txtLoopCounter.Text = pitchLoopCounter
System.Console.Beep(pitch, 200)
i += 1
pitchLoopCounter += 1
If pitchLoopCounter = 5 Then pitchUp = False
If pitchLoopCounter = 10 Then pitchUp = True
If pitchUp = True Then
pitch += 100
Else
pitch = pitch - 100
End If
txtLoopCounter.Text = pitchLoopCounter
Loop Until i = NumberOfTimes
btnBeepIt.Enabled = True
Else
MessageBox.Show("That number is too high!", _
"Well shucks")
End If
No comments:
Post a Comment