|
-
Nov 12th, 2000, 01:45 PM
#1
Thread Starter
Junior Member
Could anyone help with the code for the following event? Thanks.
Count Occurrences
· Write code to count the occurrences of "txtEntry2" in "txtEntry1" when the user clicks the button "cmdCount". Display the result in the label "lblResult". For example, entries of
"This is some text this is" and "is"
would cause the following text to appear in the label "lblResult" when the user presses the button "cmdCount".
"Occurrences Found : 4"
· Clear the result display.
· The count should NOT be case-sensitive.
· Remove leading spaces from the text before reversing it.
· Check that the user has entered at least one character in both text boxes.
· Save the project.
· Run several tests.
Hints:
use Mid and Instr functions among others
-
Nov 12th, 2000, 01:56 PM
#2
-
Nov 12th, 2000, 02:15 PM
#3
Thread Starter
Junior Member
Won't this just count the occurences of characters in the first text box? I need to count the occurrences of what is in the first text box based on what the user enters in the second text box. In other words, they may pick a string from the first text box which is placed in the second text box and want to count the occurrences of that string in the first text box and place that number in the label box.
-
Nov 12th, 2000, 02:35 PM
#4
lblResult = Len(txtEntry2)
We may have to do this step by step. It's easy, but I am confused, maybe I'm just tired .
-
Nov 12th, 2000, 02:38 PM
#5
Hyperactive Member
Is this what you're looking for?
Code:
Private Sub cmdCount_Click()
Dim I As Integer, Occur As Integer, tempstr As String
If Len(txtEntry1.Text) = 0 Or Len(txtEntry2.Text) = 0 Then
MsgBox "Evil shall not prevail!"
Exit Sub
End If
For I = 1 To Len(txtEntry1.Text)
tempstr = Mid(txtEntry1.Text, I, Len(txtEntry2.Text))
If StrComp(tempstr, txtEntry2.Text, 1) = 0 Then Occur = Occur + 1
Next I
lblResult = Occur
End Sub
-
Nov 12th, 2000, 03:53 PM
#6
Thread Starter
Junior Member
Thanks for the help Matthew and Marnitzg. That worked with only one question yet. I need to have the string "Occurrences Found :" placed in the label box as the result of occur is placed there. Any thoughts?
-
Nov 12th, 2000, 04:11 PM
#7
You mean this?
Code:
lblResult = "Occurrences Found: " & Occur
-
Nov 12th, 2000, 07:18 PM
#8
Thread Starter
Junior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|