How to Validate character pattern in string

Discussion in 'C++' started by nhicks, Jun 26, 2010.

  1. nhicks

    nhicks New Member

    Joined:
    Jun 26, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi, I have this in VBA. Don't know much about C++, if this can be done with C++, help would be appreciated. thank you...nelson
    Code:
    Function ValidAddr(addr As String) As Boolean
        Dim BadAddrs(2)
        Dim pos As Long
        Dim i As Integer
        pos = 0
        i = 0
    
        BadAddrs(0) = "PO BOX"
        BadAddrs(1) = "P.O BOX"
        BadAddrs(2) = " P.O. BOX"
        
        For i = LBound(BadAddrs) To UBound(BadAddrs)
            If (pos = 0) Then
                pos = InStr(1, addr, BadAddrs(i))
            End If
        Next i
        
        If (pos <> 0) Then
            ValidAddr = False
        Else
            ValidAddr = True
        End If
    End Function
    
    Sub CheckAddr()
        Dim isAddrPOBox As Boolean
        isAddrPOBox = False
        
        isAddrPOBox = ValidAddr("P.O BOX Rt. 11 P.O there")
        MsgBox isAddrPOBox
    End Sub
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice