|
-
Apr 25th, 2005, 10:45 PM
#1
Thread Starter
Member
[Resolved]Searching string array
hi,
im new to VB - so hope ive come to the right place. basically i've got to create a macro that searches through highlighed text for characters (ie. comma's, fullstop, etc) and counts those occurents against actual words. Now i started this the basic way and highlighted text to detect the punctuation characters but im unable to get them to recoginse more than 1 punctuation character (is there an "OR" function in Instr?). Also not sure how to count them, i know i would store them in an array and then continue the count - but i'm having problems with that? could someone give me some insight on this?
thanks a lot.
Last edited by chaos7; Apr 30th, 2005 at 09:15 AM.
Reason: Resolved
-
Apr 25th, 2005, 11:46 PM
#2
Re: Searching string array
Welcome to the Forums.
Check out my code example in this thread. I assume your talking about Word.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 26th, 2005, 02:03 AM
#3
Thread Starter
Member
Re: Searching string array
Hi Rob,
Thanks for that. I will test it out once i get home. Basically i want select some text on MSWord and then search for these symbols ('.' ',' '?' '!') and count how many times they occur on the selected text, i assumed that i would make an array (for the selected words) and then go through finding and counting the above symbols? But i thought we would need to use a for loop for this (using UBound & LBound)?? Sorry im still trying to learn VB - and doing it at work is prob not the best thing
Pls let me know if im on right track...or how to get there...
-
Apr 27th, 2005, 10:41 PM
#4
Thread Starter
Member
Re: Searching string array
hi...
okay i have been trying to test what i am supposed to do with arrays as i thought that would be the best way, but i was not having any luck, so i switched to do just a simple comma count loop. what i want to do is search the selected text for comma's and count how many times they occur but my program freezes everytime i click the button.....my code is as below, can someone pls help...
Private Sub CommandButton1_Click()
Dim myText As String
Dim counter As Long
myText = Selection.Text
counter = 0
Do While InStr(myText, ",")
counter = counter + 1
Loop
MsgBox "Number of times a comma has occured is equal to " & counter
End Sub
-
Apr 28th, 2005, 12:17 AM
#5
Re: Searching string array
Your instr function is missing its Start parameter.
VB Code:
Dim myText As String
Dim counter As Long
myText = Selection.Text
counter = 1
Do While InStr(counter, myText, ",")
counter = counter + 1
Loop
MsgBox "Number of times a comma has occured is equal to " & counter - 1
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 28th, 2005, 01:44 AM
#6
Thread Starter
Member
Re: Searching string array
hi rob...i tried that code, but when i run it, it returns with the position of the comma?? for example i select the following code in a text "Analysis, should be" and my msg box indicates that there are 9 comma's in the text?!! so i think its finding the position or something??? do you know what im doing wrong??
also in C++ when we search for more than one thing we can use the OR (||) command - can we do this in VBA as well in the InStr function in the loop?? anyway sorry to be bugging you all the time - my vb book sux!! theres not a whole lot on strings..more on integers and stuff..
thanks
-
Apr 28th, 2005, 12:49 PM
#7
Re: Searching string array
Sorry, I forgot to increase by the position of the comma.
VB Code:
Dim myText As String
Dim counter As Integer
Dim iPos As Integer
myText = "Testing, testing,testing"
counter = 0
iPos = 0
iPos = InStr(1, myText, ",")
Do While iPos > 0
iPos = InStr(iPos, myText, ",")
If iPos > 0 Then iPos = iPos + 1
counter = counter + 1
Loop
MsgBox counter '3
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 28th, 2005, 08:15 PM
#8
Thread Starter
Member
Re: Searching string array
hi rob,
thank you for that i added the script and placed a "counter = counter - 1" just after the loop and before the MsgBox prompt - as it was giving me an extra comma. now i will test it for my highligted text.
do you know how i can add to this to allow to search for fullstop, question mark, and exclamation mark? i was looking for an OR command but there isnt one..something like...
IF iPos = InStr(1, myText, ",") || iPos = InStr(1, myText, ".") || iPos = InStr(1, myText, "?") THEN
do while loop etc...
but syntax doesnt work?
-
Apr 28th, 2005, 08:41 PM
#9
Thread Starter
Member
Re: Searching string array
actually...i dont even know if the OR will work for what i want to do. i just want to add the number of times the following symbols ("," , "." , "?", "!") occur in the text in proportion to the number of words selected. so its working for counting the first comma symbol but how do i get it to count for the other 3 as well?? i thought maybe to put it in the IF/OR statement above - but not sure if that will do the trick????
plzzzzzzzzz help, i cant even get this right!!
-
Apr 28th, 2005, 09:04 PM
#10
Re: Searching string array
You need to do three separate loops or use Or conditions in the Do While loop condition.
VB Code:
'|| = Or
Do While (Instr(1, Text1.Text, ",") > 0) Or Instr(1, Text1.Text, "?") > 0) Or (Instr(1, Text1.Text, ".") > 0)
'do your stuff to test for each of the three.
'increment once for each occurance of the 3
Loop
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 28th, 2005, 09:19 PM
#11
Thread Starter
Member
Re: Searching string array
hi rob,
okay i've got another idea...which may work as im not sure my other one did - and i actually even tried to code it myself well kind of but im getting an error, basically now im just trying to pass it off as a function and then call it from the main command...but im getting a compile error "expected function or call"? maybe im calling it wrong from the CommandButton1_Click() function????????
Private Sub CommandButton1_Click()
Dim myText As String
Dim countComma As Integer
Dim countFullstop As Integer
myText = Selection.Text
countComma = findChar(myText, ",")
countFullstop = findChar(myText, ".")
MsgBox "No. of comma's is: " & countComma
MsgBox "No. of fullstop's is: " & countFullstop
End Sub
Private Sub findChar(Text As String, myChar As String)
Dim counter As Integer
Dim iPos As Integer
'Text = Selection.Text
counter = 0
iPos = 0
iPos = InStr(1, Text, myChar)
Do While iPos > 0
iPos = InStr(iPos, Text, myChar)
If iPos > 0 Then iPos = iPos + 1
counter = counter + 1
Loop
counter = counter - 1
End Sub
-
Apr 28th, 2005, 09:30 PM
#12
Re: Searching string array
Ok, your calling a sub but trying to return a value from it to set in the msgbox.
You need to change things a little.
VB Code:
Private Sub CommandButton1_Click()
Dim myText As String
Dim countComma As Integer
Dim countFullstop As Integer
myText = Selection.Text
countComma = findChar(myText, ",")
countFullstop = findChar(myText, ".")
MsgBox "No. of comma's is: " & countComma
MsgBox "No. of fullstop's is: " & countFullstop
End Sub
Private Function findChar(Text As String, myChar As String) As Integer 'Returns a Integer value
Dim counter As Integer
Dim iPos As Integer
'Text = Selection.Text
counter = 0
iPos = 0
iPos = InStr(1, Text, myChar)
Do While iPos > 0
iPos = InStr(iPos, Text, myChar)
If iPos > 0 Then
iPos = iPos + 1
counter = counter + 1
End If
Loop
'counter = counter - 1
findChar = counter
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 28th, 2005, 09:45 PM
#13
Thread Starter
Member
Re: Searching string array
hi rob,
Thanks rob - i love you!!!!
its working...i just changed the 'End Sub' at the end of the function to 'End Function' and it compiled. Now i'll try not to hassle you too much and do the word count all by myself
-
Apr 28th, 2005, 10:08 PM
#14
Re: Searching string array
Doh! I guess thats what I get for typing in the Reply box and not VB6. 
I already fixed the count = count - 1 at the end. It needed an if then endif block to only increment counter if it found a match.
For the word count, try splitting the entire string into an array on the space character.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 29th, 2005, 04:02 AM
#15
Thread Starter
Member
Re: Searching string array
Okay im stuck!! My program works now and gives me the ouput needed but ONLY if i select text. if i dont select text then i get a run-time error due to the proportion part of the essay (if i comment that out everything is okay))) but its the dividing by zero that is giving me the problem....i tried to make another small function out of it but that didn't work even after forcing it as a Double?? how do i fix this????
Private Sub CommandButton1_Click()
Dim myText As String 'holds text as string variable
Dim countComma As Integer 'stores number of comma's in selected text
Dim countFullstop As Integer 'stores number of fullstop's in selected text
Dim propComma As Double 'proportion of commas in regard to words
Dim propFullstop As Double
'To count words
Dim myRange As Range
Set myRange = Selection.Range
Dim wordCount As Integer
wordCount = myRange.ComputeStatistics(wdStatisticWords)
myText = Selection.Text
countComma = findChar(myText, ",")
countFullstop = findChar(myText, ".")
propComma = propChar(countComma, wordCount)
'propComma = countComma / wordCount
' propFullstop = countFullstop / wordCount
MsgBox "No. of comma's: " & countComma
MsgBox "No. of fullstop's: " & countFullstop
MsgBox "No. of words selected: " & wordCount
MsgBox "Proportion of comma's (,) to words is: " & propComma
'MsgBox "Proportion of fullstop's (.) to words is: " & propFullstop
End Sub
'Private Function findChar(Text As String, myChar As String) As Integer 'Returns a Integer value
'Searches for and counts the char in the text
'End Function
Private Function propChar(char As Integer, wcount As Integer) As Double 'Returns a Double value
propChar = char / wcount 'THIS IS THE PROBLEM LINE...
End Function
-
Apr 29th, 2005, 12:32 PM
#16
Re: Searching string array
Use the WholeStory of the range object to set a range to the entire document.
VB Code:
Private Sub Test()
Dim myRange As Range
Set myRange = ActiveDocument.Range
myRange.WholeStory
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 29th, 2005, 06:46 PM
#17
Thread Starter
Member
Re: Searching string array
hi .. i tried doing that but now it gives me all the number of words (even when its not selected), i placed it at the top like this. Played around with it and kept Selection.Range but still didn't work??
'To count words
Dim myRange As Range
'Set myRange = Selection.Range
Set myRange = ActiveDocument.Range
myRange.WholeStory
Dim wordCount As Integer
wordCount = myRange.ComputeStatistics(wdStatisticWords)
-
Apr 29th, 2005, 06:50 PM
#18
Re: Searching string array
Thats what WholeStory is, the entire document.I thought thats what you wanted? You said that if you dont select
text you get an error. so I thought that you wanted all. If you want just the selected text then use
wordCount = Selection.Range.ComputeStatistics(wdStatisticWords)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 29th, 2005, 07:14 PM
#19
Thread Starter
Member
Re: Searching string array
sorry...what i meant is that when i don't select any text i get an overflow error when im trying to calculate number of decimal's by wordcount (overflow error) BUT when i select the text - it works fine. so i don't know if its because im dividing by zero that its giving me the overflow error (no text selected, for example, won't let me calculate "propComma = propChar(countComma, wordCount)"). Because when i put the below in to select word count its okay.
VB Code:
Dim myRange As Range
Set myRange = Selection.Range
wordCount = myRange.ComputeStatistics(wdStatisticWords)
I'm not sure why the overflow error is coming - i tried to force the propChar function to return a Double - but its not working either (code pasted in last post) - hope this makes sense...??
-
Apr 29th, 2005, 08:00 PM
#20
Re: Searching string array
Oh, then we only need to detect if the count is equal to zero before dividing. Thats the error.
VB Code:
If wcount > 0 Then
propChar = char / wcount 'THIS IS THE PROBLEM LINE...
Else
propChar = 0
End If
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 29th, 2005, 08:32 PM
#21
Thread Starter
Member
Re: Searching string array
Thanks Rob. I can't believe it was as simple as that - i feel so stupid!! I spent hours on this one last night - i knew the number/0 gives errors, so i was doing all sorts of weird statements (adding # at the end of one of the ints) etc.. Anyway im onto the next part (which thank god is the last part!! whoo-hoo!!). Although its Distribution of sentences!! :eek
-
Apr 29th, 2005, 09:54 PM
#22
Thread Starter
Member
Re: Searching string array
OK this is the last bit i have to do - and i promise i'll stop harrassing you rob!! okay what i have to do in this part is "the distribution of the number of commas per sentence (i.e. how many sentences have 0 or 1 or more comm'as)" -- so we need to break down each sentence. i can do a sentence count okay, which gives me the number of sentences, but how to break it down and say sentence 1 = .., etc..not sure.
I've put the program in a do while loop to iterate over each sentence and find out how many comma per sentence, it just gives me the total number of comma's..??
VB Code:
Dim sentenceCount As Integer
Dim newCount As Integer
sentenceCount = Selection.Sentences.count
newCount = sentenceCount - 1
Dim sText As String
myText = Selection.Text
Dim commaCount As Integer
Do While sentenceCount > 0
commaCount = findChar(myText, ",")
sentenceCount = sentenceCount - 1
Loop
MsgBox "commas = " & commaCount
-
Apr 29th, 2005, 11:41 PM
#23
Re: Searching string array
The issue is that ou need it to search just the sentence only and not the entire document.
Can you post your updated findChar procedure?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 29th, 2005, 11:56 PM
#24
Thread Starter
Member
Re: Searching string array
yep so now instead of counting the words in the selected text, i count the sentences and search through each sentence for a comma and display how many times a comma occured in each sentence (is 1 comma in first sentence, 0 in second etc) , i thought i'd use the same findChar function as before:
VB Code:
Private Function findChar(Text As String, myChar As String) As Integer 'Returns a Integer value
Dim counter As Integer
Dim iPos As Integer
counter = 0
iPos = 0
iPos = InStr(1, Text, myChar)
Do While iPos > 0
iPos = InStr(iPos, Text, myChar)
If iPos > 0 Then
iPos = iPos + 1
counter = counter + 1
End If
Loop
findChar = counter
End Function
And then call it from the main program as this:
VB Code:
'Prints out sentences highlighted
Dim sentenceCount As Integer
Dim newCount As Integer
'Gets number of all sentences selected
sentenceCount = Selection.Sentences.count
newCount = sentenceCount - 1
'If sentenceCount > 0 Then
' MsgBox "Sentences selected = " & newCount
' Else
' MsgBox "Sentences selected = 0"
' End If
Do While sentenceCount > 0 'if sentence highlighted
commaCount = findChar(myText, ",") 'find comma
sentenceCount = sentenceCount - 1 'suppose to iterate
Loop
MsgBox "commas found in sentence" & sentenceCount & "equals " & commaCount 'but only comes out with total number of comma's in all sentences
??
-
Apr 30th, 2005, 12:04 AM
#25
Re: Searching string array
Change the passed arguments from ByRef (default) to ByVal.
VB Code:
Private Function findChar(ByVal Text As String, ByVal myChar As String) As Integer 'Returns a Integer value
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 30th, 2005, 12:36 AM
#26
Thread Starter
Member
Re: Searching string array
no its not working...
i think its to do with my do while loop (?) i put the comma search in the sub command instead of function - to test it...but that didnt work it out so i had:
VB Code:
Private Sub CommandButton2_Click()
Dim myText As String
Dim counter As Integer
Dim iPos As Integer
Dim commaCount As Integer
myText = Selection.Text
counter = 0
iPos = 0
iPos = InStr(1, myText, ",")
Do While iPos > 0
iPos = InStr(iPos, myText, ",")
If iPos > 0 Then iPos = iPos + 1
counter = counter + 1
Loop
counter = counter - 1
' MsgBox counter
'Prints out sentences highlighted
Dim sentenceCount As Integer
Dim newCount As Integer
sentenceCount = Selection.Sentences.count
newCount = sentenceCount - 1
'If sentenceCount > 0 Then
' MsgBox "Sentences selected = " & newCount
' Else
' MsgBox "Sentences selected = 0"
' End If
Do While sentenceCount > 0
commaCount = counter;
sentenceCount = sentenceCount - 1
Loop
MsgBox "commas found in " & sentenceCount & commaCount
End Sub
so the output of the sentences (say i've selected them) below should be:
Please God, let this
be, over, very, soon.
Sentence 1 = 1 comma
Senctence 2 = 3 comma
I think its the do while loop i havent written it properly or something?/
-
Apr 30th, 2005, 11:13 AM
#27
Re: [Resolved]Searching string array
Did you change the procedure signature for findchar?
Also, the do loop is doing nothing more then counting down to zero? Or is sentenceCount and commaCount function names?
VB Code:
Do While sentenceCount > 0
commaCount = counter;
sentenceCount = sentenceCount - 1
Loop
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 30th, 2005, 07:15 PM
#28
Thread Starter
Member
Re: [Resolved]Searching string array
I did...but it didn't work. I kind of gave up and moved to the next steps . I ended up finishing the whole program last night, so left this part undone. Oh well....next time....im just glad its over....for now
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
|