Monday, September 13, 2010

Monday, September 13 2010

I worked a little with global variables


Public pressure As Integer
Public power As Integer
Public ClaxonLoud As Integer


These were global variables for the "computer game" I am making (it isn't much of a game, really. But it helps me to put into practice things from the tutorials.


System.Console.Beep(ClaxonLoud, 200)
power += 1
score += 1

ProgressBar1.Value = pressure
If pressure < 50 Then
ClaxonLoud = 200
pressure += 2
ElseIf pressure >= 50 And pressure < 100 Then
ClaxonLoud = 300
pressure += 2
ElseIf pressure >= 100 And pressure < 150 Then
pressure += 5
ClaxonLoud = 400
ElseIf pressure >= 150 And pressure < 200 Then
pressure += 5
ClaxonLoud = 500
Else
Timer1.Enabled = False
End If


If pressure > 50 Then
EmergencyVent.Enabled = True
Else
EmergencyVent.Enabled = False
End If


Also I threw in a button and a button click event.



If power > 10 Then
pressure += -25
power += -10
Else
EmergencyVent.Enabled = False
End If


I am going to be working on some tutorials by Halvorson on functions. Michael Halvorson points out that there is a new statement offered in Visual Basic, the Return statement The return statement tells when you want to return a value and what that value is.

Friday, September 10, 2010

Friday, September 10 2010

Forgot to set the Timer to enabled = true


If TextBox1.Text = "secret" Then
Timer1.Enabled = False
MsgBox("Welcome to the system!")
End
Else
MsgBox("That password is incorrect")
End If


The weird thing is that the program turns off afterwards.

i tried to change the timer from ending the program to selecting the text box and centering the form on the screen but I could only get it to select the textbox.



MsgBox("Sorry, your time is up.")

Me.StartPosition = FormStartPosition.CenterScreen
TextBox1.Select()


THe next Michael Halvorson tutorial is about creating modules and procedures. It uses the lucky number 7 tutorial, which I figured out from messing with it doesn't actual generate random numbers per se. the trick is to use the system clock for the generation of the numbers, it seems.

The code from the original lucky number 7 was


label1.text CStr(Int(Rnd() * 10))


I added a Randomize() before the old code and that did seem to randomize it a bit, which was good.

For a quick break, I did a status bar which I am going to incorporate into one of my game projects



If ProgressBar1.Value < 100 Then
ProgressBar1.Value += 2
ElseIf ProgressBar1.Value >= 100 And ProgressBar1.Value < 200 Then
ProgressBar1.Value += 5
Else
Timer1.Enabled = False
End If

Thursday, September 9, 2010

Thursday September 9th 2010

Doing console aps now using tutorials from www.java2s.com. So far it's very cool.



System.Console.WriteLine("hello world")



Doesn't show up for very long.



Dim strChar As String
Console.Write("Enter a character:")
strChar = Console.ReadKey.KeyChar
Console.WriteLine()
Console.WriteLine("You just entered {0},", strChar)
System.Console.Beep(100, 2100)


I modified the next tutorial dealing with entering a line.



Dim i As Integer
For i = 1 To 3
Dim strLine As String
If i = 1 Then
Console.Write("Enter a line of text:")
ElseIf i = 2 Then
Console.WriteLine()
Console.Write("Write another line of text:")
Else
Console.WriteLine()
Console.Write("Write yet another line of text:")
End If
strLine = Console.ReadLine
Console.WriteLine()
Console.WriteLine("You just entered: {0}", strLine)
If i Mod 2 = 0 Then
System.Console.Beep(100, 300)
Else
System.Console.Beep(300, 300)
End If

Next i



And another




Dim strMessage As String
Try
strMessage = Console.ReadLine()
Console.WriteLine("Hello! " + strMessage)
Catch ex As Exception

End Try
System.Console.Beep(200, 400)


And yet another


Dim userInput As String
Console.WriteLine("Enter a source temperature.")
userInput = Console.ReadLine()
Console.WriteLine(userInput)


The only problem is that there aren't any explanations for why we are doing these tutorials, I mean what the point is, and also I'm not entirely sure why we should be using console aps or what they are for.

I added a ucase to the following tutorial as a workaround for case sensitivity



Dim strInput As String
Do
Console.WriteLine("Please enter 'q' to quit...")
strInput = Console.ReadLine()
Console.WriteLine("You typed " & strInput)
Loop While (UCase(strInput) <> "Q")
Console.WriteLine("Quitting now.")


There is another console tutorial dealing with temperatures



Dim intInput As Integer
Console.WriteLine("Enter a temperature...")
intInput = Val(Console.ReadLine())
If intInput > 75 Then
Console.WriteLine("Too hot!")
ElseIf intInput < 55 Then
Console.WriteLine("Too cold!")
Else
Console.WriteLine("Just right!")
End If
End Sub


Here is another tutorial from www.java2s.com, I had a heck of a time getting the uCase to work as it was my personal addition to the code.


Dim strInput As String

While (UCase(strInput) <> "Q")
Console.WriteLine("You typed " & strInput)
Console.WriteLine("Please enter 'q' to quit...")
strInput = Console.ReadLine()
End While
Console.WriteLine("Quitting now.")


I did another tutorial matching patterns and threw in a beep




Dim sInput As String
Dim sPattern As String
Dim sMatch As String

System.Console.Write("please enter a pattern:")
sInput = System.Console.ReadLine()
sPattern = sInput

System.Console.Write("Please enter a string to compare against:")
sInput = System.Console.ReadLine()
sMatch = sInput

If sMatch Like sPattern Then
System.Console.WriteLine(sMatch & " matched with " & sPattern)
Else
System.Console.WriteLine(sMatch & " did not match with " & sPattern)
End If

If sMatch Like sPattern Then
Dim pitch As Integer = 200
For i As Integer = 1 To 4
System.Console.Beep(pitch, 200)
pitch += 100
Next i
Else
Dim pitch As Integer = 500
For i As Integer = 1 To 4
System.Console.Beep(pitch, 200)
pitch = pitch - 100
Next i
End If

Wednesday, September 8, 2010

Wednesday, September 8th 2010

Still looking at timers. For the next Michael Halvorson tutorial I will be looking at making a digital clock.

Timers have an interval property which is set using milliseconds (spelled with two "l"s, note to self).

To set the timer to seconds, just set the interval property of the time to 1000 milliseconds.

I expanded the tutorial so that the Start / Stop button was the same


If Timer1.Enabled = False Then
Timer1.Enabled = True
btnBegin.Text = "Stop"
Else
Timer1.Enabled = False
btnBegin.Text = "Begin"
End If


I then fooled around with the mod function to play some "music" with the timer



Dim sec As Integer = DateTime.Now.Second
If sec Mod 2 = 0 And sec Mod 4 <> 0 Then System.Console.Beep(200, 100)
If sec Mod 4 = 0 Then System.Console.Beep(400, 200)
If sec Mod 3 = 0 And sec Mod 5 <> 0 Then System.Console.Beep(300, 100)
If sec Mod 5 = 0 Then System.Console.Beep(100, 150)


I also found a great tutorial site for console apps which I want to work on in a bit

VB Console tutorials

Tomorrow I have a long workday so I am going to try and focus on it.

Tuesday, September 7, 2010

Tuesday, September 7 2010

alright I am going to do a tutorial by Michael Halvorson that involves importing pictures.


Dim i As Integer
For i = 1 To 3
pctTulsaWindow.Image = System.Drawing.Image.FromFile _
("C:\Users\Alfred\Downloads\touroftulsaprogram\tulsa" & i & ".jpg")
MsgBox("click here for next face.")
Next


Following the tutorial I further modified it as


pctTulsaWindow.Image = System.Drawing.Image.FromFile("C:\Users\Alfred\Downloads\touroftulsaprogram\tulsa" & Counter & ".jpg")

Counter += 1
If Counter = 5 Then
Counter = 1
System.Console.Beep(200, 200)
End If


The next tutorial is for converting farenheit to Celsius.



Dim FTemp, Celsius As Single
Dim strFTemp As String
Dim prompt As String = "Enter a Fahrenheit temperature."
Do
strFTemp = InputBox(prompt, "Fahrenheit to Celsius")
If strFTemp <> "" Then
FTemp = CSng(strFTemp)
Celsius = Int((FTemp + 40) * 5 / 9 - 40)
MsgBox(Celsius, , "Temperature in Celsius")
End If
Loop While strFTemp <> ""

Monday, September 6, 2010

Monday, September 6

Looking at loops again, and Michael Halvorson's tutorials.


Dim i As Integer
Dim Wrap As String
Wrap = Chr(13) & Chr(10)
For i = 1 To 11
txtLoopResultBox.Text = txtLoopResultBox.Text & "Line " & i & Wrap
Next i


I also discovered something cool for creating a pause in the program

System.Threading.Thread.Sleep(500)



Private Sub wait()
System.Threading.Thread.Sleep(500)
End Sub

Private Sub btnLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoop.Click

Dim i As Integer
Dim Wrap As String
Wrap = Chr(13) & Chr(10)

For i = 1 To 10 Step 1
System.Console.Beep(200, 200)
txtLoopResultBox.Text = txtLoopResultBox.Text & "Line " & i & Wrap
If i < 5 Then
wait()
Else
End If

Next i
End Sub




I finally did another modification with



Private Sub wait()
Dim waitTime As Integer
System.Threading.Thread.Sleep(waitTime)
End Sub

Private Sub btnLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoop.Click

Dim i As Integer
Dim Wrap As String
Wrap = Chr(13) & Chr(10)

Dim waitTime As Integer
waitTime = 600


Dim loud As Integer = 200

For i = 1 To 10 Step 1
System.Console.Beep(loud, 200)
txtLoopResultBox.Text = txtLoopResultBox.Text & "Line " & i & Wrap
If i < 5 Then
wait()
Else
loud = loud + 50
waitTime = waitTime - 100
End If


Next i
End Sub

Thursday, September 2, 2010

Thursday, September 2nd

Hi!

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