Thursday, September 23, 2010

Thursday, September 23rd 2010

Using another tutorial by Evangelos Petroutsos




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 new password must contain at least one special symbol!")

End If
End While
End Sub

Wednesday, September 22, 2010

Wednesday, September 22


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If My.Computer.Clipboard.ContainsText Then
TextBox1.Text = System.DateTime.Now
TextBox1.Text = TextBox1.Text + vbNewLine
TextBox1.Text = TextBox1.Text + My.Computer.Clipboard.GetText

End If
End Sub




Public time As String
Public stringClipboard As String

Public Function getTime()
Dim dateTimeInfo As String = System.DateTime.Now
Return dateTimeInfo

End Function


Public Function getString()
Dim clipboard1 As String = My.Computer.Clipboard.GetText
Return clipboard1

End Function

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



time = getTime()
stringClipboard = getString()



If My.Computer.Clipboard.ContainsText Then
TextBox1.Text = TextBox1.Text + time + vbNewLine
TextBox1.Text = TextBox1.Text + stringClipboard + vbNewLine


End If
End Sub

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


End Sub




Public time As String
Public stringClipboardNew As String
Public pastText As String
Public i As Integer

Public Function getTime()
Dim dateTimeInfo As String = System.DateTime.Now
Return dateTimeInfo

End Function


Public Function getString()
Dim clipboard1 As String = My.Computer.Clipboard.GetText
Return clipboard1

End Function

Public Sub printSomething()
TextBox1.Text = TextBox1.Text + time + vbNewLine
TextBox1.Text = TextBox1.Text + stringClipboardNew + vbNewLine
End Sub

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



time = getTime()
stringClipboardNew = getString()
i += 1

If stringClipboardNew = pastText Then
Else
If i <= 1 Then
If My.Computer.Clipboard.ContainsText Then
Call printSomething()
pastText = stringClipboardNew
Else
Call printSomething()
End If
End If
End If


End Sub

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

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub


This is the final version of what I was try to do, it didn't work out so well, but it kind of works



Public time As String
Public stringClipboardNew As String
Public pastText As String
Public i As Integer

Public booleanResult As Boolean


Public Function getTime()
Dim dateTimeInfo As String = System.DateTime.Now
Return dateTimeInfo

End Function


Public Function getString()
Dim clipboard1 As String = My.Computer.Clipboard.GetText
Return clipboard1

End Function

Public Sub printSomething()
TextBox1.Text = TextBox1.Text + time + vbNewLine
TextBox1.Text = TextBox1.Text + stringClipboardNew + vbNewLine
End Sub

Public Sub compare(ByVal pastText As String)

stringClipboardNew = getString()
If pastText = stringClipboardNew Then
booleanResult = True
Else
booleanResult = False
End If

Return



End Sub

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



time = getTime()


i += 1


If i <= 1 Then
If My.Computer.Clipboard.ContainsText Then
stringClipboardNew = getString()
pastText = stringClipboardNew
Call printSomething()
Else
compare(pastText)
If booleanResult = False Then
Call printSomething()
Else

End If
End If
End If




End Sub

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

End Sub

Tuesday, September 21, 2010

Tuesday, September 21 2010

I am going to start yet another set of tutorials, these written by Evangelos Petroutsos.

After I do a few of these, I hope to get back to Michael Halvorson's tutorials, which are great. Then I'll finish Anne Boehm's tutorials. Hopefully I will have all this done by mid-October.


Dim language As String
language = ComboBox1.Text
If language = "Visual Basic" Then
MsgBox("We have a winner!")
Else
MsgBox(language & "is not a bad langauge.")
End If

Monday, September 20, 2010

Monday, September 20 2010

Option Strict On is something I need to start doing, but I am not entirely sure why.

Basically, it seems to make it easier to debug your programs.

Here is the tutorial I wrote, based off of a tutorial from www.java2s.com/tutorial/vb



Module Module1

Public negative As Long = 33

Sub beepUp(ByRef negative)
For i = 1 To 10
Console.Beep(200, 200)
Threading.Thread.Sleep(1000)
negative += 3
Console.WriteLine(negative)
Next i
End Sub

Sub Main()
Dim maxValue As Byte = &HFF
Dim posValue As UInteger = &HF034
Dim negValue As Integer = &HF034
Dim negative As Long = -44

Console.WriteLine(maxValue)
Console.WriteLine(posValue)
Console.WriteLine(negValue)

Call beepUp(negative)


Console.WriteLine(negative)

For i = 1 To 10
Console.Beep(200, 200)
Threading.Thread.Sleep(1000)
negative += -2
Console.WriteLine(negative)
Next i

End Sub

I added a lot to this, including the subroutine, the loops, the long value, etc.


End Module


I then made the following changes - created a Sub called beepUp that replaced the for i function, and changed it to byVal. I think I more or less have byVal and byVar fixed in my head.


Module Module1

Public negative As Long = 33

Sub beepUp(ByRef negative)
For i = 1 To 10
Console.Beep(200, 200)
Threading.Thread.Sleep(1000)
negative += 3
Console.WriteLine(negative)
Next i
End Sub

Sub beepDown(ByVal negative)
For i = 1 To 10
Console.Beep(300, 250)
Threading.Thread.Sleep(500)
negative += -5
Console.WriteLine(negative)
Next
End Sub

Sub Main()
Dim maxValue As Byte = &HFF
Dim posValue As UInteger = &HF034
Dim negValue As Integer = &HF034
Dim negative As Long = -44

Dim craziness As Integer

craziness = negative

Console.WriteLine(craziness)
Console.Beep(100, 300)
Console.WriteLine(negative)
Console.Beep(100, 300)

Console.WriteLine(maxValue)
Console.WriteLine(posValue)
Console.WriteLine(negValue)

Call beepUp(negative)


Console.WriteLine(negative)

Call beepDown(negative)

Console.WriteLine(negative)


Call beepUp(negative)

End Sub

End Module


I also did another one of their console tutorials.




Sub main()
Dim result As New System.Text.StringBuilder()
result.AppendLine("MaxValue...")


Dim maxByte As Byte = Byte.MaxValue
Dim maxSByte As SByte = SByte.MaxValue
Dim maxShort As Short = Short.MaxValue
Dim maxUShort As UShort = UShort.MaxValue
Dim maxInteger As Integer = Integer.MaxValue
Dim maxUInteger As UInteger = UInteger.MaxValue
Dim maxLong As Long = Long.MaxValue
Dim maxULong As ULong = ULong.MaxValue

result.Append("Byte = ").AppendLine(CStr(maxByte))
result.Append("SByte = ").AppendLine(CStr(maxSByte))
result.Append("Short = ").AppendLine(CStr(maxShort))
result.Append("UShort = ").AppendLine(CStr(maxUShort))
result.Append("Integer = ").AppendLine(CStr(maxInteger))
result.Append("UInteger = ").AppendLine(CStr(maxUInteger))


Console.WriteLine(result.ToString())
Threading.Thread.Sleep(3000)

End Sub


I did another tutorial, only with option explicit set to On. I also changed the addition into a function.


Option Explicit On

Module Module1

Public sumOfNumbers As Integer

Function addition(ByVal number1 As Integer, ByVal number2 As Integer)
sumOfNumbers = number1 + number2 ''add numbers
Return sumOfNumbers
End Function

Sub Main()
Dim firstNumber, secondNumber As String
Dim number1, number2, sumOfNumbers As Integer
firstNumber = CStr(10)
secondNumber = CStr(20)

number1 = CInt(firstNumber)
number2 = CInt(secondNumber)

Call addition(number1, number2)


sumOfNumbers = number1 + number2 ''add numbers
Console.WriteLine("The is is {0}", sumOfNumbers)

System.Console.Beep(300, 300)

Threading.Thread.Sleep(3000)

End Sub
End Module


Here is another tutorial I worked on


Dim n As Integer
System.Console.Beep(200, 200)
n = 10
n += 5
n = CStr(n)
Console.WriteLine("addition " & n)

Threading.Thread.Sleep(1000)
System.Console.Beep(200, 200)

n = 10
n -= 5
n = CStr(n)
Console.WriteLine("subtraction " & n)

Threading.Thread.Sleep(1000)
System.Console.Beep(200, 200)

n = 10
n *= 5
n = CStr(n)
Console.WriteLine("multiplication " & n)

Threading.Thread.Sleep(1000)
System.Console.Beep(200, 200)

n = 10
n /= 5
n = CStr(n)
Console.WriteLine("multiplication " & n)
Threading.Thread.Sleep(1000)
System.Console.Beep(200, 200)

Friday, September 17, 2010

Friday, September 17th 2010

Using a Patrice Pelland tutorial I was able to add a splash screen to one of the applications I am developing. It is quite cool.

The one bit of real code from it is


My.Application.MinimumSplashScreenDisplay.Time = 3500
http://www.blogger.com/post-edit.g?blogID=1128425782735047114&postID=4743475277019314193


I also added an about to the program


AboutBox1.ShowDialog()

Thursday, September 16, 2010

Thursday, September 16th 2010

I wanted the number randomizer program to produce three new random numbers, which wasn't happening, so I modified it a bit.

The problem is that I don't have a random number for the first low.




Function randomizer(ByVal Low As Long) As Integer

Randomize()
Dim rndNumber As Random
rndNumber = New Random
number = rndNumber.Next(Low, 1001)
Return Number
End Function

Private Sub btnRandomize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRandomize.Click
Dim numberOne As Integer
Dim numberTwo As Integer
Dim numberThree As Integer
numberOne = randomizer(4)
txtNumberOne.Text = numberOne
numberTwo = randomizer(numberOne)
txtNumberTwo.Text = numberTwo
numberThree = randomizer(numberTwo)
txtNumberThree.Text = numberThree

End Sub


I then decided to use the current second as the seed number



Private Sub btnRandomize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRandomize.Click

Dim numberOne As Integer
Dim numberTwo As Integer
Dim numberThree As Integer


numberOne = randomizer((Second(Now())))
txtNumberOne.Text = numberOne
numberTwo = randomizer(numberOne)
txtNumberTwo.Text = numberTwo
numberThree = randomizer(numberTwo - (Second(Now())))
txtNumberThree.Text = numberThree

If numberThree < 100 Then System.Console.Beep(200, 200)

End Sub


Finally, I added some things to make the fire emergency for the game.



Sub disasterCheck()

Dim numberOne As Integer
Dim numberTwo As Integer
Dim numberThree As Integer


numberOne = randomizer((Second(Now())))
numberTwo = randomizer(numberOne)
numberThree = randomizer(numberTwo - (Second(Now())))

If numberThree < 50 Then


0 Then
Call fire()

Else

End If

If (numberOne + 10) > numberThree Then
generatorBroken = True
Else
generatorBroken = False
End If
End Sub

Sub fire()
firePicture.Visible = True
noButtonClock += 3
power += -2
onfire = True
End Sub


Also working on a Michael Halvorson tutorial:


Sub AddName(ByVal Team As String, ByRef ReturnString As String)
Dim Prompt, Nm, WrapCharacter As String
Prompt = "Enter a " & Team & " employee."
Nm = InputBox(Prompt, "Input Box")
WrapCharacter = Chr(13) + Chr(10)
ReturnString = Nm & WrapCharacter
End Sub


Adapting a tutorial from Patrice Peland I was able to add a save feature, which was very very cool.

Here is the code from that


Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As _
System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
Try
My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, _
Me.txtSales.Text & vbCrLf, False)
My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, _
Me.txtMkt.Text & vbCrLf, True)
Catch fileException As ApplicationException
Throw fileException
End Try
End Sub


Note that I had a lot of trouble with this, not least of which was adding "false" or "true" to the end of the arguments.

Wednesday, September 15, 2010

Wednesday, September 15th 2010

here is the code from the Lucky 7 tutorial by Michael Halvorson


Function HitRate(ByVal Hits As Short, ByVal Tries As Short) As String
Dim percent As Single
percent = Hits / Tries
Return Format(percent, "0.0%")
End Function


This isn't the first function that I have written although I am not entirely sure on what it is or what it is for.



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PictureBox1.Visible = False
Randomize()
Label1.Text = CStr(Int(Rnd() * 10))
Label2.Text = CStr(Int(Rnd() * 10))
Label3.Text = CStr(Int(Rnd() * 10))
Spins = Spins + 1

If (Label1.Text = "7") Or (Label2.Text = "7") _
Or (Label3.Text = "7") Then
PictureBox1.Visible = True
Beep()
Wins = Wins + 1
lblWins.Text = "Wins: " & Wins
End If

lblRate.Text = HitRate(Wins, spins)

End Sub


I added subs to my radiation computer game



Sub emergencyVentAction()
pressure += -30
power += -20
score += 10
End Sub

Sub bathAction()
pressure += 5
radiation += -25
power += -20
score += 10
End Sub


Finally I am including here my own program using a function


Public Class Form1
Public number As Integer

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

Function randomizer() As Integer
Dim rndNumber As Random
rndNumber = New Random
number = rndNumber.Next(1, 1001)
Return number
End Function

Private Sub btnRandomize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRandomize.Click
Dim numberOne As Integer
numberOne = randomizer()
MsgBox(numberOne)
End Sub
End Class