Results 1 to 55 of 55

VBA Developers Handbook, 2nd Edition. questions on procedures and functions

Threaded View

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    VBA Developers Handbook, 2nd Edition. questions on procedures and functions

    so im reading VBA Developer's Handbook, 2nd edition and i have a question about a function (why it's returning 0, when it should be greater than 0). see below:

    Public Function dhCountInCaseS(strText As String, strFind As String, Optional lngCompare As VbCompareMethod = vbBinaryCompare) As Long
        Dim lngCount As Long
        Dim lngPos As Long
        'this search is case sensitive so "A" is not the same as "a"
        'if there's nothing to find, there surely can't be an found so return 0
        If Len(strFind) > 0 Then
            lngPos = 1
            Do
                lngPos = InStr(lngPos, strText, strFind, lngCompare)
                If lngPos > 0 Then
                    lngCount = lngCount + 1
                    lngPos = lngPos + Len(strFind)
                End If
            Loop While lngPos > 0
        Else
            lngCount = 0
        End If
        dhCountIn = lngCount
    End Function
    and here is the procedure

    Sub Count_Vowels()
        Dim strText As String
        Dim intVowels As Long
        
        strText = "THIS IS A TEST OF THE NATIONAL BROADCASTING SYSTEM"
        
        intVowels = dhCountInCaseS(strText, "A") + dhCountInCaseS(strText, "E") + dhCountInCaseS(strText, "I") + _
        dhCountInCaseS(strText, "O") + dhCountInCaseS(strText, "U")
        
        Debug.Print intVowels
    End Sub
    Is there a problem with the function or how i'm implementing the procedure?
    Last edited by dmcgov; 03-25-2019 at 07:29 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Which test is best for abnormal returns?
    By WASIM_PAK in forum Excel General
    Replies: 0
    Last Post: 08-27-2015, 11:39 AM
  2. Replies: 1
    Last Post: 08-10-2015, 10:30 AM
  3. Replies: 4
    Last Post: 08-07-2013, 11:29 AM
  4. return a value for a greater than less than logic test
    By azruss in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-03-2013, 12:50 PM
  5. Replies: 5
    Last Post: 12-09-2012, 11:04 PM
  6. WorksheetFunction.Sum returns 0 for array of elements whose sum is greater than 0
    By RowanB in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-12-2012, 06:15 AM
  7. Change Test Color If Value is Greater Than Another
    By BluTalon in forum Excel General
    Replies: 8
    Last Post: 11-07-2008, 10:24 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1