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

Wednesday, September 29, 2010

Wednesday, September 29 2010

I'm still looking at the tutorials Evangelos Petroutsos wrote, they are quite good.

I'd like to finish the tutorials by Halverson in his book Visual Basic 2005 Step by Step Overall I've really liked his tutorials. I think it would be good to finish a book in the near future.

Here is a quick example tutorial from Petrousos



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim password As String, ch As Char
Dim i As Integer
Dim valid As Boolean = False
While Not valid
password = InputBox("Please enter your password.")
For i = 0 To password.Length - 1
ch = password.Chars(i)
If Not Char.IsLetterOrDigit(ch) Then
valid = True
Exit For
End If
Next
If valid Then
MsgBox("Your new password will be activated immediately!")
Else
MsgBox("Your password must contain at least one special symbol!")
End If
End While
End Sub
End Class


I also made up my own small program using as an assignment from the Petroutsos book.



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim firstName(4) As String
Dim lastName(4) As String

For i = 1 To 5
firstName(i + 1) = InputBox("Please enter the first name.")
lastName(i + 1) = InputBox("Please enter the last name.")
txtDisplay.Text = txtDisplay.Text + firstName(i + 1) & " " & lastName(i + 1) & vbCrLf
Next i
End Sub

Monday, September 27, 2010

Monday, September 27th 2010

I did this tutorial on functions and factorials based off of a YouTube video here mkaatr's channel




Function Factorial(ByVal V As Double) As Double
Dim F As Double
Dim I As Integer
F = 1
For I = 1 To V
F = F * I

Next
Return F
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number As Double
number = CDbl(TextBox1.Text)
number = CStr(Factorial(number))
txtFactorials.Text = number
End Sub


I also did another tutorial based on ByVal and ByRef



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim number As Integer = 50
MsgBox(number)
Call byValTest(number)
MsgBox(number)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim number As Integer = 50
MsgBox(number)
Call byRefTest(number)
MsgBox(number)
End Sub


There was also a tutorial on creating a swap function




Function swap(ByRef V1 As Integer, ByRef V2 As Integer)
Dim tmp As Integer
tmp = V1
V1 = V2
V2 = tmp
End Function


There is also a quite lengthy tutorial on subroutines from mkaatr



Public Class Form1
Dim names As New Collection
Dim tels As New Collection

Sub addContact(ByVal CName As String, ByVal CTel As String)
names.Add(CName)
tels.Add(CTel)
End Sub

Sub viewContacts(ByVal DGV As DataGridView)
DGV.Rows.Clear()
Dim I As Integer
For I = 1 To names.Count
DGV.Rows.Add(names(I), tels(I))
Next
End Sub


Function GetTelForName(ByVal Name As String) As String
Dim i As Integer
For i = 1 To names.Count
If names(i) = Name Then
Return tels(i)
End If
Next
Return ""
End Function


Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

End Sub

Private Sub AddNewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewToolStripMenuItem.Click

Dim n As String
Dim t As String

n = InputBox("Enter the name of the contact:")
If n = "" Then
Exit Sub
End If

t = InputBox("Enter the tel number:")
If t = "" Then
Exit Sub
End If

addContact(n, t)
viewContacts(DataGridView1)

End Sub




Private Sub SearchToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchToolStripMenuItem.Click
Dim n As String
Dim t As String

n = InputBox("Enter the name you are searching for:")
If n = "" Then
Exit Sub
End If

t = GetTelForName(n)
If t = "" Then
MsgBox("Name not found")
Else
MsgBox("The telephone number is:" & t)
End If
End Sub
End Class