Sunday, December 19, 2010

Sunday 12/19/2010


Public Class Form1
'This is a tutorial written by Michael Halvorston towards the end of his book, "Microsoft Visual Basic 2005 Step By Step
'The book has been a big help
'I originally tried to get this to work by using several classes and writing it all out in code - but it was a bit too much making my own event handlers
'Getting there, though
'I would really like to have Mr. Halvorston's book finished by Christmas but fat chance


'Variables
Dim GoingUp As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = New System.Drawing.Bitmap("C:\Users\Alfred\Documents\VBPractice\dog.JPG")
Timer1.Enabled = False
Timer1.Interval = 500
Button1.Text = "Going Up"
Button2.Text = "Going Down"
'note this is not how the original tutorial goes, in the original tutorial Michael Halvorston has us change the properties using the Visual Studio editor

End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If GoingUp = True Then
'move picture box toward the top
If PictureBox1.Top > 10 Then
PictureBox1.Location = New Point _
(PictureBox1.Location.X - 10, _
PictureBox1.Location.Y - 10)
'didn't realize this when I typed it but this makes the picture move diagonally.
End If
Else
'move picture box toward the bottom
If PictureBox1.Top < (Me.Size.Height - 75) Then
PictureBox1.Location = New Point _
(PictureBox1.Location.X + 10, _
PictureBox1.Location.Y + 10)
End If
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GoingUp = True
Timer1.Enabled = True
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
GoingUp = False
Timer1.Enabled = True
End Sub
End Class


Here is another tutorial from Michael Halvorston


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Employee As New Person
Dim DOB As Date

Employee.FirstName = TextBox1.Text
Employee.LastName = TextBox2.Text
DOB = DateTimePicker1.Value.Date

MsgBox(Employee.FirstName & " " & Employee.LastName _
& " Is " & Employee.age(DOB) & " years old.")

End Sub
End Class

Public Class Person
Private Name1 As String
Private Name2 As String

Public Property FirstName() As String
Get
Return (Name1)
End Get
Set(ByVal value As String)
Name1 = value
End Set
End Property

Public Property LastName() As String
Get
Return Name2
End Get
Set(ByVal value As String)
Name2 = value
End Set
End Property

'Create a method
Public Function age(ByVal Birthday As Date) As Integer
Return Int(Now.Subtract(Birthday).Days / 365.25)
End Function
End Class

No comments: