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
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 |
Monday, January 31, 2011
If Statements
An if statement that makes one decision
An if statement where many decisions are made
A case statement
Dim a As Integer
Dim b As Integer
a = 3
b = 4
If a > b Then
MsgBox ("a is greater then b")
Else
MsgBox ("b is greater then a")
End If
if statement where it's either or num = Int(Text1.Text) 'Input
If (num > 0) Then
strReply = "You have a car!"
Else
strReply = "You don't have a car!"
End If
An if statement where many decisions are made
intInput = Val(System.Console.ReadLine())
If intInput = 1 Then
System.Console.WriteLine("Thank you.")
ElseIf intInput = 2 Then
System.Console.WriteLine("That's fine.")
ElseIf intInput = 3 Then
System.Console.WriteLine("Too big.")
Else
System.Console.WriteLine("Not a number I know.")
End If
A case statement
Dim grade As String
Private Sub Compute_Click( )
grade=txtgrade.Text
Select Case grade
Case "A"
result.Caption="High Distinction"
Case "A-"
result.Caption="Distinction"
Case "B"
result.Caption="Credit"
Case "C"
result.Caption="Pass"
Case Else
result.Caption="Fail"
End Select
End Sub
Wednesday, January 26, 2011
Terms
CBool - use this function to convert to Bool data type
CByte - use this function to convert to Byte data type
CChar - use this function to convert to Char data type
CDate - use this function to convert to Date type
CDbl - use this function to convert to Double data type
CDec - use this function to convert to Decimal data type
CInt - use this function to convert to Integer data type
CLng - use this function to convert to Long data type
CObj - use this function to convert to Object type
CShort - use this function to convert to Short data type
CSng - use this function to convert to Single data type
CString - use this function to convert to String data type
.vbproj->A Visual Basic project
Form1.vb->A form's code
AssemblyInfo.VB->Information about an assembly, includes version information
.vbproj.user->Stores project user options
.sln->Solution file which stores solution's configuration
.suo-> Stores Solution user options
Form1.resx.NET->XML based resource template
bin directory->Directory for binary executables
obj directory->Directory for debugging binaries
Module: Used to hold code
Variable: A named memory location of a specific data type used to hold some value
Procedure: A callable series of statements which may or may not return a value
Sub-Procedure: A procedure with no return value
Function: A procedure with return value
Methods: A procedure built into the class
Constructor: Special method used to initialize and customize the object. It has the same name as the class
Class: An OOP class which contains data and code
Object: An instance of a class
Arrays: Programming constructs that lets us access data by numeric index
Attributes: They are the items that specify information about other items being used in VB. NET
CByte - use this function to convert to Byte data type
CChar - use this function to convert to Char data type
CDate - use this function to convert to Date type
CDbl - use this function to convert to Double data type
CDec - use this function to convert to Decimal data type
CInt - use this function to convert to Integer data type
CLng - use this function to convert to Long data type
CObj - use this function to convert to Object type
CShort - use this function to convert to Short data type
CSng - use this function to convert to Single data type
CString - use this function to convert to String data type
.vbproj->A Visual Basic project
Form1.vb->A form's code
AssemblyInfo.VB->Information about an assembly, includes version information
.vbproj.user->Stores project user options
.sln->Solution file which stores solution's configuration
.suo-> Stores Solution user options
Form1.resx.NET->XML based resource template
bin directory->Directory for binary executables
obj directory->Directory for debugging binaries
Module: Used to hold code
Variable: A named memory location of a specific data type used to hold some value
Procedure: A callable series of statements which may or may not return a value
Sub-Procedure: A procedure with no return value
Function: A procedure with return value
Methods: A procedure built into the class
Constructor: Special method used to initialize and customize the object. It has the same name as the class
Class: An OOP class which contains data and code
Object: An instance of a class
Arrays: Programming constructs that lets us access data by numeric index
Attributes: They are the items that specify information about other items being used in VB. NET
Monday, January 24, 2011
Visual Basic
Dim FirstName As String
Dim LastName As String
Dim FullName As String
FirstName = "Michael "
LastName = "Voller"
FullName = FirstName & LastName
MessageBox.Show(FullName)
to convert a number to a string
Dim hi As Integer
hi = 54
Dim bye As String
bye = hi.ToString
MessageBox.Show(bye)
Subscribe to:
Posts (Atom)