Solved

Text Analysis example counting sentences, paragraphs, words just like MS word does

Posted on 2003-11-17
11
680 Views
Last Modified: 2010-05-01
I want to count the number of sentence parargraphs and words and character and then number of characters without spaces and report onthis into simple text boxes imagine like MS word does a wordcount i want this functonality from my VB app in a text box.

Cheers
0
Comment
Question by:Ranoldin
11 Comments
 
LVL 3

Accepted Solution

by:
NBrownoh earned 40 total points
ID: 9762833
for characters without spaces do this:
YourVal = len(replace(YourText, " ", ""))

for the number of words genericaly just do this:
Tem = replace(YourText, " ", "")
YourVal = Val(Len(YourText) - Len(Tem))

and for sentances do this:
Tem = replace(YourText, ".", "")
YourVal = Val(Len(YourText) - Len(Tem))
0
 
LVL 3

Assisted Solution

by:monvelasquez
monvelasquez earned 40 total points
ID: 9762899
The best way to do this is probably by using the RegExp object

a nice discussion about RegExp is at
    http://www.juicystudio.com/tutorial/vb/regexp.asp

In your project references add "Microsoft VBScript Regular Expressions"

here's are some samples

Function CountWords(ByVal Text As String) As Long
    Dim re As New RegExp
    re.Pattern = "\b\w+\b"
    re.Global = True
    CountWords = re.Execute(Text).Count
End Function

Function CountCharsNoSpaces(ByVal Text As String) As Long
    Dim re As New RegExp
    re.Pattern = "\s"
    re.Global = True
    CountChars = re.Execute(Text).Count
End Function


Function CountChars(ByVal Text As String) As Long
    Dim re As New RegExp
    re.Pattern = "."
    re.Global = True
    CountChars = re.Execute(Text).Count
End Function


0
 

Author Comment

by:Ranoldin
ID: 9762903
What about the VBClrf character some reason it counts them as characters too?

Thanks for speedy respons though NBrownoh

I would also like to ask is it possible to do this on a string variable

myChar = Replace(strTemp, vbCrLf, "")
myChar = Replace(strTemp, " ", "")


frmAnalysis.txtNumberOfCharacters.Text = Len(myChar)
to also count the length of the string after the two above things have been done

0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 45 total points
ID: 9763284
Do this

strTemp = Replace(strTemp, vbCr, "")
strTemp = Replace(strTemp, vbLf, "")
strTemp = Replace(strTemp, " ", "")
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9763857
Listening . . .
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Ranoldin
ID: 9764148
Who is Dang 123 BTW ?? where you come from i have a feeling i know why u are listening hehe

THankyou for speedy responses guys as ever appreciate it loads so i thought id split the points up failry i got help from all three of you rather than from just one person :PP


Cheers
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9765048
Ranoldin,
    I am in New Jersey. My users are working on specs for a program I will be working on soon that will require me to do Text Analysis, it will be an in-house only program. I just wanted to be able to find this question easily in the future, and since EE gives a list of questions you comment into . . . .

    Am I who you were thinking of?   ; )

    Glad you got what you needed, and thanks for letting me listen in.

Dang123

0
 

Author Comment

by:Ranoldin
ID: 9765269
Hehe no you are not the person lol i thought it was someone i knew locally to me hehe.

Text Analysis is ok i am continuing to develop Paragraphs counting and pages ugghies ))


Confusing this is VBClrf and VBcr lol

mean practically the same thing but of course vbClrf is a key nto a character oh well lol

Cheers Ranoldin ))
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9765457
Ranoldin,
    Your right, it can be a bit confusing. Basically, vbCrLf represents two characters (13 and 10) this is from the old teletype terminals. Carriage return (13) would move the print head back to the start of the line and Linefeed (10) would advance the paper by one line. While this has no real effect on the screens we use today, most programs still use this character combination to represent a line break. A few try to save the character length by using just Carriage return (13) (vbCr) or just Linefeed (10) (vbLf) so you need to be aware of any of the three ways to spot a line break.

Good luck, and thanks again for letting me listen in.

Dang123

0
 

Author Comment

by:Ranoldin
ID: 9773434
Gusy id like to extend this question dont know if u will be able to help how would i go about counting Paragrahs in a text box ??
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9773463
1. Replace all vbCrLf & vbCrLf with vbCrLf (may need to do it a few times depending on your users typing)

2. Loop through the text counting vbCrLf

3. If the last characters in the text are vbCrLf, you have your count otherwise add 1 to the get your count.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now