' NOTES:
' First and most important, you won't understand everything in this program anytime
' soon, there is a lot here. Just try to learn what you can the rest will come with time.
' You may see that a lot of the code is hidden in parts of code using "#Region"
' and "#End Region". This helps keep the code seperated and makes it easier to find
' certain parts of code. I like using region for every method and one for the
' constructor(s).
' A method (subroutine/function) will start with "Sub/Function" and end with
' "End Sub/End Function". The difference is that you can return a value from a Function.
' Look For the region named TestSub and TestFunction for some examples.
' When ever you see a line start with ' or "Rem", it is for commenting code and is never compiled into the final program.
' We will use 3 basic data types to keep thing simple:
' Integer - A number which can hold a value from -2,147,483,648 to +2,147,483,647 - Example: 1,250,000
' Single - A number that can have decimals - Example: 57.2548
' String - Text - Example: "This is a quote"
' Boolean - Has only two states, true/false or 1/0, 1 being true and 0 false
' A varible is just that a varible. Its an object we create to store a value which can change. Examples below:
' Dim MyVarible As Integer
' Dim SomeText As String
' Dim HourlyWage As Single
' "Me" is more or less the equivelent as to the name of the class, in this case "MyWindow"
Public Class MyWindow
Inherits System.Windows.Forms.Form
#Region "Constructor"
Public Sub New()
MyBase.New()
Me.InitializeComponent()
End Sub
#End Region
#Region "Declarations"
' Nothing to do here...
#End Region
#Region "Designer Generated Stuff"
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.SuspendLayout()
'
'MyWindow
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 264)
Me.Name = "MyWindow"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
' There is to return type on a sub.
Private Sub TestSub(ByVal FirstNumber As Integer, ByVal SecondNumber As Integer)
' Here we the numbers a and b to test function to be added together.
Me.Text = TestFunction(FirstNumber, SecondNumber)
End Sub
' Here we can see the return type as being an integer -----------> [----------]
Private Function TestFunction(ByVal a As Integer, ByVal b As Integer) As Integer
' And here we return the two numbers added together.
Return a + b
End Function
' Now, on to something that actually does something :)
' This Will display some text in a label that flashes between two colors every second. But first, we need to determine
' what a second is. To do that we create a timer. The next step will be when this window loads (a method called an event handler), we
' set some properties that sets how often the timer "fires", in this case ever second. Finally, we will have the last method (which
' is also an event handler) handler the "firing of the timer and that code will cause the text in the label change colors.
' Forgot the label, we also want to create it and set its properties when we do the timers.
Friend WithEvents OurSecondTimer As System.Windows.Forms.Timer ' This is our timer
Friend WithEvents OurLabel As System.Windows.Forms.Label ' Our label
' The is the event handler that gets "fired" when the window is loading. This is where we set some properties for the timer. We
' will even toss is the method "TestSub" here too.
Private Sub MyWindow_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Here we set "HisAge" and "HerAge" to whatever you want...
Dim HisAge As Integer = 100
Dim HerAge As Integer = 100000' :)
' Now we pass the two ages together to be added and sets the windows title.
TestSub(HisAge, HerAge)
' Create a new timer and set the timers properties.
Me.OurSecondTimer = New System.Windows.Forms.Timer ' We need to create a new instance of our timer and store it in "OurSecondTimer" varible.
Me.OurSecondTimer.Interval = 1000 ' Here we set how often in milliseconds we want the timer to "fire" its event.
' Time for ice cream break :)
' Now create the label and set its properties.
Me.OurLabel = New System.Windows.Forms.Label ' Create a new instance of the timer.
Me.OurLabel.Text = "Some mushy stuff here! Not dead" & vbCrLf & "center either for some odd reason :("' Set the labels text.
Me.OurLabel.AutoSize = False ' Turn auto size off so we can set th width ourselfs.
Me.OurLabel.Width = 200' The label will be 200 pixels wide.
Me.OurLabel.Height = 24' The label will be 24 pixels high.
Me.OurLabel.TextAlign = ContentAlignment.MiddleCenter ' Set the text to the center of the label.
Me.OurLabel.Location = New Point((Me.Width / 2) - (Me.OurLabel.Width / 2), (Me.Height / 2) - (Me.OurLabel.Height / 2)) ' We positioned the label to the center of the window here.
Me.OurLabel.ForeColor = Color.Black' Make sure the default color is black
' We need to "add" the label to the window so we can see it.
Me.Controls.Add(Me.OurLabel)
' Last but not least, we need to start the timer.
Me.OurSecondTimer.Start()
End Sub
' Our timer fires every second and the event handler "OurSecondTimer_Tick" does what we want and we want to changed the color of the text in our label.
Private Sub OurSecondTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles OurSecondTimer.Tick
If Me.OurLabel.ForeColor = Color.Black Then
' The the forecolor (the text) is black, then lets make it red.
Me.OurLabel.ForeColor = Color.Red
Else
' If the color was anything other than black, make it black
Me.OurLabel.ForeColor = Color.Black
End If
End Sub
' Well, there is a start, any questions, just hollar...
End Class