Sunday, October 31, 2010

Sunday October 21st 2010


Dim dtCurrent As System.DateTime
Dim iHour As Integer

dtCurrent = dtCurrent.Now()
iHour = dtCurrent.Hour

If (iHour < 12) Then
Console.WriteLine("Good morning!")
ElseIf (iHour >= 12) And (iHour < 18) Then
Console.WriteLine("Good afternoon!")
Else
Console.WriteLine("Good evening!")
End If
Console.ReadLine()




Dim temp As Integer = 32


For i = 1 To temp
If temp <= 32 Then
If temp = 32 Then
Console.WriteLine("temp = 32")
Else
Console.WriteLine("Temp: {0}", temp)
End If
End If
' I added a cool sound effect here just for fun
System.Console.Beep(10 * temp + 40, 7 * temp + 35)

temp = temp - 1
Next i



Dim superString As String

superString = Console.ReadLine()

If superString.Length > 10 Then
Console.WriteLine("Your string is longer than ten")
Else
Console.WriteLine("Your string is less than ten")
End If

Dim length As Integer = superString.Length

For i = 0 To superString.Length - 1
Console.WriteLine(superString.Chars(i))
System.Console.Beep(100 + i * 5 + 40, 100 + i * 4 + 40)

Next

Friday, October 29, 2010

Friiday, October 29th 2010



Public Class Rectangle

Dim dblLength As Double
Dim dblWidth As Double



Public Function CalculateArea() As Double
Return (dblLength * dblWidth)
End Function

Sub New(ByVal [_length] As Double, ByVal [_width] As Double)
dblLength = _length
dblWidth = _width

End Sub

End Class



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myLength As Double = InputBox("Please enter the length of the box")
Dim myWidth As Double = InputBox("Please enter the width of the box")

Dim myRectangle As New Rectangle(myLength, myWidth)
Me.Label1.Text = "The area is: " & myRectangle.CalculateArea

makeRectangle(myLength, myWidth)


End Sub

Public Sub makeRectangle(ByVal myLength, ByVal myWidth)


Dim firstX, firstY, secondX, secondY As Integer

firstY = 30
firstX = 30
secondY = firstY
secondX = (firstX + myLength) * 2

drawLine(firstX, firstY, secondX, secondY)

firstY = (30 + myWidth) * 2
firstX = 30
secondY = firstY
secondX = (firstX + myLength) * 2

drawLine(firstX, firstY, secondX, secondY)


firstY = 30
firstX = 30
secondY = (firstY + myWidth) * 2
secondX = firstX

drawLine(firstX, firstY, secondX, secondY)

firstY = 30
firstX = (30 + myLength) * 2
secondY = (firstY + myWidth) * 2
secondX = firstX

drawLine(firstX, firstY, secondX, secondY)

End Sub

Private Sub drawLine(ByVal firstX As Integer, ByVal firstY As Integer, ByVal secondX As Integer, ByVal secondY As Integer)
Dim myGraphics As Graphics
Dim myPen As Pen

'’ set the color and the width of the pen
myPen = New Pen(Color:=Color.Blue, Width:=2)

'’ set where the graphics will be drawn
myGraphics = Graphics.FromHwnd(hwnd:=ActiveForm().Handle)

'’ draw the line between two points
myGraphics.DrawLine(pen:=myPen, x1:=firstX, y1:=firstY, x2:=secondX, y2:=secondY)
End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Thursday, October 28, 2010

Thursday, 10/28/2010

Here is a tutorial done by Evangelos Petroutsos


Dim Payment As Double
Dim LoanIRate As Double
Dim LoanDuration As Integer
Dim LoanAmount As Integer

' Validate amount
If IsNumeric(txtAmount.Text) Then
LoanAmount = Convert.ToInt32(txtAmount.Text)
Else
MsgBox("Please enter a valid amount.")
Exit Sub
End If
' Validate interest rate
If IsNumeric(txtRate.Text) Then
LoanIRate = 0.01 * Convert.ToDouble(txtRate.Text) / 12
Else
MsgBox("Invalid interest rate, please re-enter.")
Exit Sub
End If
'Validate loan's duration
If IsNumeric(txtDuration.Text) Then
LoanDuration = Convert.ToInt32(txtDuration.Text)
Else
MsgBox("Please specifiy the loan's duration as a number of months")
Exit Sub
End If
'If all data were validated, proceed with calculations
Dim payEarly As DueDate
If chkPayEarly.Checked Then
payEarly = DueDate.BegOfPeriod
Else
payEarly = DueDate.EndOfPeriod
End If
Payment = Pmt(LoanIRate, LoanDuration, -LoanAmount, 0, payEarly)
txtPayment.Text = Payment.ToString("#.00")


Here is a rich text editor with lots of dialog boxes dealing with saving, loading etc.


Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click

End Sub

Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
txtField.Clear()

End Sub

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Try
Dim dlg As OpenFileDialog = New OpenFileDialog
dlg.Title = "Open"
dlg.Filter = "Rich Text Files (*.rtf) | *.rtf"
If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
txtField.LoadFile(dlg.FileName)
End If
Catch ex As Exception : End Try
End Sub

Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
Try
Dim dlg As SaveFileDialog = New SaveFileDialog
dlg.Title = "Save"
dlg.Filter = "Rich Text Files (*.rtf) | *.rtf"
If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
txtField.SaveFile(dlg.FileName, RichTextBoxStreamType.RichText)
End If
Catch ex As Exception : End Try
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub

Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.Click

End Sub

Private Sub UnoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UnoToolStripMenuItem.Click
txtField.Undo()

End Sub

Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
Try
Dim dlg As FontDialog = New FontDialog
dlg.Font = txtField.Font
If dlg.ShowDialog = System.Windows.Forms.DialogResult.OK Then
txtField.Font = dlg.Font
End If
Catch ex As Exception

End Try
End Sub

Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
Try
Dim dlg As ColorDialog = New ColorDialog
dlg.Color = txtField.ForeColor
If dlg.ShowDialog = System.Windows.Forms.DialogResult.OK Then
txtField.ForeColor = dlg.Color
End If
Catch ex As Exception

End Try
End Sub


I also did a tutorial on do while loops


Dim Num1 As Integer = 1

Do While Num1 <= 10
MessageBox.Show("the value of the variable is: " & Num1)
Num1 = Num1 + 1
Loop

Tuesday, October 26, 2010

Tuesday, October 26 2010

Here is the code for the finished program I made, the one that draws a line.


Private Sub form1_mousedown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
mouseClickCounter = mouseClickCounter + 1

If mouseClickCounter = 1 Then
firstX = e.X
firstY = e.Y
messageToMe(firstX, firstY)
ElseIf mouseClickCounter = 2 Then
secondX = e.X
secondY = e.Y

Dim myGraphics As Graphics
Dim myPen As Pen

myPen = New Pen(Color:=Color.Black, Width:=2)
myGraphics = Graphics.FromHwnd(hwnd:=ActiveForm().Handle)

myGraphics.DrawLine(pen:=myPen, x1:=firstX, y1:=firstY, x2:=secondX, y2:=secondY)
messageToMe(secondX, secondY)

firstX = 0
firstY = 0
secondX = 0
secondY = 0
mouseClickCounter = 0

End If


End Sub

Public Sub messageToMe(ByVal X As Integer, ByVal Y As Integer)
MessageBox.Show("Hello!" & " " & mouseClickCounter & vbTab & "(" & X & ", " & Y & ")")
End Sub
End Class

Monday, October 25, 2010

Monday, October 25th 2010

Me preliminary course load for the upcoming Spring semester:


Scripting 23122 CSYS 2033-190
VB.net / ASP / SQL 22290 CSCI 2893-101
PHP Programming 23990 CSYS 2463-101
Principles of Microeconomics 21483 ECON 2023-313
Intermediate Algebra 22638 March 0123-316


I hope that none of these classes will be canceled.


Overloads Function CountFiles(ByVal minSize As Integer, ByVal maxSize As Integer) As Integer
Debug.WriteLine("You've reqested the files between " & minSize & " and " & maxSize & " bytes.")
Dim files() As String
files = System.IO.Directory.GetFiles("c:\windows")
Dim i, fileCount As Integer
For i = 0 To files.GetUpperBound(0)
Dim FI As New System.IO.FileInfo(files(i))
If FI.Length >= minSize And FI.Length <= maxSize Then
fileCount = fileCount + 1
End If
Next
Return (fileCount)
End Function

Overloads Function CountFiles(ByVal fromDate As Date, ByVal toDate As Date) As Integer
Debug.WriteLine("You've requested the count of files creadted from " & fromDate & " to " & toDate)
Dim files() As String
files = System.IO.Directory.GetFiles("C:\windows")
Dim i, fileCount As Integer
For i = 0 To files.GetUpperBound(0)
Dim FI As New System.IO.FileInfo(files(i))
If FI.CreationTime.Date >= fromDate And FI.CreationTime.Date <= toDate Then
fileCount = fileCount + 1
End If
Next
Return (fileCount)
End Function

Overloads Function CountFiles(ByVal type As String) As Integer
Debug.WriteLine("You've requested the " & type & " files")
'Function Implementation
End Function

Overloads Function CountFiles(ByVal minSize As Integer, ByVal maxSize As Integer, ByVal type As String) As Integer
Debug.WriteLine("You've requested the " & type & " files between " & minSize & " and " & maxSize & " bytes")
End Function

Overloads Function CountFiles(ByVal fromDate As Date, ByVal toDate As Date, ByVal type As String) As Integer
Debug.WriteLine("You've requested teh " & type & " files created from " & fromDate & " to " & toDate)
End Function




Try
Dim num_Items As Integer = Integer.Parse("12345678")
Catch ex As Exception
Console.WriteLine(ex.Message)

End Try





Dim a As Double = 5.687
Dim b As Int32 = 1234

Console.WriteLine(a.ToString)
Console.WriteLine(b.ToString)
Console.WriteLine(483733.2324.ToString)

Dim C As Integer
Console.WriteLine(C.GetType())
Console.WriteLine(C.GetType().ToString)

Console.ReadLine()





i = 3 Or 4
Console.WriteLine(i)
i = 2 And 4
Console.WriteLine(i)
i = 3 Xor 3
Console.WriteLine(i)
i = Not 5
Console.WriteLine(i)
Console.ReadLine()


Here is something I made about drawing lines



Dim myGraphics As Graphics
Dim myPen As Pen

Dim firstX As Integer = InputBox("Please enter the first X coordinate")
Dim firstY As Integer = InputBox("Please enter the first y coordinate")
Dim secondX As Integer = InputBox("please enter the second X coordinate")
Dim secondY As Integer = InputBox("please enter the second Y coordinate")



myGraphics = Graphics.FromHwnd(hwnd:=ActiveForm().Handle)
myPen = New Pen(Color:=Color.Blue, Width:=3)
myGraphics.DrawLine(pen:=myPen, x1:=firstX, y1:=firstY, x2:=secondX, y2:=secondY)

Friday, October 22, 2010

Friday, October 22 2010

This isn't really that fancy, but I mostly did it on my own. I am populating a textbox with more textboxes, where the textboxes location is being determined randomly. I like it.


Public Class Form1

Dim arrayName(1000) As String
Dim index As Integer = 0


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
playingField.Width = 1200
playingField.Height = 800
playingField.Left = ClientRectangle.Left + 7

Randomize()
Dim x As Integer
Dim y As Integer
Dim MyNewTextbox As New TextBox


x = (Int(Rnd() * 1150)) + playingField.Left + 3
y = (Int(Rnd() * 750)) + playingField.Top + 3

arrayName(index) = "Box" & index




index += 1
MyNewTextbox.Size = New Size(20, 20)
MyNewTextbox.Text = "0"
MyNewTextbox.Location = New Point(x, y)
MyNewTextbox.ForeColor = Color.White
MyNewTextbox.BackColor = Color.Black
MyNewTextbox.BorderStyle = BorderStyle.None
MyNewTextbox.Name = arrayName(index)

If arrayName(index) = "box5" Then
MyNewTextbox.ForeColor = Color.Red

End If

If index Mod 7 = 1 Then
MyNewTextbox.ForeColor = Color.Green
End If

Me.Controls.Add(MyNewTextbox)
MyNewTextbox.BringToFront()





End Sub

Private Sub playingField_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles playingField.TextChanged

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 0 To 1000
arrayName(i) = "box" & i
Next i

End Sub
End Class




Dim Message As String
Select Case Now.DayOfWeek
Case DayOfWeek.Monday
Message = "Have a nice week"
Case DayOfWeek.Friday
Message = "Have a nice weekend!"
Case Else
Message = "Welcome back!"

End Select

'' I added a title to the message box, I've done it before from tutorials but couldn't remeber how to do it off the top of my head.

MsgBox(Message, 0, "Title")


End Sub
End Class


These tutorials are from Evangelos Petroutsos

''The IndexOf method locates an instance of a character in a string


Dim MyText As String
MyText = "The quick brown fox jumped over the lazy dog."
Dim position, words As Integer
position = 0 : words = 0
Do While position >= 0
position = MyText.IndexOf(" ", position + 1)
words += 1
Loop
MsgBox("There are " & words & " words in the text.")



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

'' Pmt() is a built-in function for figuring out payments

Dim mPay, totalPay As Double
'' I edited this to allow the end user to put some of their own information
Dim years As Integer
Dim months As Integer

years = InputBox("How many years will you be paying the loan?")
months = monthlyOrNot()
MsgBox(months)
Dim Duration As Integer = months * years
Dim Rate As Single = (7.25 / 100) / 12
Dim Amount As Single = 20000
mPay = -Pmt(Rate, Duration, Amount)
totalPay = mPay * Duration
MsgBox("Each payment will be " & mPay.ToString("C") & vbCrLf & "You will pay back a total of " & totalPay.ToString("C"))




End Sub
Public Function monthlyOrNot()
If MsgBox("Will you be paying monthly?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Return 12
ElseIf MsgBox("Will it be quarterly?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Return 4
ElseIf MsgBox("Will the payment be bimonthly?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Return 6
Else
Return 1
End If
End Function

Thursday, October 21, 2010

Thursday 10/21/2010

Here is a quick tutorial I did off of Youtube



Dim X As Integer
Dim Num1 As Integer
Dim size1 As Integer = 1000
Dim arrayStore(size1) As Integer

Randomize()

For X = 1 To 1000
Num1 = Rnd() * 9 + 1
TextBox1.AppendText(Str(Num1))
arrayStore()
Next

Wednesday, October 20, 2010

Wednesday, October 20th 2010


Public Class Form1

Dim goRight As Boolean
Dim goBottom As Boolean
Dim tickCount As Integer

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblOne.Click

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


tickCount += 1



If lblOne.Left >= TextBox1.Right - lblOne.Width - 4 Then
goRight = False
End If

If lblOne.Left <= TextBox1.Left + 3 Then
goRight = True
End If

If goRight = True Then
lblOne.Left += 5
Else
lblOne.Left -= 5
End If


If lblOne.Top <= TextBox1.Top + 3 Then
goBottom = False
End If

If lblOne.Top >= TextBox1.Bottom - lblOne.Height - 4 Then
goBottom = True
End If




If goBottom = True Then
lblOne.Top -= 5
Else
lblOne.Top += 5
End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
goRight = True
goBottom = True

tickCount = 1
lblOne.Text = "O"
lblOne.BackColor = TextBox1.BackColor

TextBox1.Width = Me.ClientRectangle.Width - 7
TextBox1.Left = Me.ClientRectangle.Left + 3
TextBox1.Height = Me.ClientRectangle.Height - 10
TextBox1.Top = Me.ClientRectangle.Top + 5


End Sub
End Class


I added the ability to move another character around


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.Right
lblCharacter.Text = "X"
lblCharacter.Location = New Point(lblCharacter.Location.X + 5, lblCharacter.Location.Y)
Case Keys.Left
lblCharacter.Text = "X"
lblCharacter.Location = New Point(lblCharacter.Location.X - 5, lblCharacter.Location.Y)
Case Keys.Up
lblCharacter.Text = "X"
lblCharacter.Location = New Point(lblCharacter.Location.X, lblCharacter.Location.Y - 5)
Case Keys.Down
lblCharacter.Text = "X"
lblCharacter.Location = New Point(lblCharacter.Location.X, lblCharacter.Location.Y + 5)
End Select
End Sub


I also created a quick program that creates a form


Dim playingField As New TextBox
playingField.Width = 300
playingField.Height = 300
playingField.Multiline = True


Me.Controls.Add(playingField)


Here is a better version of the program to create a form



Dim textDisplay As New TextBox()
textDisplay.Location = New Point(ClientRectangle.Left + 7, ClientRectangle.Top + 7)
textDisplay.Size = New Size(200, 200)
textDisplay.Multiline = True
Me.Controls.Add(textDisplay)

Monday, October 18, 2010

Monday October 18th 2010

Working on some tutorials by Patrice Pelland. It's a bit of a nuisance navigating all the forms, etc. I can see how it is cool to be able to do these things with the design environment instead of coding it by hand, but I am just afraid that they will up and change everything with the next edition of visual basic. not sure if that concern is valid.



If e.CurrentProgress < e.MaximumProgress Then
If pbStatus.Value >= pbStatus.Maximum Then
pbStatus.Value =
pbStatus.Minimum
Else
pbStatus.PerformStep()
End If
Else
pbStatus.Value = pbStatus.Minimum
End If

Thursday, October 14, 2010

Thursday 10/14/2010

I am going to convert some psuedo-code I wrote for a class into real VB.net code.

First I am going to test to see if the general principles work.



Const month_list As String = "january february march april may june july august september october november december"


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim monthName As String
monthName = InputBox("Enter a month")
monthName = monthName.ToLower

If month_list.Contains(monthName) = True Then
MessageBox.Show("That is a month")
Else
MessageBox.Show("That is not a month")
End If
End Sub


OK here is the finished product. Debating whether or not to do a quick tutorial. Will smoke a cigarrette and walk to QT while deciding.



Public Class Form1

Const month_list As String = "january february march april may june july august september october november december"
Const month_31 As String = "january march may july august october december"
Const January_value As Integer = 31
Const February_value As Integer = 28
Const March_value As Integer = 31
Const April_value As Integer = 30
Const May_value As Integer = 31
Const June_value As Integer = 30
Const July_value As Integer = 30
Const August_value As Integer = 31
Const September_value As Integer = 30
Const October_value As Integer = 31
Const November_value As Integer = 30




Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim monthString, doAnother As String
Dim dayInteger, totalValue, totalRemainingValue As Integer
Dim i As Integer = 1
Dim yesOrNo As String
Dim totalRemaingValue As Integer = 0

Do
totalRemaingValue = 0
dayInteger = 0
totalValue = 0

monthString = ""
dayInteger = 0
getMonth(monthString)
getDay(monthString, dayInteger)
getMonthValue(monthString, dayInteger, totalValue)
totalRemaingValue = subtractTotalValue(totalValue)
txtInfo.Text = txtInfo.Text & "Entry " & i & vbTab & monthString.ToUpper & " " & dayInteger & vbTab & totalRemaingValue & " days left in the year." & vbCrLf
i += 1
yesOrNo = InputBox("Do you want to enter another date? Enter NO to stop")
yesOrNo = yesOrNo.ToLower
Loop While yesOrNo <> "no"






End Sub

Sub getMonth(ByRef monthString)
Dim monthCorrect As Boolean = False
While monthCorrect = False
While isNull(monthString) = True
monthString = InputBox("Please enter a month")
End While
monthString = monthString.ToLower
If month_list.Contains(monthString) = True Then
MessageBox.Show("You entered the month " & monthString)
monthCorrect = True
Else
MessageBox.Show("You entered " & monthString & " which is incorrect. Please try again.")
End If
End While
End Sub


Sub getDay(ByVal monthString, ByRef dayInteger)
While dayInteger = 0
dayInteger = InputBox("Please enter a date for the day.")
If dayInteger = "" Then
MessageBox.Show("Please enter a number.")
dayInteger = 0
Else
If monthString.tolower = "february" Then
If dayInteger >= 1 And dayInteger <= 28 Then
MessageBox.Show("You have entered " & monthString.ToUpper & " " & dayInteger)
Else
MessageBox.Show("You entered " & dayInteger & ". That is incorrect. Please try again.")
dayInteger = 0
End If
ElseIf month_31.Contains(monthString) Then
If dayInteger >= 1 And dayInteger <= 31 Then
MessageBox.Show("You have entered " & monthString.ToUpper & " " & dayInteger)
Else
MessageBox.Show("You entered " & dayInteger & ". That is incorrect. Please try again.")
dayInteger = 0
End If
Else
If dayInteger >= 1 And dayInteger <= 30 Then
MessageBox.Show("You have entered " & monthString.ToUpper & " " & dayInteger)
Else
MessageBox.Show("You entered " & dayInteger & ". That is incorrect. Please try again.")
dayInteger = 0
End If
End If
End If
End While
End Sub

Sub getMonthValue(ByVal monthString, ByVal dayInteger, ByRef totalValue)
Select Case monthString.tolower
Case "january"
totalValue = dayInteger
Case "february"
totalValue = dayInteger + January_value
Case "march"
totalValue = dayInteger + January_value + February_value
Case "april"
totalValue = dayInteger + January_value + February_value + March_value
Case "may"
totalValue = dayInteger + January_value + February_value + March_value + April_value
Case "june"
totalValue = dayInteger + January_value + February_value + March_value + April_value + May_value
Case "july"
totalValue = dayInteger + January_value + February_value + March_value + April_value + May_value + June_value
Case "august"
totalValue = dayInteger + January_value + February_value + March_value + April_value + May_value + June_value + July_value
Case "september"
totalValue = dayInteger + January_value + February_value + March_value + April_value + May_value + June_value + July_value + August_value
Case "october"
totalValue = dayInteger + January_value + February_value + March_value + April_value + May_value + June_value + July_value + August_value + September_value
Case "november"
totalValue = dayInteger + January_value + February_value + March_value + April_value + May_value + June_value + July_value + August_value + September_value + October_value
Case "december"
totalValue = dayInteger + January_value + February_value + March_value + April_value + May_value + June_value + July_value + August_value + September_value + October_value + November_value
End Select
End Sub

Function isNull(ByVal variableHolder)
If variableHolder = "" Then
Return True
Else
Return False
End If
End Function

Function subtractTotalValue(ByVal totalValue)
totalValue = 365 - totalValue
Return totalValue
End Function
End Class


Here I am trying to work with rectangular arrays


Dim numbersArray(7, 2) As Integer
Dim numbersString As String = ""
Dim arrayFillerOne As Integer = 0
Dim arrayFillerTwo As UInteger = 0


For integerCounter As Integer = 1 To numbersArray.GetLength(0) - 1
arrayFillerONe = integerCounter * 3
arrayFillerTwo = integerCounter * 4
numbersArray(integerCounter, 0) = arrayFillerOne

Next


For i As Integer = 0 To numbersArray.GetLength(0) - 1
For j As Integer = 0 To numbersArray.GetLength(1) - 1
numbersString &= numbersArray(i, j) & vbTab
TextBox1.Text = numbersString
Next
numbersString &= vbCrLf


Next


I think I've gotten the hang of it. It is a bit tricky to convert numbers into spaces, and vice versa.


Dim numbersArray(7, 2) As Integer
Dim numbersString As String = ""
Dim arrayFillerOne As Integer = 0
Dim arrayFillerTwo As UInteger = 0

For i = 0 To numbersArray.GetLength(0) - 1
numbersArray(i, 0) = i * 3
numbersArray(i, 1) = numbersArray(i, 0) + 5
numbersArray(i, 2) = numbersArray(i, 1) + numbersArray(i, 0)


Next i

For i As Integer = 0 To numbersArray.GetLength(0) - 1
For j As Integer = 0 To numbersArray.GetLength(1) - 1
numbersString &= numbersArray(i, j) & vbTab
TextBox1.Text = numbersString
Next
numbersString &= vbCrLf
Next

Tuesday, October 12, 2010

Tuesday, October 12

I am redoing the web browser tutorial by Patrice Pelland



myBrowser.Navigate(txtUrl.Text)


This is the basic command, feeding the url from a textbox into the web browser.


My.Application.MinimumSplashScreenDisplayTime = 3500


I set up a splash screen again.

Monday, October 11, 2010

Monday, October 11, 2010

I am working on some console arrays from www.java2s.com


Sub Main()
Dim myInt As Integer = 7
Console.WriteLine("Initialzed myInt: {0}", myInt)
myInt = 5
Console.WriteLine("After assingment: myInt: {0}", myInt)

End Sub



Tutorial 2.3

Sub Main()
Dim n As Integer

n = 16
n += 102.3
n.ToString()
Console.WriteLine("Addition " & n)

n = 24
n -= 2
Console.WriteLine("Subtraction " & n)

n = 6
n *= 10
Console.WriteLine("Multiplication " & n)

n = 12
n /= 6
Console.WriteLine("Division " & n)

Console.ReadLine()

End Sub


Here is tutorial 2.2.4


Dim firstValue As Integer = 117
Dim secondValue As Integer = 123
Console.WriteLine("Before swap: {0}, {1}", firstValue, secondValue)
System.Threading.Thread.Sleep(700)

firstValue = firstValue Xor secondValue
Console.WriteLine("{0}, {1} ", firstValue, secondValue)
System.Threading.Thread.Sleep(800)

secondValue = firstValue Xor secondValue
Console.WriteLine("{0}, {1} ", firstValue, secondValue)
System.Threading.Thread.Sleep(800)

firstValue = firstValue Xor secondValue
Console.WriteLine("After swap: {0}, {1} ", firstValue, secondValue)
System.Threading.Thread.Sleep(2700)


Here is the next tutorial


Dim iNum As Integer
Console.WriteLine("Integer: " & iNum.MinValue & " to " & iNum.MaxValue)
Console.ReadLine()


Here is the next tutorial, with a try...catch...


Try
Dim numItams As Integer = Integer.Parse("123")

Catch ex As Exception
Console.WriteLine(ex.Message)

End Try


I also did a tutorial by Anne Boehm on arrays.


Dim arrayNumbers(9) As Integer
Dim numbersString As String = " "

For i As Integer = 0 To arrayNumbers.Length - 1
arrayNumbers(i) = i + 1
Next i

For Each number As Integer In arrayNumbers
numbersString &= number.ToString & " "
Next
MessageBox.Show(numbersString, "Numbers Test")

Thursday, October 7, 2010

Thursday October 7th

I've turned some of the psuedo code I have been writing in class to real code. Here is the first part


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim inputNumber As Integer = 0
Dim i As Integer = 1
Dim numberArray(100) As Integer
Dim arrayCount As Integer = 0

Dim maxNumber As Integer = 0



While inputNumber <> -99
inputNumber = InputBox("Input the number, enter -99 when done.")
numberArray(arrayCount) = inputNumber
arrayCount = arrayCount + 1
i = i + 1
End While


TextBox1.Text = arrayCount - 1


End Sub
End Class



I finally got this to work. I have to convert it into pseudocode, which I will post here as well if I get the chance.





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim inputNumber As Integer = 0
Dim i As Integer = 0
Dim numberArray(100) As Integer
Dim arrayCount As Integer = 0

Dim maxNumber As Integer = 0



While inputNumber <> -99
inputNumber = InputBox("Input the number, enter -99 when done.")
numberArray(arrayCount) = inputNumber
i = i + 1
arrayCount = arrayCount + 1

End While


'' The last number entered is -99, and we don't want that to count as part of the array, right?
TextBox1.Text = "The last number you entered (excluding -99) was " & numberArray(i - 2).ToString & vbCrLf
TextBox1.Text = TextBox1.Text & "The array count is " & arrayCount & vbCrLf

TextBox1.Text = TextBox1.Text & "The numberArray(arrayCount - 2) is " & numberArray(arrayCount - 2) & vbCrLf


Call compare(i, numberArray, arrayCount, maxNumber)

TextBox1.Text = TextBox1.Text & "The maximum number is " & maxNumber & vbCrLf

End Sub


Sub compare(ByVal i As Integer, ByVal numberArray As Array, ByVal arrayCount As Integer, ByRef maxNumber As Integer)
i = i - 3
arrayCount = arrayCount - 2
While i >= 1
If numberArray(arrayCount) > numberArray(i) Then
maxNumber = numberArray(arrayCount)
TextBox1.Text = TextBox1.Text & numberArray(arrayCount) & " > " & numberArray(i) & vbCrLf
i = i - 1
Else
TextBox1.Text = TextBox1.Text & numberArray(arrayCount) & " < " & numberArray(i) & vbCrLf
maxNumber = numberArray(i)
arrayCount = i
i = i - 1

End If
End While

End Sub

Monday, October 4, 2010

Monday, October 4th 2010

I'm going to be continuing to work on the Halvorson tutorials. I am comfortable working with the tutorials that Michael Halvorson has designed, they're fun, they're well paced and build on each other(I think the word I am looking for is they are incremental?)

array.sort
array.find
array.reverse
array.copy
array.clear

According to Halvorson, these are the most useful methods for dealing with arrays.



Public Class Form1

Dim RandArray(0 To 499) As Long

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

ProgressBar1.Minimum = 0
ProgressBar1.Maximum = UBound(RandArray)
lblCounter.Text = UBound(RandArray) + 1

End Sub

Private Sub txtDisplay_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDisplay.TextChanged

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
txtDisplay.Text = ""
For i = 0 To UBound(RandArray)
RandArray(i) = Int(Rnd() * 1000000)
txtDisplay.Text = txtDisplay.Text & RandArray(i) & vbCrLf
ProgressBar1.Value = i
Next
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
txtDisplay.Text = ""
Array.Sort(RandArray)
For i = 0 To UBound(RandArray)
txtDisplay.Text = txtDisplay.Text & RandArray(i) & vbCrLf
ProgressBar1.Value = i
Next
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim i As Integer
txtDisplay.Text = ""
Array.Sort(RandArray)
Array.Reverse(RandArray)
For i = 0 To UBound(RandArray)
txtDisplay.Text = txtDisplay.Text & RandArray(i) & vbCrLf
ProgressBar1.Value = i
Next
End Sub
End Class


I also worked with a tutorial written by Anne Boehm



Dim numbers(10) As Integer
For i As Integer = 0 To numbers.Length - 1
numbers(i) = i
Next

Dim numbersString As String = ""
For i As Integer = 0 To numbers.Length - 1
numbersString &= numbers(i).ToString & vbCrLf
Next
TextBox1.Text = numbersString

Dim sum As Decimal
For i As Integer = 0 To numbers.Length - 1
sum += numbers(i)
Next
Dim average As Decimal = sum / numbers.Length
TextBox1.Text = TextBox1.Text + "The average is: " & average.ToString


Here is a tutorial by Patrice Pelland that I modified a little


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.lblApplicationStatus.Text = "Ready"
WebBrowser.Navigate("about:blank")

End Sub

Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
Dim address As String = txtAddress.Text
Me.lblApplicationStatus.Text = "Waiting for: " + address
WebBrowser.Navigate(address)

End Sub

Private Sub WebBrowser_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser.DocumentCompleted

If ((Not (WebBrowser.IsBusy)) And (WebBrowser.ReadyState = WebBrowserReadyState.Complete)) Then
If My.Application.Info.Title <> "" Then
Me.Text = My.Application.Info.Title + " - " +
e.Url.Host.ToString()
Else
Me.Text = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName) + " - " +
e.Url.Host.ToString()
End If
Me.lblApplicationStatus.Text = "Ready"
End If
End Sub

Private Sub WebBrowser_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser.ProgressChanged
If e.CurrentProgress < e.MaximumProgress Then
If pbStatus.Value >= pbStatus.Maximum Then
pbStatus.Value = pbStatus.Minimum
Else
pbStatus.PerformStep()
End If
Else
pbStatus.Value = pbStatus.Minimum
End If
End Sub

Friday, October 1, 2010

October 1st 2010

Howdy!

I'm going to do a quick tutorial on fixed arrays written by Michael Halvorson.


Public Class Form1

Dim Temperatures(0 To 6) As Single

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

End Sub

Private Sub btnTemps_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTemps.Click
Dim prompt, title As String
Dim i As Short
prompt = "Enter the day's high temperature."

'' the UBound function will be used for future flexibility
For i = 0 To UBound(Temperatures)
title = "Day " & (i + 1)
Temperatures(i) = InputBox(prompt, title)
Next
End Sub

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim Result As String
Dim i As Short
Dim Total As Single = 0
Result = "High temperatures for the week:" & vbCrLf & vbCrLf
For i = 0 To UBound(Temperatures)
Result = Result & "Day " & (i + 1) & vbTab & _
Temperatures(i) & vbCrLf
Total = Total + Temperatures(i)
Next
''notice how result is repeated on both sides of the equal side to preserve the information
Result = Result & vbCrLf & _
"Average temperature: " & Format(Total / 7, "0.0")
txtDisplay.Text = Result
End Sub
End Class