Results 1 to 8 of 8
  1. #1
    Lounger
    Join Date
    Jul 2001
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to cut a string! (vba)

    hi
    i have a string
    file="c:datatransaction_log.txt"
    how can i cut this string so i can get output only with text as below using vb:
    transaction_log

    thanks
    gan

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to cut a string! (vba)

    Use :
    file = mid(left("c:datatransaction_log.txt",instrrev("c:d atatransaction_log.txt",".")-1),instrrev("c:datatransaction_log.txt","")+1)
    Francois

  3. #3
    Lounger
    Join Date
    Jul 2001
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to cut a string! (vba)

    thanks alots!! [img]/forums/images/smilies/smile.gif[/img]

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: how to cut a string! (vba)

    Assuming the string is always going to be a file path, another way to do this is to use the FileSystemObject's GetFileName method (which is just a string manipulation function):

    Public Sub StripOutFileName()
    Dim strFileName As String
    'Assumes reference has been set to
    ' MS Scripting Runtime - scrrun.dll
    Dim FSO As FileSystemObject
    Set FSO = New FileSystemObject
    strFileName = FSO.GetFileName("c:datatransaction_log.txt")
    Debug.Print strFileName
    Set FSO = Nothing
    End Sub

    Gary

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Correction...(vba)

    Previous sample doesn't quite do it - I thought GetFileName would return just "transaction_log', but actually it returns "transaction_log.txt".
    The following is wordier, but does return just "transaction_log":

    Public Sub GetStrippedFileName()
    Dim strPath As String
    Dim strFullFileName As String
    Dim strExt As String
    Dim strStrippedFileName As String
    Dim lngExtLen As Long
    'Assumes reference has been set to
    ' MS Scripting Runtime - scrrun.dll
    Dim FSO As FileSystemObject
    Set FSO = New FileSystemObject
    strPath = "c:datatransaction_log.txt"
    strFullFileName = FSO.GetFileName(strPath)
    strExt = FSO.GetExtensionName(strPath)
    lngExtLen = Len(strExt)
    strStrippedFileName = Left(strFullFileName, Len(strFullFileName) - (lngExtLen + 1))
    Debug.Print strStrippedFileName
    Set FSO = Nothing
    End Sub

  6. #6
    Lounger
    Join Date
    Jul 2001
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Correction...(vba)

    hi thanks .. [img]/forums/images/smilies/smile.gif[/img] really appreacite all your help

  7. #7
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Correction...(vba)

    The GetBaseName function returns the file name with no extension.

    i.e. strStrippedFileName=FSO.GetBaseName(strPath)

    Regards,

    Kevin Bell

  8. #8
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Correction...(vba)

    <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> - that is, of course, just a little bit more concise! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

Posting Permissions

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