Count the number of times that character a is used in the string InputText
Function strCountA1(ByVal InputText As String, ByVal a As Char) As Integer
Dim i As Integer
For i = 0 To InputText.Length - 1
If InputText.Substring(i, 1) = a Then
strCountA1 = strCountA1 + 1
End If
Next
End Function
Count the number of times that character A is used in the string InputText
Function strCountA2(ByVal InputText As String, ByVal a As Char) As Integer
Dim i As Integer
For i = 0 To InputText.Length - 1
If InputText.Substring(i, 1) = a Then
strCountA2 = strCountA2 + 1
End If
Next
End Function
Count the number of times that character e is used in the string InputText
Function strCountE1(ByVal InputText As String, ByVal e As Char) As Integer
Dim i As Integer
For i = 0 To InputText.Length - 1
If InputText.Substring(i, 1) = e Then
strCountE1 = strCountE1 + 1
End If
Next
End Function
Count the number of times that character E is used in the string InputText
Function strCountE2(ByVal InputText As String, ByVal e As Char) As Integer
Dim i As Integer
For i = 0 To InputText.Length - 1
If InputText.Substring(i, 1) = e Then
strCountE2 = strCountE2 + 1
End If
Next
End Function
Count the number of times that character s is used in the string InputText
Function strCountS1(ByVal InputText As String, ByVal s As Char) As Integer
Dim i As Integer
For i = 0 To InputText.Length - 1
If InputText.Substring(i, 1) = s Then
strCountS1 = strCountS1 + 1
End If
Next
End Function
Count the number of times that character S is used in the string InputText
Function strCountS2(ByVal InputText As String, ByVal s As Char) As Integer
Dim i As Integer
For i = 0 To InputText.Length - 1
If InputText.Substring(i, 1) = s Then
strCountS2 = strCountS2 + 1
End If
Next
End Function
Count the number of times that character v is used in the string InputText
Function strCountV1(ByVal InputText As String, ByVal s As Char) As Integer
Dim i As Integer
For i = 0 To InputText.Length - 1
If InputText.Substring(i, 1) = s Then
strCountV1 = strCountV1 + 1
End If
Next
End Function
Count the number of times that character V is used in the string InputText
Function strCountV2(ByVal InputText As String, ByVal s As Char) As Integer
Dim i As Integer
For i = 0 To InputText.Length - 1
If InputText.Substring(i, 1) = s Then
strCountV2 = strCountV2 + 1
End If
Next
End Function
Count the number of times that characters st are used in the string InputText
Function CountSTTotal(ByVal InputText As String, ByVal t As Char) As Integer
Dim i As Integer
If InputText.EndsWith("s") Or InputText.EndsWith("S") Then
For i = 0 To InputText.Length - 1
If InputText.Substring(i, 1) = t Then
CountSTTotal = CountSTTotal + 1
End If
Next
End If
End Function
test countwords
Function CountWords()
Dim strWords() As String
Dim lCounter As Long
Dim lWordCount As Long
strWords = Split(Trim(InputTextBox.Text), " ")
For lCounter = 0 To UBound(strWords)
If strWords(lCounter) <> " " And strWords(lCounter) <> "" Then lWordCount = lWordCount + 1
Next lCounter
End Function
Private Sub InputTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InputTextBox.TextChanged
Collection1.Add(Me.InputTextBox)
Me.ClearButton.Enabled = True
Me.ACountLabel.Text = strCountA1(InputTextBox.Text, "a"c) + strCountA2(InputTextBox.Text, "A"c)
Me.ECountLabel.Text = strCountE1(InputTextBox.Text, "e"c) + strCountE2(InputTextBox.Text, "E"c)
Me.SCountLabel.Text = strCountS1(InputTextBox.Text, "s"c) + strCountS2(InputTextBox.Text, "S"c)
Me.VCountLabel.Text = strCountV1(InputTextBox.Text, "v"c) + strCountV2(InputTextBox.Text, "V"c)
Me.STCountLabel.Text = CountSTTotal(InputTextBox.Text, "t"c)
Me.LetterCountLabel.Text = intLetterCount
End Sub
test count letters
Private Sub InputTextBox_KeyPress(ByVal KeyAscii As Integer)
If (KeyAscii > 64 And KeyAscii < 91) Or (KeyAscii > 96 And KeyAscii < 123) Then
user typed a letter
intLetterCount = intLetterCount + 1
Me.LetterCountLabel.Text = intLetterCount
End If
End Sub