Announcement

Collapse
No announcement yet.

Tally type function for words?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tally type function for words?

    Hi,

    I'm looking for a word type tally function that would count app but not application or snapped. I don't use PB much and may just be missing it in the help guide. ??

    Thanks!

    --Ben

  • #2
    There are some codes posted in source code forum. Link leads to a very fast "Replace All / Count All" function I did once - when used as "Count all", it can be set to respect "Match Case" and "Whole words only", which I guess is what you want. See https://forum.powerbasic.com/forum/u...t-all-function

    Comment


    • #3
      Oh, didn't see you posted in PB DOS forum. Sorry, then I've got nothing.

      Comment


      • #4
        In case you posted in wrong place, PBWin and PBCC have TALLY function. To avoid finding "app" (for example) within other words surround it with spaces.
        count = TALLY(mainstring, $sp + "app" + $sp)
        Allowing for app being first or last word, and different case, will take additional coding on your part.

        Even if you have to write your own TALLY in PBDOS, adding spaces will prevent finding matchstring inside other words.

        Cheers,
        Dale

        Comment


        • #5
          Originally posted by Dale Yarker View Post
          In case you posted in wrong place, PBWin and PBCC have TALLY function. To avoid finding "app" (for example) within other words surround it with spaces.
          count = TALLY(mainstring, $sp + "app" + $sp)
          Allowing for app being first or last word, and different case, will take additional coding on your part.

          Even if you have to write your own TALLY in PBDOS, adding spaces will prevent finding matchstring inside other words.

          Cheers,
          But It would miss words that end with punctuation.

          Comment


          • #6
            Sounds like it's time to add the PBWin version. I originally thought I'd be doing more DOS applications but after coming up on a couple of years, that list is exactly 0. Will pick that up.

            Hm. I see there are 3 offered versions of PBWin: 8, 9 and 10. For relatively novice usage, is there a compelling reason to pick up vsn 10?

            Thanks!

            --Ben

            Comment


            • #7
              Hi Ben,

              Yes, you can do more with it.
              hutch at movsd dot com
              The MASM Forum

              www.masm32.com

              Comment


              • #8
                Close enough then. Just downloaded Jorge's code. I guess this now qualifies for a different topic category. LOL. Will give that a shot and see what happens. Thanks to all!

                --Ben

                Comment


                • #9
                  Originally posted by Ben Conner View Post
                  Sounds like it's time to add the PBWin version. I originally thought I'd be doing more DOS applications but after coming up on a couple of years, that list is exactly 0. Will pick that up.

                  Hm. I see there are 3 offered versions of PBWin: 8, 9 and 10. For relatively novice usage, is there a compelling reason to pick up vsn 10?

                  Thanks!

                  --Ben
                  Ver 10 was a major upgrade with many new capabilities for people at all experience levels. It's definitey the one to go with.

                  Comment


                  • #10
                    But It would miss words that end with punctuation.
                    That would make it a last word!
                    Dale

                    Comment


                    • #11
                      Originally posted by Dale Yarker View Post
                      That would make it a last word!
                      If the OP is going to upgrade to PBWin, then TALLY and REGEXP will be his friends

                      https://forum.powerbasic.com/forum/u...193#post795193


                      https://forum.powerbasic.com/forum/u...311#post795311

                      Comment


                      • #12
                        Howdy, Ben!

                        Here's a whole word extraction snippet, based on Borje's syntax highlighting code. It would be the base for what you want to do (PBWin code, Jose includes). You should be able to take the output (a list of all terms found) and reduce it to a count of words pretty easily.

                        Code:
                        'Compilable Example:  (Jose Includes)
                        #Compile Exe
                        #Dim All
                        #Include "Win32API.inc"
                        
                        %IDC_Button = 500
                        %IDC_TextIn = 501
                        %IDC_TextOut = 502
                        
                        Global hDlg,hFont As Dword
                        Global WordList() As String
                        
                        Function PBMain() As Long
                           Local temp$, style&
                           style& = %WS_TabStop Or %WS_Border Or %ES_WantReturn Or %ES_MultiLine
                           temp$ = "Sub MySub" + $CrLf + "   s += " + $Dq + "text" + $Dq + $CrLf + "   Call MyFunction 'comment" + $CrLf + "End Sub"
                           Dialog New Pixels, 0, "Extract Words From Code",300,300,505,230, %WS_OverlappedWindow To hDlg
                           Control Add Button, hDlg, %IDC_Button,"Create Word List", 10,5,120,25
                           Control Add TextBox, hDlg, %IDC_TextIn,temp$, 10,35,240,190,style&, %WS_Ex_ClientEdge
                           Control Add TextBox, hDlg, %IDC_TextOut,"<output>", 260,35,240,190,style&, %WS_Ex_ClientEdge
                           Dialog Show Modal hDlg Call DlgProc
                        End Function
                        CallBack Function DlgProc() As Long
                           Local temp$
                           Select Case Cb.Msg
                              Case %WM_InitDialog
                                 Font New "Tahoma",10,0 To hFont
                                 Control Set Font hDlg, %IDC_Button, hFont
                                 Control Set Font hDlg, %IDC_TextIn, hFont
                                 Control Set Font hDlg, %IDC_TextOut, hFont
                              Case %WM_Command
                                 If Cb.Ctl = %IDC_Button And Cb.CtlMsg = %BN_Clicked Then
                                    Control Get Text hDlg, %IDC_TextIn To temp$
                                    Control Set Text hDlg, %IDC_TextOut, ScanCode(temp$)
                                 End If
                           End Select
                        End Function
                        
                        Function ScanCode(InText$) As String
                          Local pd As CHARRANGE, Oldpd As CHARRANGE, tBuff As TEXTRANGE, temp$
                          Local xWord,Buf,UCBuf As String
                          Local i,j,StopPos,lnLen As Long
                          Local wFlag As Byte, Letter As Byte Ptr
                        
                          For J = 1 To ParseCount(InText$, $CrLf)
                             Buf = Parse$(InText$,$CrLf,J)
                             UCBuf = UCase$(Buf) + $Spc
                             If Len(Trim$(UCBuf))=0 Then Iterate For
                             lnLen = Len(UCBuf$)
                             Letter = StrPtr(UCBuf) : wFlag = 0
                             For I = 1 To Len(UCBuf)
                                Select Case @Letter
                                   Case 97 To 122, 65 To 90, 192 To 214, 216 To 246, 248 To 255,35 To 38, 48 To 57, 63, 95 'word characters
                                      If wFlag = 0 Then wFlag = 1 : stopPos = I
                                   Case 34 'string quotes -> "
                                     stopPos = InStr(I + 1, UCBuf, Chr$(34)) 'Find match
                                     If stopPos Then
                                        StopPos = (StopPos - I + 1)
                                        I = I + StopPos
                                        Letter = Letter + StopPos
                                        wFlag = 0
                                     End If
                                   Case 39 'comment character -> '
                                      wFlag = 0
                                      Exit For
                                   Case Else  'word is ready
                                      If wFlag = 1 Then
                                         xWord = Mid$(Buf, stopPos, I - stopPos)  'Get word
                                         If xWord = "REM" Then wFlag = 0 : Exit For
                                         wFlag = 0
                                         '--- do something with the word here ---
                                         temp$ += $CrLf + xWord
                                         '---------------------------------------
                                      End If
                                End Select
                                Incr Letter
                             Next I
                          Next J
                          Function = LTrim$(temp$,$CrLf)
                        End Function
                        
                        'gbs_01452
                        'Date: 10-17-2014

                        Comment


                        • #13
                          Same code as above but uses PB includes, keeping it simple for new users. (unused code commented out)(nothing wrong with Jose's includes)
                          Code:
                          'Compilable Example:  (PB Includes)
                          #COMPILE EXE
                          #DIM ALL
                          #INCLUDE "Win32API.inc"
                          
                          %IDC_Button = 500
                          %IDC_TextIn = 501
                          %IDC_TextOut = 502
                          
                          GLOBAL hDlg,hFont AS DWORD
                          GLOBAL WordList() AS STRING
                          
                          FUNCTION PBMAIN() AS LONG
                             LOCAL temp$, style&
                             style& = %WS_TABSTOP OR %WS_BORDER OR %ES_WANTRETURN OR %ES_MULTILINE
                             temp$ = "Sub MySub" + $CRLF + "   s += " + $DQ + "text" + $DQ + $CRLF + "   Call MyFunction 'comment" + $CRLF + "End Sub"
                             DIALOG NEW PIXELS, 0, "Extract Words From Code",300,300,505,230, %WS_OVERLAPPEDWINDOW TO hDlg
                             CONTROL ADD BUTTON, hDlg, %IDC_Button,"Create Word List", 10,5,120,25
                             CONTROL ADD TEXTBOX, hDlg, %IDC_TextIn,temp$, 10,35,240,190,style&, %WS_EX_CLIENTEDGE
                             CONTROL ADD TEXTBOX, hDlg, %IDC_TextOut,"<output>", 260,35,240,190,style&, %WS_EX_CLIENTEDGE
                             DIALOG SHOW MODAL hDlg CALL DlgProc
                          END FUNCTION
                          CALLBACK FUNCTION DlgProc() AS LONG
                             LOCAL temp$
                             SELECT CASE CB.MSG
                                CASE %WM_INITDIALOG
                                   FONT NEW "Tahoma",10,0 TO hFont
                                   CONTROL SET FONT hDlg, %IDC_Button, hFont
                                   CONTROL SET FONT hDlg, %IDC_TextIn, hFont
                                   CONTROL SET FONT hDlg, %IDC_TextOut, hFont
                                CASE %WM_COMMAND
                                   IF CB.CTL = %IDC_Button AND CB.CTLMSG = %BN_CLICKED THEN
                                      CONTROL GET TEXT hDlg, %IDC_TextIn TO temp$
                                      CONTROL SET TEXT hDlg, %IDC_TextOut, ScanCode(temp$)
                                   END IF
                             END SELECT
                          END FUNCTION
                          
                          FUNCTION ScanCode(InText$) AS STRING
                            LOCAL temp$'pd As CHARRANGE, Oldpd As CHARRANGE, tBuff As TEXTRANGE,
                            LOCAL xWord,Buf,UCBuf AS STRING
                            LOCAL i,j,StopPos,lnLen AS LONG
                            LOCAL wFlag AS BYTE, Letter AS BYTE PTR
                          
                            FOR J = 1 TO PARSECOUNT(InText$, $CRLF)
                               Buf = PARSE$(InText$,$CRLF,J)
                               UCBuf = UCASE$(Buf) + $SPC
                               IF LEN(TRIM$(UCBuf))=0 THEN ITERATE FOR
                               lnLen = LEN(UCBuf$)
                               Letter = STRPTR(UCBuf) : wFlag = 0
                               FOR I = 1 TO LEN(UCBuf)
                                  SELECT CASE @Letter
                                     CASE 97 TO 122, 65 TO 90, 192 TO 214, 216 TO 246, 248 TO 255,35 TO 38, 48 TO 57, 63, 95 'word characters
                                        IF wFlag = 0 THEN wFlag = 1 : stopPos = I
                                     CASE 34 'string quotes -> "
                                       stopPos = INSTR(I + 1, UCBuf, CHR$(34)) 'Find match
                                       IF stopPos THEN
                                          StopPos = (StopPos - I + 1)
                                          I = I + StopPos
                                          Letter = Letter + StopPos
                                          wFlag = 0
                                       END IF
                                     CASE 39 'comment character -> '
                                        wFlag = 0
                                        EXIT FOR
                                     CASE ELSE  'word is ready
                                        IF wFlag = 1 THEN
                                           xWord = MID$(Buf, stopPos, I - stopPos)  'Get word
                                           IF xWord = "REM" THEN wFlag = 0 : EXIT FOR
                                           wFlag = 0
                                           '--- do something with the word here ---
                                           temp$ += $CRLF + xWord
                                           '---------------------------------------
                                        END IF
                                  END SELECT
                                  INCR Letter
                               NEXT I
                            NEXT J
                            FUNCTION = LTRIM$(temp$,$CRLF)
                          END FUNCTION
                          Rod
                          I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                          Comment


                          • #14
                            Added a function from Gary Beene Dedupe app.

                            Code:
                            [FONT=Consolas][COLOR=#008000]'Compilable Example:  (PB Includes)[/COLOR]
                            [COLOR=#0000FF]#Compile Exe[/COLOR]
                            [COLOR=#0000FF]#Dim All[/COLOR]
                            [COLOR=#0000FF]#Include[/COLOR] [COLOR=#FF0000]"Win32API.inc"[/COLOR]
                            
                            %IDC_Button [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]500[/COLOR]
                            %IDC_TextIn [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]501[/COLOR]
                            %IDC_TextOut [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]502[/COLOR]
                            
                            [COLOR=#0000FF]Global[/COLOR] hDlg,hFont [COLOR=#0000FF]As Dword[/COLOR]
                            [COLOR=#0000FF]Global[/COLOR] WordList[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As String[/COLOR]
                            
                            [COLOR=#0000FF]Function PBMain[/COLOR][COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As Long[/COLOR]
                               [COLOR=#0000FF]Local[/COLOR] temp$, [COLOR=#0000FF]Style[/COLOR]&
                               [COLOR=#0000FF]Style[/COLOR]& [COLOR=#FF0000]=[/COLOR] %WS_TABSTOP [COLOR=#0000FF]Or[/COLOR] %WS_BORDER [COLOR=#0000FF]Or[/COLOR] %ES_WANTRETURN [COLOR=#0000FF]Or[/COLOR] %ES_MULTILINE
                               temp$ [COLOR=#FF0000]=[/COLOR] [COLOR=#FF0000]"Sub MySub"[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$CrLf[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#FF0000]"   s += "[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$Dq[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#FF0000]"text"[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$Dq[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$CrLf[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#FF0000]"   Call MyFunction 'comment"[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$CrLf[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#FF0000]"End Sub"[/COLOR]
                               [COLOR=#0000FF]Dialog New Pixels[/COLOR], [COLOR=#400000]0[/COLOR], [COLOR=#FF0000]"Extract Words From Code"[/COLOR],[COLOR=#400000]300[/COLOR],[COLOR=#400000]300[/COLOR],[COLOR=#400000]505[/COLOR],[COLOR=#400000]230[/COLOR], %WS_OVERLAPPEDWINDOW [COLOR=#0000FF]To[/COLOR] hDlg
                               [COLOR=#0000FF]Control Add Button[/COLOR], hDlg, %IDC_Button,[COLOR=#FF0000]"Create Word List"[/COLOR], [COLOR=#400000]10[/COLOR],[COLOR=#400000]5[/COLOR],[COLOR=#400000]120[/COLOR],[COLOR=#400000]25[/COLOR]
                               [COLOR=#0000FF]Control Add TextBox[/COLOR], hDlg, %IDC_TextIn,temp$, [COLOR=#400000]10[/COLOR],[COLOR=#400000]35[/COLOR],[COLOR=#400000]240[/COLOR],[COLOR=#400000]190[/COLOR],[COLOR=#0000FF]Style[/COLOR]&, %WS_EX_CLIENTEDGE
                               [COLOR=#0000FF]Control Add TextBox[/COLOR], hDlg, %IDC_TextOut,[COLOR=#FF0000]"<output>"[/COLOR], [COLOR=#400000]260[/COLOR],[COLOR=#400000]35[/COLOR],[COLOR=#400000]240[/COLOR],[COLOR=#400000]190[/COLOR],[COLOR=#0000FF]Style[/COLOR]&, %WS_EX_CLIENTEDGE
                               [COLOR=#0000FF]Dialog Show Modal[/COLOR] hDlg [COLOR=#0000FF]Call[/COLOR] DlgProc
                            [COLOR=#0000FF]End Function[/COLOR]
                            [COLOR=#0000FF]CallBack Function[/COLOR] DlgProc[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As Long[/COLOR]
                               [COLOR=#0000FF]Local[/COLOR] temp$,tmp [COLOR=#0000FF]As String[/COLOR]
                               [COLOR=#0000FF]Select Case Cb.Msg[/COLOR]
                                  [COLOR=#0000FF]Case[/COLOR] %WM_INITDIALOG
                                     [COLOR=#0000FF]Font New[/COLOR] [COLOR=#FF0000]"Tahoma"[/COLOR],[COLOR=#400000]10[/COLOR],[COLOR=#400000]0[/COLOR] [COLOR=#0000FF]To[/COLOR] hFont
                                     [COLOR=#0000FF]Control Set Font[/COLOR] hDlg, %IDC_Button, hFont
                                     [COLOR=#0000FF]Control Set Font[/COLOR] hDlg, %IDC_TextIn, hFont
                                     [COLOR=#0000FF]Control Set Font[/COLOR] hDlg, %IDC_TextOut, hFont
                                  [COLOR=#0000FF]Case[/COLOR] %WM_COMMAND
                                     [COLOR=#0000FF]If Cb.Ctl[/COLOR] [COLOR=#FF0000]=[/COLOR] %IDC_Button [COLOR=#0000FF]And Cb.CtlMsg[/COLOR] [COLOR=#FF0000]=[/COLOR] %BN_CLICKED [COLOR=#0000FF]Then[/COLOR]
                                        [COLOR=#0000FF]Control Get Text[/COLOR] hDlg, %IDC_TextIn [COLOR=#0000FF]To[/COLOR] temp$
                                        tmp[COLOR=#FF0000]=[/COLOR]scanCode[COLOR=#FF0000]([/COLOR]temp$[COLOR=#FF0000])[/COLOR]
                                        RemoveDupes[COLOR=#FF0000]([/COLOR]tmp,[COLOR=#400000]1[/COLOR][COLOR=#FF0000])[/COLOR]  [COLOR=#008000]'0 no sorting. 1 sorting[/COLOR]
                                        [COLOR=#0000FF]Control Set Text[/COLOR] hDlg, %IDC_TextOut, tmp
                                     [COLOR=#0000FF]End If[/COLOR]
                               [COLOR=#0000FF]End Select[/COLOR]
                            [COLOR=#0000FF]End Function[/COLOR]
                            
                            [COLOR=#0000FF]Function[/COLOR] ScanCode[COLOR=#FF0000]([/COLOR]InText$[COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As String[/COLOR]
                              [COLOR=#0000FF]Local[/COLOR] temp$[COLOR=#008000]'pd As CHARRANGE, Oldpd As CHARRANGE, tBuff As TEXTRANGE,[/COLOR]
                              [COLOR=#0000FF]Local[/COLOR] xWord,Buf,UCBuf [COLOR=#0000FF]As String[/COLOR]
                              [COLOR=#0000FF]Local[/COLOR] i,j,StopPos,lnLen [COLOR=#0000FF]As Long[/COLOR]
                              [COLOR=#0000FF]Local[/COLOR] wFlag [COLOR=#0000FF]As Byte[/COLOR], Letter [COLOR=#0000FF]As Byte Ptr[/COLOR]
                            
                              [COLOR=#0000FF]For[/COLOR] J [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR] [COLOR=#0000FF]To ParseCount[/COLOR][COLOR=#FF0000]([/COLOR]InText$, [COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000])[/COLOR]
                                 Buf [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]Parse$[/COLOR][COLOR=#FF0000]([/COLOR]InText$,[COLOR=#0000FF]$CrLf[/COLOR],J[COLOR=#FF0000])[/COLOR]
                                 UCBuf [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]UCase$[/COLOR][COLOR=#FF0000]([/COLOR]Buf[COLOR=#FF0000])[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$Spc[/COLOR]
                                 [COLOR=#0000FF]If Len[/COLOR][COLOR=#FF0000]([/COLOR][COLOR=#0000FF]Trim$[/COLOR][COLOR=#FF0000]([/COLOR]UCBuf[COLOR=#FF0000])[/COLOR][COLOR=#FF0000])[/COLOR][COLOR=#FF0000]=[/COLOR][COLOR=#400000]0[/COLOR] [COLOR=#0000FF]Then Iterate For[/COLOR]
                                 lnLen [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]Len[/COLOR][COLOR=#FF0000]([/COLOR]UCBuf$[COLOR=#FF0000])[/COLOR]
                                 Letter [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]StrPtr[/COLOR][COLOR=#FF0000]([/COLOR]UCBuf[COLOR=#FF0000])[/COLOR] : wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR]
                                 [COLOR=#0000FF]For[/COLOR] I [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR] [COLOR=#0000FF]To Len[/COLOR][COLOR=#FF0000]([/COLOR]UCBuf[COLOR=#FF0000])[/COLOR]
                                    [COLOR=#0000FF]Select Case[/COLOR] @Letter
                                       [COLOR=#0000FF]Case[/COLOR] [COLOR=#400000]97[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]122[/COLOR], [COLOR=#400000]65[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]90[/COLOR], [COLOR=#400000]192[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]214[/COLOR], [COLOR=#400000]216[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]246[/COLOR], [COLOR=#400000]248[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]255[/COLOR],[COLOR=#400000]35[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]38[/COLOR], [COLOR=#400000]48[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]57[/COLOR], [COLOR=#400000]63[/COLOR], [COLOR=#400000]95[/COLOR] [COLOR=#008000]'word characters[/COLOR]
                                          [COLOR=#0000FF]If[/COLOR] wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR] [COLOR=#0000FF]Then[/COLOR] wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR] : stopPos [COLOR=#FF0000]=[/COLOR] I
                                       [COLOR=#0000FF]Case[/COLOR] [COLOR=#400000]34[/COLOR] [COLOR=#008000]'string quotes -> "[/COLOR]
                                         stopPos [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]InStr[/COLOR][COLOR=#FF0000]([/COLOR]I [COLOR=#FF0000]+[/COLOR] [COLOR=#400000]1[/COLOR], UCBuf, [COLOR=#0000FF]Chr$[/COLOR][COLOR=#FF0000]([/COLOR][COLOR=#400000]34[/COLOR][COLOR=#FF0000])[/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#008000]'Find match[/COLOR]
                                         [COLOR=#0000FF]If[/COLOR] stopPos [COLOR=#0000FF]Then[/COLOR]
                                            StopPos [COLOR=#FF0000]=[/COLOR] [COLOR=#FF0000]([/COLOR]StopPos [COLOR=#FF0000]-[/COLOR] I [COLOR=#FF0000]+[/COLOR] [COLOR=#400000]1[/COLOR][COLOR=#FF0000])[/COLOR]
                                            I [COLOR=#FF0000]=[/COLOR] I [COLOR=#FF0000]+[/COLOR] StopPos
                                            Letter [COLOR=#FF0000]=[/COLOR] Letter [COLOR=#FF0000]+[/COLOR] StopPos
                                            wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR]
                                         [COLOR=#0000FF]End If[/COLOR]
                                       [COLOR=#0000FF]Case[/COLOR] [COLOR=#400000]39[/COLOR] [COLOR=#008000]'comment character -> '[/COLOR]
                                          wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR]
                                          [COLOR=#0000FF]Exit For[/COLOR]
                                       [COLOR=#0000FF]Case Else[/COLOR]  [COLOR=#008000]'word is ready[/COLOR]
                                          [COLOR=#0000FF]If[/COLOR] wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR] [COLOR=#0000FF]Then[/COLOR]
                                             xWord [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]Mid$[/COLOR][COLOR=#FF0000]([/COLOR]Buf, stopPos, I [COLOR=#FF0000]-[/COLOR] stopPos[COLOR=#FF0000])[/COLOR]  [COLOR=#008000]'Get word[/COLOR]
                                             [COLOR=#0000FF]If[/COLOR] xWord [COLOR=#FF0000]=[/COLOR] [COLOR=#FF0000]"REM"[/COLOR] [COLOR=#0000FF]Then[/COLOR] wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR] : [COLOR=#0000FF]Exit For[/COLOR]
                                             wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR]
                                             [COLOR=#008000]'--- do something with the word here ---[/COLOR]
                                             temp$ [COLOR=#FF0000]+[/COLOR][COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]$CrLf[/COLOR] [COLOR=#FF0000]+[/COLOR] xWord
                                             [COLOR=#008000]'---------------------------------------[/COLOR]
                                          [COLOR=#0000FF]End If[/COLOR]
                                    [COLOR=#0000FF]End Select[/COLOR]
                                    [COLOR=#0000FF]Incr[/COLOR] Letter
                                 [COLOR=#0000FF]Next[/COLOR] I
                              [COLOR=#0000FF]Next[/COLOR] J
                              [COLOR=#0000FF]Function[/COLOR] [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]LTrim$[/COLOR][COLOR=#FF0000]([/COLOR]temp$,[COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000])[/COLOR]
                            [COLOR=#0000FF]End Function[/COLOR]
                            
                            [COLOR=#0000FF]Sub[/COLOR] RemoveDupes[COLOR=#FF0000]([/COLOR][COLOR=#0000FF]ByRef[/COLOR] listWords [COLOR=#0000FF]As String[/COLOR],Flag [COLOR=#0000FF]As Long[/COLOR][COLOR=#FF0000])[/COLOR]  [COLOR=#008000]'0 no sorting. 1 sorting[/COLOR]
                            [COLOR=#008000]'from Gary Beene Dedupe app[/COLOR]
                               [COLOR=#008000]'list of words delimited $crlf[/COLOR]
                               [COLOR=#0000FF]Local[/COLOR] i,j,iCount,iMax [COLOR=#0000FF]As Long[/COLOR], temp$
                            
                               [COLOR=#008000]'put Source text into array Words()[/COLOR]
                               temp$ [COLOR=#FF0000]=[/COLOR]listwords
                               [COLOR=#008000]'If CaseSensitive = 0 Then temp$ = LCase$(temp$)[/COLOR]
                               i [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]ParseCount[/COLOR][COLOR=#FF0000]([/COLOR]temp$,[COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000])[/COLOR]
                               [COLOR=#0000FF]Dim[/COLOR] Words[COLOR=#FF0000]([/COLOR]i[COLOR=#FF0000]-[/COLOR][COLOR=#400000]1[/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As String[/COLOR]
                               [COLOR=#0000FF]Parse[/COLOR] temp$, Words[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR], [COLOR=#0000FF]$CrLf[/COLOR]
                            
                               [COLOR=#0000FF]If[/COLOR] Flag [COLOR=#0000FF]Then[/COLOR]
                                  [COLOR=#008000]'Sorted[/COLOR]
                                  [COLOR=#0000FF]Array Sort[/COLOR] Words[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR]
                                  [COLOR=#0000FF]For[/COLOR] i [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]UBound[/COLOR][COLOR=#FF0000]([/COLOR]Words[COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]1[/COLOR] [COLOR=#0000FF]Step[/COLOR] [COLOR=#FF0000]-[/COLOR][COLOR=#400000]1[/COLOR]   [COLOR=#008000]'zero based array[/COLOR]
                                     [COLOR=#0000FF]If[/COLOR] Words[COLOR=#FF0000]([/COLOR]i[COLOR=#FF0000])[/COLOR] [COLOR=#FF0000]=[/COLOR] Words[COLOR=#FF0000]([/COLOR]i[COLOR=#FF0000]-[/COLOR][COLOR=#400000]1[/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]Then Array Delete[/COLOR] Words[COLOR=#FF0000]([/COLOR]i[COLOR=#FF0000])[/COLOR] : [COLOR=#0000FF]Incr[/COLOR] iCount
                                  [COLOR=#0000FF]Next[/COLOR] i
                                  [COLOR=#0000FF]ReDim Preserve[/COLOR] Words[COLOR=#FF0000]([/COLOR][COLOR=#0000FF]UBound[/COLOR][COLOR=#FF0000]([/COLOR]Words[COLOR=#FF0000])[/COLOR][COLOR=#FF0000]-[/COLOR]iCount[COLOR=#FF0000])[/COLOR]
                               [COLOR=#0000FF]Else[/COLOR]
                                  [COLOR=#008000]'Not sorted[/COLOR]
                                  iMax [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]UBound[/COLOR][COLOR=#FF0000]([/COLOR]Words[COLOR=#FF0000])[/COLOR]
                                       [COLOR=#0000FF]For[/COLOR] i [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR] [COLOR=#0000FF]To[/COLOR] iMax[COLOR=#FF0000]-[/COLOR][COLOR=#400000]1[/COLOR]
                                     [COLOR=#0000FF]For[/COLOR] j [COLOR=#FF0000]=[/COLOR] iMax [COLOR=#0000FF]To[/COLOR] i[COLOR=#FF0000]+[/COLOR][COLOR=#400000]1[/COLOR] [COLOR=#0000FF]Step[/COLOR] [COLOR=#FF0000]-[/COLOR][COLOR=#400000]1[/COLOR]
                                        [COLOR=#0000FF]If[/COLOR] Words[COLOR=#FF0000]([/COLOR]j[COLOR=#FF0000])[/COLOR] [COLOR=#FF0000]=[/COLOR] Words[COLOR=#FF0000]([/COLOR]i[COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]Then Array Delete[/COLOR] Words[COLOR=#FF0000]([/COLOR]j[COLOR=#FF0000])[/COLOR] : [COLOR=#0000FF]Decr[/COLOR] iMax
                                     [COLOR=#0000FF]Next[/COLOR] j
                                  [COLOR=#0000FF]Next[/COLOR] i
                                  [COLOR=#0000FF]ReDim Preserve[/COLOR] Words[COLOR=#FF0000]([/COLOR]iMax[COLOR=#FF0000])[/COLOR]
                               [COLOR=#0000FF]End If[/COLOR]
                            
                               listWords[COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]Join$[/COLOR][COLOR=#FF0000]([/COLOR]Words[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR],[COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000])[/COLOR]
                              [COLOR=#008000]' MousePtr 1[/COLOR]
                            [COLOR=#0000FF]End Sub[/COLOR] [/FONT]

                            Comment


                            • #15
                              Added Borje Hagsten GetWordCount function to program.


                              Code:
                              [FONT=Consolas][COLOR=#008000]'Compilable Example:  (PB Includes)[/COLOR]
                              [COLOR=#0000FF]#Compile Exe[/COLOR]
                              [COLOR=#0000FF]#Dim All[/COLOR]
                              [COLOR=#0000FF]#Include[/COLOR] [COLOR=#FF0000]"Win32API.inc"[/COLOR]
                              
                              %IDC_Button [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]500[/COLOR]
                              %IDC_TextIn [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]501[/COLOR]
                              %IDC_TextOut [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]502[/COLOR]
                              
                              [COLOR=#0000FF]Global[/COLOR] hDlg,hFont [COLOR=#0000FF]As Dword[/COLOR]
                              [COLOR=#0000FF]Global[/COLOR] WordList[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As String[/COLOR]
                              
                              [COLOR=#0000FF]Function PBMain[/COLOR][COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As Long[/COLOR]
                                 [COLOR=#0000FF]Local[/COLOR] temp$, [COLOR=#0000FF]Style[/COLOR]&
                                 [COLOR=#0000FF]Style[/COLOR]& [COLOR=#FF0000]=[/COLOR] %WS_TABSTOP [COLOR=#0000FF]Or[/COLOR] %WS_BORDER [COLOR=#0000FF]Or[/COLOR] %ES_WANTRETURN [COLOR=#0000FF]Or[/COLOR] %ES_MULTILINE
                                 temp$ [COLOR=#FF0000]=[/COLOR] [COLOR=#FF0000]"Sub MySub"[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$CrLf[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#FF0000]"   s += "[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$Dq[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#FF0000]"text"[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$Dq[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$CrLf[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#FF0000]"   Call MyFunction 'comment"[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$CrLf[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#FF0000]"End Sub"[/COLOR]
                                 [COLOR=#0000FF]Dialog New Pixels[/COLOR], [COLOR=#400000]0[/COLOR], [COLOR=#FF0000]"Extract Words From Code"[/COLOR],[COLOR=#400000]300[/COLOR],[COLOR=#400000]300[/COLOR],[COLOR=#400000]505[/COLOR],[COLOR=#400000]230[/COLOR], %WS_OVERLAPPEDWINDOW [COLOR=#0000FF]To[/COLOR] hDlg
                                 [COLOR=#0000FF]Control Add Button[/COLOR], hDlg, %IDC_Button,[COLOR=#FF0000]"Create Word List"[/COLOR], [COLOR=#400000]10[/COLOR],[COLOR=#400000]5[/COLOR],[COLOR=#400000]120[/COLOR],[COLOR=#400000]25[/COLOR]
                                 [COLOR=#0000FF]Control Add TextBox[/COLOR], hDlg, %IDC_TextIn,temp$, [COLOR=#400000]10[/COLOR],[COLOR=#400000]35[/COLOR],[COLOR=#400000]240[/COLOR],[COLOR=#400000]190[/COLOR],[COLOR=#0000FF]Style[/COLOR]&, %WS_EX_CLIENTEDGE
                                 [COLOR=#0000FF]Control Add TextBox[/COLOR], hDlg, %IDC_TextOut,[COLOR=#FF0000]"<output>"[/COLOR], [COLOR=#400000]260[/COLOR],[COLOR=#400000]35[/COLOR],[COLOR=#400000]240[/COLOR],[COLOR=#400000]190[/COLOR],[COLOR=#0000FF]Style[/COLOR]&, %WS_EX_CLIENTEDGE
                                 [COLOR=#0000FF]Dialog Show Modal[/COLOR] hDlg [COLOR=#0000FF]Call[/COLOR] DlgProc
                              [COLOR=#0000FF]End Function[/COLOR]
                              [COLOR=#0000FF]CallBack Function[/COLOR] DlgProc[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As Long[/COLOR]
                                 [COLOR=#0000FF]Local[/COLOR] temp$,tmp [COLOR=#0000FF]As String[/COLOR],wordCnt [COLOR=#0000FF]As Long[/COLOR]
                                 [COLOR=#0000FF]Select Case Cb.Msg[/COLOR]
                                    [COLOR=#0000FF]Case[/COLOR] %WM_INITDIALOG
                                       [COLOR=#0000FF]Font New[/COLOR] [COLOR=#FF0000]"Tahoma"[/COLOR],[COLOR=#400000]10[/COLOR],[COLOR=#400000]0[/COLOR] [COLOR=#0000FF]To[/COLOR] hFont
                                       [COLOR=#0000FF]Control Set Font[/COLOR] hDlg, %IDC_Button, hFont
                                       [COLOR=#0000FF]Control Set Font[/COLOR] hDlg, %IDC_TextIn, hFont
                                       [COLOR=#0000FF]Control Set Font[/COLOR] hDlg, %IDC_TextOut, hFont
                                    [COLOR=#0000FF]Case[/COLOR] %WM_COMMAND
                                       [COLOR=#0000FF]If Cb.Ctl[/COLOR] [COLOR=#FF0000]=[/COLOR] %IDC_Button [COLOR=#0000FF]And Cb.CtlMsg[/COLOR] [COLOR=#FF0000]=[/COLOR] %BN_CLICKED [COLOR=#0000FF]Then[/COLOR]
                                          [COLOR=#0000FF]Control Get Text[/COLOR] hDlg, %IDC_TextIn [COLOR=#0000FF]To[/COLOR] temp$
                                          wordCnt[COLOR=#FF0000]=[/COLOR]GetWordCount[COLOR=#FF0000]([/COLOR]temp$[COLOR=#FF0000])[/COLOR]
                                          tmp[COLOR=#FF0000]=[/COLOR]scanCode[COLOR=#FF0000]([/COLOR]temp$[COLOR=#FF0000])[/COLOR]
                                          RemoveDupes[COLOR=#FF0000]([/COLOR]tmp,[COLOR=#400000]1[/COLOR][COLOR=#FF0000])[/COLOR]  [COLOR=#008000]'0 no sorting. 1 sorting[/COLOR]
                                          tmp[COLOR=#FF0000]=[/COLOR][COLOR=#FF0000]"Borje Hagsten WORD COUNT: "[/COLOR][COLOR=#FF0000]+[/COLOR][COLOR=#0000FF]Str$[/COLOR][COLOR=#FF0000]([/COLOR]wordCnt[COLOR=#FF0000])[/COLOR][COLOR=#FF0000]+[/COLOR][COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000]+[/COLOR][COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000]+[/COLOR][COLOR=#FF0000]"==============="[/COLOR][COLOR=#FF0000]+[/COLOR][COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000]+[/COLOR]  tmp
                                          [COLOR=#0000FF]Control Set Text[/COLOR] hDlg, %IDC_TextOut, tmp
                                       [COLOR=#0000FF]End If[/COLOR]
                                 [COLOR=#0000FF]End Select[/COLOR]
                              [COLOR=#0000FF]End Function[/COLOR]
                              
                              [COLOR=#0000FF]Function[/COLOR] ScanCode[COLOR=#FF0000]([/COLOR]InText$[COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As String[/COLOR]
                                [COLOR=#0000FF]Local[/COLOR] temp$[COLOR=#008000]'pd As CHARRANGE, Oldpd As CHARRANGE, tBuff As TEXTRANGE,[/COLOR]
                                [COLOR=#0000FF]Local[/COLOR] xWord,Buf,UCBuf [COLOR=#0000FF]As String[/COLOR]
                                [COLOR=#0000FF]Local[/COLOR] i,j,StopPos,lnLen [COLOR=#0000FF]As Long[/COLOR]
                                [COLOR=#0000FF]Local[/COLOR] wFlag [COLOR=#0000FF]As Byte[/COLOR], Letter [COLOR=#0000FF]As Byte Ptr[/COLOR]
                              
                                [COLOR=#0000FF]For[/COLOR] J [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR] [COLOR=#0000FF]To ParseCount[/COLOR][COLOR=#FF0000]([/COLOR]InText$, [COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000])[/COLOR]
                                   Buf [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]Parse$[/COLOR][COLOR=#FF0000]([/COLOR]InText$,[COLOR=#0000FF]$CrLf[/COLOR],J[COLOR=#FF0000])[/COLOR]
                                   UCBuf [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]UCase$[/COLOR][COLOR=#FF0000]([/COLOR]Buf[COLOR=#FF0000])[/COLOR] [COLOR=#FF0000]+[/COLOR] [COLOR=#0000FF]$Spc[/COLOR]
                                   [COLOR=#0000FF]If Len[/COLOR][COLOR=#FF0000]([/COLOR][COLOR=#0000FF]Trim$[/COLOR][COLOR=#FF0000]([/COLOR]UCBuf[COLOR=#FF0000])[/COLOR][COLOR=#FF0000])[/COLOR][COLOR=#FF0000]=[/COLOR][COLOR=#400000]0[/COLOR] [COLOR=#0000FF]Then Iterate For[/COLOR]
                                   lnLen [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]Len[/COLOR][COLOR=#FF0000]([/COLOR]UCBuf$[COLOR=#FF0000])[/COLOR]
                                   Letter [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]StrPtr[/COLOR][COLOR=#FF0000]([/COLOR]UCBuf[COLOR=#FF0000])[/COLOR] : wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR]
                                   [COLOR=#0000FF]For[/COLOR] I [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR] [COLOR=#0000FF]To Len[/COLOR][COLOR=#FF0000]([/COLOR]UCBuf[COLOR=#FF0000])[/COLOR]
                                      [COLOR=#0000FF]Select Case[/COLOR] @Letter
                                         [COLOR=#0000FF]Case[/COLOR] [COLOR=#400000]97[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]122[/COLOR], [COLOR=#400000]65[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]90[/COLOR], [COLOR=#400000]192[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]214[/COLOR], [COLOR=#400000]216[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]246[/COLOR], [COLOR=#400000]248[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]255[/COLOR],[COLOR=#400000]35[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]38[/COLOR], [COLOR=#400000]48[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]57[/COLOR], [COLOR=#400000]63[/COLOR], [COLOR=#400000]95[/COLOR] [COLOR=#008000]'word characters[/COLOR]
                                            [COLOR=#0000FF]If[/COLOR] wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR] [COLOR=#0000FF]Then[/COLOR] wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR] : stopPos [COLOR=#FF0000]=[/COLOR] I
                                         [COLOR=#0000FF]Case[/COLOR] [COLOR=#400000]34[/COLOR] [COLOR=#008000]'string quotes -> "[/COLOR]
                                           stopPos [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]InStr[/COLOR][COLOR=#FF0000]([/COLOR]I [COLOR=#FF0000]+[/COLOR] [COLOR=#400000]1[/COLOR], UCBuf, [COLOR=#0000FF]Chr$[/COLOR][COLOR=#FF0000]([/COLOR][COLOR=#400000]34[/COLOR][COLOR=#FF0000])[/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#008000]'Find match[/COLOR]
                                           [COLOR=#0000FF]If[/COLOR] stopPos [COLOR=#0000FF]Then[/COLOR]
                                              StopPos [COLOR=#FF0000]=[/COLOR] [COLOR=#FF0000]([/COLOR]StopPos [COLOR=#FF0000]-[/COLOR] I [COLOR=#FF0000]+[/COLOR] [COLOR=#400000]1[/COLOR][COLOR=#FF0000])[/COLOR]
                                              I [COLOR=#FF0000]=[/COLOR] I [COLOR=#FF0000]+[/COLOR] StopPos
                                              Letter [COLOR=#FF0000]=[/COLOR] Letter [COLOR=#FF0000]+[/COLOR] StopPos
                                              wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR]
                                           [COLOR=#0000FF]End If[/COLOR]
                                         [COLOR=#0000FF]Case[/COLOR] [COLOR=#400000]39[/COLOR] [COLOR=#008000]'comment character -> '[/COLOR]
                                            wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR]
                                            [COLOR=#0000FF]Exit For[/COLOR]
                                         [COLOR=#0000FF]Case Else[/COLOR]  [COLOR=#008000]'word is ready[/COLOR]
                                            [COLOR=#0000FF]If[/COLOR] wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR] [COLOR=#0000FF]Then[/COLOR]
                                               xWord [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]Mid$[/COLOR][COLOR=#FF0000]([/COLOR]Buf, stopPos, I [COLOR=#FF0000]-[/COLOR] stopPos[COLOR=#FF0000])[/COLOR]  [COLOR=#008000]'Get word[/COLOR]
                                               [COLOR=#0000FF]If[/COLOR] xWord [COLOR=#FF0000]=[/COLOR] [COLOR=#FF0000]"REM"[/COLOR] [COLOR=#0000FF]Then[/COLOR] wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR] : [COLOR=#0000FF]Exit For[/COLOR]
                                               wFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR]
                                               [COLOR=#008000]'--- do something with the word here ---[/COLOR]
                                               temp$ [COLOR=#FF0000]+[/COLOR][COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]$CrLf[/COLOR] [COLOR=#FF0000]+[/COLOR] xWord
                                               [COLOR=#008000]'---------------------------------------[/COLOR]
                                            [COLOR=#0000FF]End If[/COLOR]
                                      [COLOR=#0000FF]End Select[/COLOR]
                                      [COLOR=#0000FF]Incr[/COLOR] Letter
                                   [COLOR=#0000FF]Next[/COLOR] I
                                [COLOR=#0000FF]Next[/COLOR] J
                                [COLOR=#0000FF]Function[/COLOR] [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]LTrim$[/COLOR][COLOR=#FF0000]([/COLOR]temp$,[COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000])[/COLOR]
                              [COLOR=#0000FF]End Function[/COLOR]
                              
                              [COLOR=#0000FF]Sub[/COLOR] RemoveDupes[COLOR=#FF0000]([/COLOR][COLOR=#0000FF]ByRef[/COLOR] listWords [COLOR=#0000FF]As String[/COLOR],Flag [COLOR=#0000FF]As Long[/COLOR][COLOR=#FF0000])[/COLOR]  [COLOR=#008000]'0 no sorting. 1 sorting[/COLOR]
                              [COLOR=#008000]'from Gary Beene Dedupe app[/COLOR]
                                 [COLOR=#008000]'list of words delimited $crlf[/COLOR]
                                 [COLOR=#0000FF]Local[/COLOR] i,j,iCount,iMax [COLOR=#0000FF]As Long[/COLOR], temp$
                              
                                 [COLOR=#008000]'put Source text into array Words()[/COLOR]
                                 temp$ [COLOR=#FF0000]=[/COLOR]listwords
                                 [COLOR=#008000]'If CaseSensitive = 0 Then temp$ = LCase$(temp$)[/COLOR]
                                 i [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]ParseCount[/COLOR][COLOR=#FF0000]([/COLOR]temp$,[COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000])[/COLOR]
                                 [COLOR=#0000FF]Dim[/COLOR] Words[COLOR=#FF0000]([/COLOR]i[COLOR=#FF0000]-[/COLOR][COLOR=#400000]1[/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As String[/COLOR]
                                 [COLOR=#0000FF]Parse[/COLOR] temp$, Words[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR], [COLOR=#0000FF]$CrLf[/COLOR]
                              
                                 [COLOR=#0000FF]If[/COLOR] Flag [COLOR=#0000FF]Then[/COLOR]
                                    [COLOR=#008000]'Sorted[/COLOR]
                                    [COLOR=#0000FF]Array Sort[/COLOR] Words[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR]
                                    [COLOR=#0000FF]For[/COLOR] i [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]UBound[/COLOR][COLOR=#FF0000]([/COLOR]Words[COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]1[/COLOR] [COLOR=#0000FF]Step[/COLOR] [COLOR=#FF0000]-[/COLOR][COLOR=#400000]1[/COLOR]   [COLOR=#008000]'zero based array[/COLOR]
                                       [COLOR=#0000FF]If[/COLOR] Words[COLOR=#FF0000]([/COLOR]i[COLOR=#FF0000])[/COLOR] [COLOR=#FF0000]=[/COLOR] Words[COLOR=#FF0000]([/COLOR]i[COLOR=#FF0000]-[/COLOR][COLOR=#400000]1[/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]Then Array Delete[/COLOR] Words[COLOR=#FF0000]([/COLOR]i[COLOR=#FF0000])[/COLOR] : [COLOR=#0000FF]Incr[/COLOR] iCount
                                    [COLOR=#0000FF]Next[/COLOR] i
                                    [COLOR=#0000FF]ReDim Preserve[/COLOR] Words[COLOR=#FF0000]([/COLOR][COLOR=#0000FF]UBound[/COLOR][COLOR=#FF0000]([/COLOR]Words[COLOR=#FF0000])[/COLOR][COLOR=#FF0000]-[/COLOR]iCount[COLOR=#FF0000])[/COLOR]
                                 [COLOR=#0000FF]Else[/COLOR]
                                    [COLOR=#008000]'Not sorted[/COLOR]
                                    iMax [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]UBound[/COLOR][COLOR=#FF0000]([/COLOR]Words[COLOR=#FF0000])[/COLOR]
                                         [COLOR=#0000FF]For[/COLOR] i [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR] [COLOR=#0000FF]To[/COLOR] iMax[COLOR=#FF0000]-[/COLOR][COLOR=#400000]1[/COLOR]
                                       [COLOR=#0000FF]For[/COLOR] j [COLOR=#FF0000]=[/COLOR] iMax [COLOR=#0000FF]To[/COLOR] i[COLOR=#FF0000]+[/COLOR][COLOR=#400000]1[/COLOR] [COLOR=#0000FF]Step[/COLOR] [COLOR=#FF0000]-[/COLOR][COLOR=#400000]1[/COLOR]
                                          [COLOR=#0000FF]If[/COLOR] Words[COLOR=#FF0000]([/COLOR]j[COLOR=#FF0000])[/COLOR] [COLOR=#FF0000]=[/COLOR] Words[COLOR=#FF0000]([/COLOR]i[COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]Then Array Delete[/COLOR] Words[COLOR=#FF0000]([/COLOR]j[COLOR=#FF0000])[/COLOR] : [COLOR=#0000FF]Decr[/COLOR] iMax
                                       [COLOR=#0000FF]Next[/COLOR] j
                                    [COLOR=#0000FF]Next[/COLOR] i
                                    [COLOR=#0000FF]ReDim Preserve[/COLOR] Words[COLOR=#FF0000]([/COLOR]iMax[COLOR=#FF0000])[/COLOR]
                                 [COLOR=#0000FF]End If[/COLOR]
                              
                                 listWords[COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]Join$[/COLOR][COLOR=#FF0000]([/COLOR]Words[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR],[COLOR=#0000FF]$CrLf[/COLOR][COLOR=#FF0000])[/COLOR]
                                [COLOR=#008000]' MousePtr 1[/COLOR]
                              [COLOR=#0000FF]End Sub[/COLOR]
                              
                                [COLOR=#008000]' Wordcount procedures in strings can be done in many different ways.[/COLOR]
                                [COLOR=#008000]' The following one uses pointers to loop through the text, which is[/COLOR]
                                [COLOR=#008000]' very fast and also gives you the ability to set what you want to[/COLOR]
                                [COLOR=#008000]' count in as words. Extended ANSI characters supported. Use like:[/COLOR]
                                [COLOR=#008000]'[/COLOR]
                                [COLOR=#008000]' WordCount& = GetWordCount(MyString$)[/COLOR]
                                [COLOR=#008000]'[/COLOR]
                                [COLOR=#008000]' It's simple, but still far more correct than MS Word's crappy one.[/COLOR]
                                [COLOR=#008000]' (and faster) (MS Word even counts separated dots as words, etc..)[/COLOR]
                                [COLOR=#008000]'-------------------------------------------------------------------[/COLOR]
                              [COLOR=#0000FF]Function[/COLOR] GetWordCount[COLOR=#FF0000]([/COLOR][COLOR=#0000FF]ByVal[/COLOR] tStr [COLOR=#0000FF]As String[/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]As Long[/COLOR]
                              
                                  [COLOR=#0000FF]Local[/COLOR] wordFlag [COLOR=#0000FF]As Byte[/COLOR], wCount [COLOR=#0000FF]As Long[/COLOR], Letter [COLOR=#0000FF]As Byte Ptr[/COLOR]
                              
                                  [COLOR=#0000FF]For[/COLOR] Letter [COLOR=#FF0000]=[/COLOR] [COLOR=#0000FF]StrPtr[/COLOR][COLOR=#FF0000]([/COLOR]tStr[COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#FF0000]([/COLOR][COLOR=#0000FF]StrPtr[/COLOR][COLOR=#FF0000]([/COLOR]tStr[COLOR=#FF0000])[/COLOR] [COLOR=#FF0000]+[/COLOR]  [COLOR=#0000FF]Len[/COLOR][COLOR=#FF0000]([/COLOR]tStr[COLOR=#FF0000])[/COLOR] [COLOR=#FF0000]-[/COLOR] [COLOR=#400000]1[/COLOR][COLOR=#FF0000])[/COLOR]
                                    [COLOR=#0000FF]Select Case[/COLOR] @Letter
                                      [COLOR=#0000FF]Case[/COLOR] [COLOR=#400000]97[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]122[/COLOR], [COLOR=#400000]65[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]90[/COLOR], [COLOR=#400000]192[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]214[/COLOR], _
                                                    [COLOR=#400000]216[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]246[/COLOR], [COLOR=#400000]248[/COLOR] [COLOR=#0000FF]To[/COLOR] [COLOR=#400000]255[/COLOR], [COLOR=#400000]39[/COLOR], [COLOR=#400000]96[/COLOR], [COLOR=#400000]180[/COLOR], [COLOR=#400000]45[/COLOR], [COLOR=#400000]146[/COLOR]
                                        [COLOR=#0000FF]If[/COLOR] [COLOR=#FF0000]([/COLOR]wordFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR] [COLOR=#0000FF]And[/COLOR] @Letter [COLOR=#FF0000]<[/COLOR][COLOR=#FF0000]>[/COLOR] [COLOR=#400000]45[/COLOR][COLOR=#FF0000])[/COLOR] [COLOR=#0000FF]Then[/COLOR] [COLOR=#008000]'not '-' outside words[/COLOR]
                                          [COLOR=#008000]'Set flag when we hit an approved letter or apostroph, etc.[/COLOR]
                                          wordFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR]
                                        [COLOR=#0000FF]End If[/COLOR]
                                      [COLOR=#0000FF]Case Else[/COLOR]
                                        [COLOR=#008000]'Increase when we hit something else, like space, dot, etc..[/COLOR]
                                        [COLOR=#0000FF]If[/COLOR] wordFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR] [COLOR=#0000FF]Then[/COLOR]
                                          wordFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]0[/COLOR]: [COLOR=#0000FF]Incr[/COLOR] wCount
                                        [COLOR=#0000FF]End If[/COLOR]
                                    [COLOR=#0000FF]End Select[/COLOR]
                                  [COLOR=#0000FF]Next[/COLOR]
                              
                                  [COLOR=#008000]'Add one in case there were letters all the way to the end..[/COLOR]
                                  [COLOR=#0000FF]If[/COLOR] wordFlag [COLOR=#FF0000]=[/COLOR] [COLOR=#400000]1[/COLOR] [COLOR=#0000FF]Then Incr[/COLOR] wCount
                              
                                  [COLOR=#0000FF]Function[/COLOR] [COLOR=#FF0000]=[/COLOR] wCount [COLOR=#008000]'The function returns the number of words[/COLOR]
                                [COLOR=#0000FF]End Function[/COLOR] [/FONT]

                              Comment


                              • #16
                                is there a compelling reason to pick up vsn 10?
                                If you want to get code here to use, much of it will be written with version 10. v10 is also a native Unicode (wide) compiler and supports much more COM interface utility ,

                                In a broader front, if you are looking for a word count function, use an internet search engine to look for "Windows equivalent to Unix 'wc'' utility." Unix wc is exactly what you asked for and I'll bet someone has created a Windows version. That said, 'wc' is a command-line utility and I cannot tell what use you are looking to satisfy.

                                MCM
                                Michael Mattias
                                Tal Systems (retired)
                                Port Washington WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  Dale

                                  Comment

                                  Working...
                                  X