Public Class Form1
Dim C As Integer
Dim W As Integer
Dim Se As Integer
Dim Sp As Integer
Public Function getWord(ByVal InputString As String) As String
Return Split(System.Text.RegularExpressions.Regex.Replace(InputString, "\s+", Space(1))).Length
End Function
Public Function getSentence(ByVal InputString As String) As Integer
Dim periods As Integer
Dim questionmarks As Integer
Dim exclamations As Integer
periods = InputString.Split(".").Length
questionmarks = InputString.Split("?").Length
exclamations = InputString.Split("!").Length
Return periods + questionmarks + exclamations
End Function
Public Function getSpaces(ByVal sText As String) As Long
Dim Spaces As Integer = 0
For Each s As String In sText
If s = " " Then
Spaces += 1
End If
Next
Return Spaces
End Function
Public Function CountCharacters(ByVal sText As String) As Integer
Return TextBox1.Text.Length.ToString
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Count characters
C = CountCharacters(TextBox1.Text)
'Count Sentences
Se = getSentence(TextBox1.Text)
'Count Word
W = getWord(TextBox1.Text)
'Count Spaces
Sp = getSpaces(TextBox1.Text)
UpdateTextBox()
End Sub
Private Sub UpdateTextBox()
'Count characters
TextBox2.Text = TextBox1.Text.Length.ToString
TextBox2.Text = C
'Count Sentences
TextBox3.Text = getSentence(TextBox1.Text)
TextBox3.Text = Se
'Count Word
TextBox4.Text = getWord(TextBox1.Text)
TextBox4.Text = W
'Count Spaces
TextBox5.Text = getSpaces(TextBox1.Text)
TextBox5.Text = Sp
End Sub
End Class
Friday, April 8, 2011
Practice 6 Project
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment