Results 1 to 8 of 8

Thread: Function - Please help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Malaysia
    Posts
    90

    Question

    Hi,
    Appreciate very much if someone can point out my mistake on the code sample below. What I am trying to do is to eliminate the "'" in front and at the back of the date string.

    Kind regards



    Public mtext As String

    Private Sub Command1_Click()
    Dim rDate As String
    rDate = "'09/07/00'"
    mtext = strip34(rDate)
    msgbox(mtext) ' THIS MSGBOX RETURNED EMPTY STRING
    End Sub

    Private Function strip34(mStr As String)
    Dim xCount%, iPos%
    For xCount% = 1 To 2
    iPos% = InStr(mStr, "'")
    'Found at first position?
    If iPos% = 1 Then
    mStr = Mid(mStr, iPos% + 1, Len(Trim(mStr)))
    Else
    mStr = Mid(mStr, 1, iPos% - 1)
    End If
    Next xCount%
    mtext = mStr
    End Function
    CT

  2. #2
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Sydney Australia
    Posts
    476
    Loose the % and try again.

  3. #3
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Code:
    Public mtext As String
    
    Private Sub Command1_Click()
     Dim rDate As String
        rDate = "'09/07/00'"
        mtext = strip34(rDate) 'mtext is assigned the value returned by strip34
        MsgBox (mtext) ' THIS MSGBOX RETURNED EMPTY STRING
    End Sub
    
    Private Function strip34(mStr As String) As String
     Dim xCount%, iPos%
    
        For xCount% = 1 To 2
    
            iPos% = InStr(mStr, "'")
    
             'Found at first position?
             If iPos% = 1 Then
    
                mStr = Mid(mStr, iPos% + 1, Len(Trim(mStr)))
    
             Else
    
                mStr = Mid(mStr, 1, iPos% - 1)
    
             End If
    
        Next xCount%
    
        strip34 = mStr 'ASSIGN THE VALUE OF mStr to be returned by this function
    
    End Function
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    Public mtext As String
    
    Private Sub Command1_Click()
        Dim rDate As String
        rDate = "'09/07/00'"
        rDate = strip34(rDate)
        MsgBox mtext
    End Sub
    
    Public Function strip34(mStr As String) As String
    
        Dim xCount As Integer, intLen As Integer
        intLen = Len(mStr)
        
        For xCount = 1 To intLen
        
        If Mid(mStr, xCount, 1) = "'" Then Mid(mStr, xCount, 1) = " "
                 Next xCount
              mStr = Trim(mStr)
              mtext = mStr
    End Function
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Malaysia
    Posts
    90
    Thanks YoungBuck, it is working now!
    Magic word is strip34 = mstr

    kind regards
    CT

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Malaysia
    Posts
    90
    Many thanks to all those who has responded to my problem above.

    Kind regards
    CT

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    If you have VB6 there is also Replace

    rDate = replace(rdate,"'","")
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Malaysia
    Posts
    90
    Thanks to HeSaidJoe, Replace function pointed is even more efficient.

    Best regards
    CT

Posting Permissions

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



Click Here to Expand Forum to Full Width