Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim plus As Integer
Dim int As Integer
Dim dig As Integer
plus = CInt(TextBox1.Text)
dig = 0
For int = 1 To plus
dig = dig + 1
ListBox1.Items.Add(dig)
Next
End Sub
End Class
Bolten's Page
Random Stuff All The Time!!!
Fun
Monday, April 18, 2011
Loop Assignment 1
Yatzee!!!2.0
Public Class Form1
'these variables can be used anywhere in the form
Dim lblDice1, lblDice2, lblDice3, lblDice4, lblDice5 As New Label
Dim WithEvents butRoll As New Button
Dim nYatzee, nFourOfAKind, nThreeOfAKind As New Integer
Dim lblYatzee, lblFourOfAKind, lblThreeOfAKind As New TextBox
Dim rnd As New Random
Private Sub addDice(ByRef lbl As Label, ByVal x As Integer, ByVal y As Integer)
'working on the equation here, so we can call upon it when we need it in other parts of the form
lbl.Text = 0
lbl.Location = New Point(x, y)
lbl.Font = New Drawing.Font("Microsoft Sans Serif", 28.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)
lbl.Height = 40
lbl.Width = 40
End Sub
Private Sub AddCount(ByRef txt As TextBox, ByVal x As Integer, ByVal y As Integer, ByVal z As String)
'putting it in it's own sub so we can call upon it or change it without changing the entire form
txt.Text = z
txt.Location = New Point(x, y)
txt.Width = 150
End Sub
Private Sub BC(ByVal x As Integer, ByVal y As Integer, ByVal z As String)
'keeping it nice and organized
butRoll.Text = z
butRoll.Location = New Point(x, y)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'the place where all the other subs get put into
addDice(lblDice1, 10, 20)
addDice(lblDice2, 70, 20)
addDice(lblDice3, 130, 20)
addDice(lblDice4, 190, 20)
addDice(lblDice5, 250, 20)
AddCount(lblYatzee, 20, 140, "Yatzee: 0")
AddCount(lblFourOfAKind, 20, 180, "Four Of A Kind: 0")
AddCount(lblThreeOfAKind, 20, 220, "Three Of A Kind: 0")
BC(butRoll, 100, 90, "Roll")
Me.Controls.Add(lblDice1)
Me.Controls.Add(lblDice2)
Me.Controls.Add(lblDice3)
Me.Controls.Add(lblDice4)
Me.Controls.Add(lblDice5)
Me.Controls.Add(butRoll)
Me.Controls.Add(lblYatzee)
Me.Controls.Add(lblFourOfAKind)
Me.Controls.Add(lblThreeOfAKind)
End Sub
Private Sub RollDice() Handles butRoll.Click
'where all the magic happends
Dim arrNumbers() As Integer = {0, 0, 0, 0, 0, 0}
lblDice1.Text = rnd.Next(1, 7)
lblDice2.Text = rnd.Next(1, 7)
lblDice3.Text = rnd.Next(1, 7)
lblDice4.Text = rnd.Next(1, 7)
lblDice5.Text = rnd.Next(1, 7)
For Each lbl As Label In Me.Controls.OfType(Of Label)()
arrNumbers(lbl.Text - 1) += 1
Next
For Each i As Integer In arrNumbers
If i = 5 Then
nYatzee += 1
ElseIf i = 4 Then
nFourOfAKind += 1
ElseIf i = 3 Then
nThreeOfAKind += 1
End If
Next
lblYatzee.Text = "Yatzees: " & nYatzee
lblFourOfAKind.Text = "Four Of A Kind: " & nFourOfAKind
lblThreeOfAKind.Text = "Three Of A Kind: " & nThreeOfAKind
End Sub
Private Sub BC(ByVal button As Button, ByVal p2 As Integer, ByVal p3 As Integer, ByVal p4 As String)
Throw New NotImplementedException
End Sub
End Class
Sunday, April 17, 2011
For Each
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim siteName As String
Dim singleChar As Char
siteName = "HTTP://NET-INFORMATIONS.COM"
For Each singleChar In siteName
MsgBox(singleChar)
Next
End Sub
End Class
Yatzee!!!!!!
Public Class Form1
Dim lblDice1, lblDice2, lblDice3, lblDice4, lblDice5 As New Label
Dim WithEvents butRoll As New Button
Dim nYatzee, nFourOfAKind, nThreeOfAKind As New Integer
Dim lblYatzee, lblFourOfAKind, lblThreeOfAKind As New TextBox
Dim rnd As New Random
Private Sub addDice(ByRef lbl As Label, ByVal x As Integer, ByVal y As Integer)
lbl.Text = 0
lbl.Location = New Point(x, y)
lbl.Font = New Drawing.Font("Microsoft Sans Serif", 28.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)
lbl.Height = 40
lbl.Width = 40
End Sub
Private Sub AddCount(ByRef txt As TextBox, ByVal x As Integer, ByVal y As Integer, ByVal z As String)
txt.Text = z
txt.Location = New Point(x, y)
txt.Width = 150
End Sub
Private Sub BC(ByVal x As Integer, ByVal y As Integer, ByVal z As String)
butRoll.Text = z
butRoll.Location = New Point(x, y)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
addDice(lblDice1, 10, 20)
addDice(lblDice2, 70, 20)
addDice(lblDice3, 130, 20)
addDice(lblDice4, 190, 20)
addDice(lblDice5, 250, 20)
AddCount(lblYatzee, 20, 140, "Yatzee: 0")
AddCount(lblFourOfAKind, 20, 180, "Four Of A Kind: 0")
AddCount(lblThreeOfAKind, 20, 220, "Three Of A Kind: 0")
BC(butRoll, 100, 90, "Roll")
Me.Controls.Add(lblDice1)
Me.Controls.Add(lblDice2)
Me.Controls.Add(lblDice3)
Me.Controls.Add(lblDice4)
Me.Controls.Add(lblDice5)
Me.Controls.Add(butRoll)
Me.Controls.Add(lblYatzee)
Me.Controls.Add(lblFourOfAKind)
Me.Controls.Add(lblThreeOfAKind)
End Sub
Private Sub RollDice() Handles butRoll.Click
Dim arrNumbers() As Integer = {0, 0, 0, 0, 0, 0}
lblDice1.Text = Rnd.Next(1, 7)
lblDice2.Text = Rnd.Next(1, 7)
lblDice3.Text = Rnd.Next(1, 7)
lblDice4.Text = Rnd.Next(1, 7)
lblDice5.Text = Rnd.Next(1, 7)
For Each lbl As Label In Me.Controls.OfType(Of Label)()
arrNumbers(lbl.Text - 1) += 1
Next
For Each i As Integer In arrNumbers
If i = 5 Then
nYatzee += 1
ElseIf i = 4 Then
nFourOfAKind += 1
ElseIf i = 3 Then
nThreeOfAKind += 1
End If
Next
lblYatzee.Text = "Yatzees: " & nYatzee
lblFourOfAKind.Text = "Four Of A Kind: " & nFourOfAKind
lblThreeOfAKind.Text = "Three Of A Kind: " & nThreeOfAKind
End Sub
Private Sub BC(ByVal button As Button, ByVal p2 As Integer, ByVal p3 As Integer, ByVal p4 As String)
Throw New NotImplementedException
End Sub
End Class
Monday, April 11, 2011
counter
Public Class Form1
Public Function getWordCount(ByVal InputString As String) As Integer
Return Split(System.Text.RegularExpressions.Regex.Replace(InputString, "\s+", Space(1))).Length
End Function
Public Function getSentenceCount(ByVal InputString As String) As Integer
Dim nperiod As Integer
Dim nexclamation As Integer
Dim nquestion As Integer
nperiod = InputString.Split(".").Length
nexclamation = InputString.Split("!").Length
nquestion = InputString.Split("?").Length
Return (nquestion + nexclamation + nperiod)
End Function
Public Function CountSpaces(ByVal sText As String) As Long
Dim nSpaces As Integer = 0
For Each s As String In sText
If s = " " Then
nSpaces += 1
End If
Next
Return nSpaces
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = TextBox1.Text.Length
TextBox3.Text = getWordCount(TextBox1.Text)
TextBox4.Text = getSentenceCount(TextBox1.Text)
TextBox5.Text = CountSpaces(TextBox1.Text)
End Sub
End Class
Friday, March 25, 2011
Button hover
Public Class Form1
Dim pt1 As New Point(100, 35)
Dim pt2 As New Point(45, 500)
Dim pt3 As New Point(354, 99)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("You shot me", "Why would you shoot me?!?", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Sub
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
If Button1.Location = pt1 Then
Button1.Location = pt2
ElseIf Button1.Location = pt2 Then
Button1.Location = pt3
ElseIf Button1.Location = pt3 Then
Button1.Location = pt1
End If
End Sub
Private Sub Button1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseHover
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Location = pt1
End Sub
End Class
Sunday, March 20, 2011
Example loops
Example on For loop
Example on While loop
Module1 Sub Main() Dim d As Integer For d = 0 To 2 System.Console.WriteLine("In the For Loop") Next d End Sub Example on Do loop
|
Example on While loop
Module Module1 Sub Main() Dim d, e As Integer d = 0 e = 6 While e > 4 e -= 1 d += 1 End While System.Console.WriteLine("The Loop ran " & e & "times") End Sub |
Subscribe to:
Posts (Atom)