Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Location
    San Diego, CA
    Posts
    7

    Question Unanswered: Count only certain word in memo

    Hi,

    How I can count certain word in memo field?

    For example I have 15 words in one field and "PLUMING" word repeats in
    it 3 times. So I would like my code give me number three as the
    answer.

    Any help with it will be kindly,
    Alex

  2. #2
    Join Date
    Sep 2003
    Posts
    228
    I have a solution but it assumes you know the word you want to count
    The solution below searches for the string "Steve_Bartman" but, you can easily substitue a variable for the string to search for...

    You can easily send values into the function as parameters and return the number of times the word was counted as the return value. Also this function alters the string you are searching so be sure to send in a copy of the string not the actual data...

    PHP Code:
        Dim Temp1 As String
        Dim Temp2 
    As String
        Dim start_pos 
    As Variant
        Dim strlen 
    As Integer
        Dim input_string 
    As String
        Dim i 
    As Integer
        
    Const delim "!@#"
        
    Dim findwhat As String
        Dim findwhatlen 
    As Integer
        
        input_string 
    "A cat was walking Steve_Bartman down the Steve_Bartman street."
        
    findwhat "Steve_Bartman"
        
        
    start_pos InStr(input_string"Steve_Bartman")
        
    strlen Len(input_string)
        
    findwhatlen Len(findwhat)
        
    0
        
        
    'Here we loop through the string and turn all findwhats into 
        '
    a delimeter so we can move on to the next findwhat
        
    Do While start_pos <> And Not IsNull(start_pos)
            
    Temp1 Left(input_stringstart_pos 1)
            
    Temp2 Right(input_string, (strlen start_pos findwhatlen))
            
    input_string Temp1 delim Temp2
            start_pos 
    InStr(input_string"Steve_Bartman")
            
    1
            strlen 
    Len(input_string)
        
    Loop
        
        MsgBox 
    "Steve_Bartman was in the string " " times." 
    Last edited by ottomatic; 10-13-04 at 20:42.

  3. #3
    Join Date
    May 2004
    Location
    San Diego, CA
    Posts
    7

    Smile

    Thanks! Works just fine!!!

    Alex

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •