|
-
Aug 31st, 2010, 08:56 PM
#1
Thread Starter
Junior Member
[RESOLVED] newbie here... need help on built-in functions...
rivate Sub Command1_Click()
Dim x As Integer, ng As Integer, b As Integer, counter As Integer
Dim z As String, y As String, char1 As String, str1 As String
z = 0
For x = 1 To Len(Text1.Text)
y = Mid(Text1.Text, x, 1)
If (y) = "ng" Then
z = z + 1
Label.Caption = z
End If
Next
counter = 0
str1 = Text1.Text
For b = i To Len(str1)
char1 = char1 + Replace(str1, char1, "", i)
Form1.Caption = Form1.Caption + char1
Next
End Sub
-----------
this code should display a counter for every occurence of the "ng" but i do not know if what part of this code does not work... help pls... thanx
-
Aug 31st, 2010, 09:14 PM
#2
Re: newbie here... need help on built-in functions...
Sorry, I'm a bit confused! At the moment your code displays the contents of text1 in the form caption is that what you want?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 31st, 2010, 09:52 PM
#3
Re: newbie here... need help on built-in functions...
If you want to count the number of "ng"s in a string just do this.
Code:
Const TEST_STRING = "testing testing testing"
Const LOOK_FOR = "ng"
MsgBox (Len(TEST_STRING) - Len(Replace(TEST_STRING, LOOK_FOR, ""))) / Len(LOOK_FOR)
-
Aug 31st, 2010, 10:30 PM
#4
Thread Starter
Junior Member
Re: newbie here... need help on built-in functions...
 Originally Posted by Nightwalker83
Sorry, I'm a bit confused! At the moment your code displays the contents of text1 in the form caption is that what you want?
No sir, the text1 will only get input from the user... what i am trying to make is that i only want to count how many "ng" the program encounters and displays how many "ng" occurs..
example
-
Aug 31st, 2010, 10:45 PM
#5
Re: newbie here... need help on built-in functions...
Martin's example is very neat.
If you wanted to use the Len and Mid$ Functions then here's another way of doing it
Code:
Option Explicit
Private Sub Command_Click()
Dim intI As Integer
Dim intNg As Integer
Dim strCheck As String
intI = 1
Do
'
' Pick up the intI'th and intI'th + 1 characters
' and assign to strCheck
'
strCheck = Mid$(Text1.Text, intI, 2)
'
' are they 'ng' ?
'
If strCheck = "ng" Then
'
' Yes then add 1 to the count
'
intNg = intNg + 1
End If
'
' Move to the next character position
' by adding 1 to intI
'
intI = intI + 1
'
' Loop until all characters have been checked
'
Loop Until intI = Len(Text1.Text)
MsgBox "There were " & intNg & " occurences of 'ng' found in Text1.Text"
End Sub
-
Sep 1st, 2010, 08:13 AM
#6
Re: newbie here... need help on built-in functions...
FYI: One of the reasons your code fails is this line: y = Mid(Text1.Text, x, 1)
How can y = "ng" if the Mid() function is only returning 1 character?
-
Sep 1st, 2010, 08:41 AM
#7
Re: newbie here... need help on built-in functions...
 Originally Posted by LaVolpe
FYI: One of the reasons your code fails is this line: y = Mid(Text1.Text, x, 1)
How can y = "ng" if the Mid() function is only returning 1 character?
and if he fixes that he will have to change line one also to len(text1.text)-1
-
Sep 2nd, 2010, 07:33 AM
#8
Thread Starter
Junior Member
Re: newbie here... need help on built-in functions...
Thanx for the help everyone... i have found what i wanted to do...
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
|