To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Display Modes
Old Aug 29th, 2005, 08:35 PM   #1
spazzirifick
Junior Member
 
Join Date: Aug 05
Location: perth
Posts: 30
spazzirifick is an unknown quantity at this point (<10)
Exclamation counting question marks and full stops.

Below is my coding for the counting of sentences in a paragraph of inputted text. So far though i can only get it to count full stops (eg. however many full stops there are there are sentences.). What if i had a question mark though, because that would be the end of a sentence too???? so how do i include question marks in the code below to count question marks AND full stops. (eg. however many full stops AND question marks there are sentences).
hope u caught my drift!!

VB Code:
  1. Private Sub cmdsentences_Click()
  2.     Dim Sentence As String, Char As String
  3.     Dim Count As Integer, I As Integer
  4.     Count = 0
  5.     Sentence = Trim(txtInput.Text)
  6.     If Len(Sentence) > 0 Then
  7.         For I = 1 To Len(Sentence)
  8.             Char = Mid(Sentence, I, 1)
  9.             If Char = "." Then
  10.            
  11.                 Count = Count + 1
  12.             End If
  13.         Next I
  14.             Count = Count
  15.     End If
  16.     lblCountsentences.Caption = Count
  17. End Sub
spazzirifick is offline   Reply With Quote
Old Aug 29th, 2005, 08:38 PM   #2
dglienna
Banned
 
dglienna's Avatar
 
Join Date: Jun 04
Location: Center of it all
Posts: 17,901
dglienna is a glorious beacon of light (400+)dglienna is a glorious beacon of light (400+)dglienna is a glorious beacon of light (400+)dglienna is a glorious beacon of light (400+)dglienna is a glorious beacon of light (400+)dglienna is a glorious beacon of light (400+)
Re: counting question marks and full stops.

If it's formatted correctly, you could check for two spaces, which should be between the period and the next sentence. Same from a question mark.

Otherwise, change it to this:

VB Code:
  1. If Char = "." Or Char = "?"Then
dglienna is offline   Reply With Quote
Old Aug 29th, 2005, 08:44 PM   #3
spazzirifick
Junior Member
 
Join Date: Aug 05
Location: perth
Posts: 30
spazzirifick is an unknown quantity at this point (<10)
Re: counting question marks and full stops.

THANKYOU!!!!

we have the "or" inbetween but i didnt realise that you had to have char= twice!!

thanks!

it works in other words..could you tell :P
spazzirifick is offline   Reply With Quote
Old Aug 29th, 2005, 08:49 PM   #4
Hojo
Lively Member
 
Hojo's Avatar
 
Join Date: Jul 05
Location: Brisbane, Australia
Posts: 119
Hojo is an unknown quantity at this point (<10)
Re: counting question marks and full stops.

Don't forget sentences can finish with an exclamation point to!

And does it mater if people over puncuate??? (this would be 3 sentences to you code)

Just some things to consider.
__________________
Despite body and mind, my youth will never die!

Everytime I learn something new it pushes some old stuff out of my brain!
Hojo is offline   Reply With Quote
Old Aug 29th, 2005, 11:36 PM   #5
MartinLiss
Administrator
 
MartinLiss's Avatar
 
Join Date: Sep 99
Location: Looking over your shoulder from San Jose, CA
Posts: 30,814
MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)
Re: counting question marks and full stops.

Here's another way.

VB Code:
  1. Dim strSentences() As String
  2.     Dim intCount As Integer
  3.    
  4.     strSentences = Split(Text1.Text, ".")
  5.     intCount = intCount + UBound(strSentences)
  6.     strSentences = Split(Text1.Text, "?")
  7.     intCount = intCount + UBound(strSentences)
  8.     strSentences = Split(Text1.Text, "!")
  9.     intCount = intCount + UBound(strSentences)
  10.     MsgBox intCount
__________________
Tips, Examples & Tutorials:
A valuable forum toolGenerate unique TreeView keysTreeView with "open" and "closed folder" iconsTime code using GetTickCountHow to trap the Tab keyScroll a formNumberBox ActiveX controlColor a ListView rowAn InputBox formHow to use SaveSetting and GetSettingA program registration schemeSpellcheck a TextboxResize controlsOpen Windows Explorer at Last Visited PathA Blackjack GameCount lines of codeV1.3Private Message ViewerCopy/Paste VB CodePaste VB Code Add-InInsert Procedure Names Add-InA calculator for the game of SpiderMy review of REALbasic 2008VB6 Debug TutorialPicture/Video ViewerVBF Photo Contest Winners

Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009-2010
If someone helped you today then please consider rating their post.
MartinLiss is offline   Reply With Quote
Old Aug 29th, 2005, 11:37 PM   #6
MartinLiss
Administrator
 
MartinLiss's Avatar
 
Join Date: Sep 99
Location: Looking over your shoulder from San Jose, CA
Posts: 30,814
MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)
Re: counting question marks and full stops.

Oh, wait, "THANK YOU!!!!" is a valid sentence!
__________________
Tips, Examples & Tutorials:
A valuable forum toolGenerate unique TreeView keysTreeView with "open" and "closed folder" iconsTime code using GetTickCountHow to trap the Tab keyScroll a formNumberBox ActiveX controlColor a ListView rowAn InputBox formHow to use SaveSetting and GetSettingA program registration schemeSpellcheck a TextboxResize controlsOpen Windows Explorer at Last Visited PathA Blackjack GameCount lines of codeV1.3Private Message ViewerCopy/Paste VB CodePaste VB Code Add-InInsert Procedure Names Add-InA calculator for the game of SpiderMy review of REALbasic 2008VB6 Debug TutorialPicture/Video ViewerVBF Photo Contest Winners

Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009-2010
If someone helped you today then please consider rating their post.
MartinLiss is offline   Reply With Quote
Old Aug 30th, 2005, 12:12 AM   #7
penagate
Super Moderator
 
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,738
penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)
Re: counting question marks and full stops.

Courtesy of yrwyddfa and I, with a few slight modifications:

VB Code:
  1. Declare Sub RtlMoveMemory Lib "kernel32" ( _
  2.     ByRef lpvDest As Any, _
  3.     ByRef lpvSrc As Any, _
  4.     ByVal cbLen As Long _
  5. )
  6. Function InStr2CharCount( _
  7.     ByVal pszString As Long, _
  8.     ByRef pszFind1 As String, _
  9.     ByRef pszFind2 As String _
  10. ) As Long
  11. Static chBuf(1024)  As Byte
  12. Dim chSearchChar1   As Byte
  13. Dim chSearchChar2   As Byte
  14. Dim lStringLen      As Long
  15. Dim i               As Long
  16.     RtlMoveMemory lStringLen, ByVal (pszString - 4), 4&
  17.     RtlMoveMemory chBuf(0), ByVal pszString, lStringLen
  18.     chSearchChar1 = AscW(pszFind1)
  19.     chSearchChar2 = AscW(pszFind2)
  20.     For i = 0 To lStringLen Step 2
  21.         If (chBuf(i) = chSearchChar1) Or (chBuf(i) = chSearchChar2) Then _
  22.             InStr2CharCount = InStr2CharCount + 1
  23.     Next i
  24. End Function
  25. ' Usage:
  26. MsgBox Instr2CharCount(StrPtr(Trim$(txtInput.Text)), ".", "?")
penagate is offline   Reply With Quote
Old Aug 30th, 2005, 01:47 AM   #8
GreenEye
Junior Member
 
Join Date: Jun 05
Posts: 22
GreenEye is an unknown quantity at this point (<10)
Thumbs up Re: counting question marks and full stops.

Its not a very good way of counting sentences. But rather number of occurances of fullstops, question marks and exclamation marks. To increase accuracy try counting a trailing space. Like count for ". " and "? " etc. And dont forget to add 1 to count for the last sentence. This way confusions made by sentences like "Thank you!!!" will be eliminated. Actually its just more accurate way not foll-proof. More accurate count requires more sophisticated and complex code.
GreenEye is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:37 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.