1: Public Class Form1
2: Dim nWord As Integer
3: Dim nCharacter As Integer
4: Dim nSentence As Integer
5: Dim nSpace As Integer
6: Private Sub Analyze_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Analyze.Click
7: Dim str As String = txtPar.Text
8: nWord = WordCount(str)
9: nCharacter = CharacterCount(str)
10: nSentence = SentenceCount(str)
11: nSpace = SpaceCount(str)
12: Answer()
13: End Sub
14: Private Function CharacterCount(ByVal str As String) As Integer
15: Return str.Length
16: End Function
17: Public Function WordCount(ByVal value As String) As Integer
18: Return System.Text.RegularExpressions.Regex.Matches(value, "\S+").Count()
19: End Function
20: Public Function SentenceCount(ByVal sentence As String) As Integer
21: Dim x As Integer
22: x = sentence.Split(".").Count()
23: x -= 1
24: Return x
25: End Function
26: Public Function SpaceCount(ByVal space As String) As Integer
27: Dim x As Integer
28: x = space.Split(" ").Count()
29: x -= 1
30: Return x
31: End Function
32: Private Sub Answer()
33: txtWords.Text = nWord
34: txtCharacters.Text = nCharacter
35: txtSentences.Text = nSentence
36: txtSpaces.Text = nSpace
37: End Sub
38: End Class
Showing posts with label VB. Show all posts
Showing posts with label VB. Show all posts
Wednesday, April 13, 2011
Practice # 6
Wednesday, March 30, 2011
Practice # 5
Hashtables and Queues
1.
2.
3.
1.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str() As String = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
For Each s As String In str
MsgBox(s)
Next
End Sub
End Class
2.
Public Class btnFirst
Dim info As New Hashtable
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
info.Clear()
info.Add("First Name", txtFirst.Text)
info.Add("Last Name", txtLast.Text)
info.Add("E-mail", txtMail.Text)
txtFirst.Clear()
txtLast.Clear()
txtMail.Clear()
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(info.Item("First Name"))
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
MsgBox(info.Item("Last Name"))
End Sub
Private Sub btnMail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMail.Click
MsgBox(info.Item("E-mail"))
End Sub
End Class
3.
Public Class frmPrinter
Dim print As New Queue
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim page As New Hashtable
page.Add("Title", txtTitle.Text)
page.Add("Pages", txtPages.Text)
print.Enqueue(page)
refreshJobs()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
print.Dequeue()
refreshJobs()
End Sub
Private Sub refreshJobs()
lstQueue.Items.Clear()
For Each d As Hashtable In print
lstQueue.Items.Add(d.Item("Pages") & (" ") & d.Item("Title"))
Next
End Sub
End Class
Wednesday, February 16, 2011
Loops
This is a example of a FOR LOOP. The For is the keyword you use to start the loop.
basically what is happening is that it is going to step threw by 1 until it gets to 10
This is a example of Do (While last)
Loop check when the loops ends. So this code means that the loop is going to continue to run until x = 10 then it will stop.
This is a example of Do (While first)
Do checks when the loop starts.
This is a example of a For Each
This is going to display each letter one by one until it spells the whole thing out.
For i = 1 To 10 Step 1
Print("programmershelp")
Next i
End Sub
basically what is happening is that it is going to step threw by 1 until it gets to 10
This is a example of Do (While last)
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As Integer
Do
Debug.Print("hello")
x = x + 1
Loop Until x = 10
End Sub
End Class
Loop check when the loops ends. So this code means that the loop is going to continue to run until x = 10 then it will stop.
This is a example of Do (While first)
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As Integer
Do Until x = 10
Debug.Print("hello")
x = x + 1
Loop
End Sub
End Class
Do checks when the loop starts.
This is a example of a For Each
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
This is going to display each letter one by one until it spells the whole thing out.
Monday, February 14, 2011
Practice 3 assignment
1.
2.
3.
Public Class Form1
Private Sub btnMove_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMove.MouseHover
Dim P1 As New Point(5, 239)
Dim P2 As New Point(39, 215)
If btnMove.Location = P1 Then
btnMove.Location = P2
ElseIf btnExit.Location = P2 Then
btnMove.Location = P1
Else
btnMove.Location = P1
End If
'btnMove.Location = New Point(39, 151)
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
2.
Public Class Form1
Private Sub btnColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnColor.Click
'to change the color back and forth i just used a if statement so that if i click the button and it is Black then it will
'change to White but if it is not already Black then it would change to black
If txtTest.BackColor = Color.Black Then
txtTest.BackColor = Color.White
Else
txtTest.BackColor = Color.Black
End If
End Sub
Private Sub btnText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnText.Click
'I did this one the same as the color one the only change i made was that i am using text now so the second one is just a
'empty string
If txtTest.Text = "hello" Then
txtTest.Text = " "
Else
txtTest.Text = "hello"
End If
End Sub
Private Sub btnBorder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorder.Click
'This one it the same as the two above.
If txtTest.BorderStyle = BorderStyle.Fixed3D Then
txtTest.BorderStyle = BorderStyle.None
Else
txtTest.BorderStyle = BorderStyle.Fixed3D
End If
End Sub
Private Sub btnDisable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisable.Click
'This one is also the same
If txtTest.Enabled = False Then
txtTest.Enabled = True
Else
txtTest.Enabled = False
End If
End Sub
End Class
3.
Public Class Form1
Dim lbl1, lbl2, lbl3 As New Label
Dim WithEvents txt1, txt2, txt3 As New TextBox
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
lbl1.AutoSize = True
lbl1.Text = "Hi"
Me.Controls.Add(lbl1)
lbl1.Location = New Point(8, 163)
lbl2.AutoSize = True
lbl2.Text = "Good"
Me.Controls.Add(lbl2)
lbl2.Location = New Point(5, 236)
lbl3.AutoSize = True
lbl3.Text = "Morning"
Me.Controls.Add(lbl3)
lbl3.Location = New Point(1, 6)
txt1.Location = New Point(65, 6)
Me.Controls.Add(txt1)
txt1.Name = "txt1"
txt2.Location = New Point(125, 240)
Me.Controls.Add(txt2)
txt2.Name = "txt2"
txt3.Location = New Point(54, 166)
Me.Controls.Add(txt3)
txt3.Name = "txt3"
End Sub
Private Sub txthightlight1() Handles txt1.MouseEnter
txt1.BackColor = Color.Blue
End Sub
Private Sub txthightlight1B() Handles txt1.MouseLeave
txt1.BackColor = Color.White
End Sub
Private Sub txthightlight2() Handles txt2.MouseEnter
txt2.BackColor = Color.Black
End Sub
Private Sub txthightlight2B() Handles txt2.MouseLeave
txt2.BackColor = Color.White
End Sub
Private Sub txthightlight3() Handles txt3.MouseEnter
txt3.BackColor = Color.Red
End Sub
Private Sub txthightlight3B() Handles txt3.MouseLeave
txt3.BackColor = Color.White
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Practice 2 assignment
1.
2.
3.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim total, cost As Integer
cost = 60
If cost < 50 Then
total = cost + 5
ElseIf cost > 50 Then
total = cost
End If
MessageBox.Show(total)
End Sub
End Class
2.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim temp As Integer
temp = 72
If temp < 72 Then
MessageBox.Show("The Heat is on")
ElseIf temp > 76 Then
MessageBox.Show("The AC is on")
ElseIf temp > 77 & temp < 71 Then
MessageBox.Show("Idle")
End If
End Sub
End Class
3.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim size As String
Dim shirt As String
size = 5
shirt = size
Select Case shirt
Case 0 To 2
size = "XS"
Case 3 To 5
size = "S"
Case 6 To 8
size = "M"
Case 9 To 11
size = "L"
Case Is < 11
size = "XL"
End Select
MessageBox.Show(size)
End Sub
End Class
Friday, February 4, 2011
This is some code that allows you to add buttons, labels, textbox, and listbox
First you have to declare then control then from there you have to set what ever you want like the size, back color, or any thing like that. Once you done with that you have to follow it with a Me.Controls.Add() to add it to the form.
Dim Button1 As New Button
Dim textbox1 As New TextBox
Dim label1 As New Label
Dim listbox1 As New ListBox
Button1.Text = "Go"
Me.Controls.Add(Button1)
textbox1.Text = "Hello"
textbox1.BackColor = Color.Chocolate
Me.Controls.Add(textbox1)
label1.Text = "Good Morning"
label1.BackColor = Color.Aqua
Me.Controls.Add(label1)
listbox1.BackColor = Color.Black
listbox1.Location = New System.Drawing.Point(77, 162)
Me.Controls.Add(listbox1)
First you have to declare then control then from there you have to set what ever you want like the size, back color, or any thing like that. Once you done with that you have to follow it with a Me.Controls.Add() to add it to the form.
Monday, January 31, 2011
If Statements
This is a example of a If statement.
I just basically give name a value and put it in a if statement saying if name = the name i put in then it would output Yes.
This is a example of a If statment where its either or
This is a example of a if statement where many decisions are made
This is a example of a case statement
1st you have to make a Select case statement, then from there you can make as many cases as you want followed by a end Select
Dim name, correct As String
name = "Dalonte"
If name = "Dalonte" Then
correct = "Yes"
End If
MessageBox.Show(correct)
I just basically give name a value and put it in a if statement saying if name = the name i put in then it would output Yes.
This is a example of a If statment where its either or
Dim name, correct As String
name = "Gibson"
If name = "Dalonte" Then
correct = "yes"
Else
correct = "no"
End If
MessageBox.Show(correct)
This is just like my example above but the only thing i did different is that i added a "ELSE" so that if the name does not match up it was say no This is a example of a if statement where many decisions are made
Dim name, As String
name = "anderson"
If name = "Dalonte" Then
MessageBox.Show("First Name")
ElseIf name = "Gibson" Then
MessageBox.Show("last name")
ElseIf name = "anderson" Then
MessageBox.Show("Middle Name")
End If
The only thing that i did different on this one is that i added a elseif statement which allows me to make more then 2 decisions.This is a example of a case statement
Select [ Case ] testexpression
[ Case expressionlist
[ statements ] ]
[ Case Else
[ elsestatements ] ]
End Select
1st you have to make a Select case statement, then from there you can make as many cases as you want followed by a end Select
Friday, January 28, 2011
How to join a String with another String
Dim FirstName As String
Dim LastName As String
Dim FullName As String
FirstName = "Bill"
LastName = "Gates"
FullName = FirstName & LastName
MessageBox.Show(FullName)
first you have to declare your variables then you have to give each variable a value such as Bill and Gates. From there you add them together with a "&" sign then display it with a messagebox
Wednesday, January 19, 2011
Repeatable Process examples
Calculate the final grade
30% Blog 40% assignments 10% peer evals 20% final
86/100 Blog, 345/450 assignment, 43/50 peer, 55/80 final
BlogTP = 100
BlogS = 86 86/100 x .3 = 23.8
BlogW = .3
BlogP = BlogS/BlogTP
AssignTP = 450
AssignS = 345
AssignP = AssignS/AssignTP(76.7) x .4 = 30.68
Grade = (BlogP x BlogW) + (AssignP x AssignW)
30% Blog 40% assignments 10% peer evals 20% final
86/100 Blog, 345/450 assignment, 43/50 peer, 55/80 final
BlogTP = 100
BlogS = 86 86/100 x .3 = 23.8
BlogW = .3
BlogP = BlogS/BlogTP
AssignTP = 450
AssignS = 345
AssignP = AssignS/AssignTP(76.7) x .4 = 30.68
Grade = (BlogP x BlogW) + (AssignP x AssignW)
Friday, January 14, 2011
Name: Message Box
Description: Making a message box
Description: Making a message box
MessageBox.Show("Hello World!")
Subscribe to:
Posts (Atom)