MACRO LIBRARY

Lesson 1.6 - string functions

Free public access. No account or subscription required.

Files

Lesson 1.6 - string functions

Code

'Assumptions:
'Main directory is always C:\Engineering
'Extension is always 6 characters long
    
Const strFilePath As String = "C:\Engineering\Door\493452327.sldprt"
    
Dim strExtension As String
Dim strPartNo As String
Dim strComponent As String
    
Dim intLastSlashLoc As Integer
Dim intLength As Integer
    
Sub main()
    'get the extension
    strExtension = Right(strFilePath, 6)
    
    'get the component
    intLastSlashLoc = InStrRev(strFilePath, "\")
    strComponent = Mid(strFilePath, 16, intLastSlashLoc - 15 - 1)
    
    'get the part no
    intLength = Len(strFilePath)
    strPartNo = Mid(strFilePath, intLastSlashLoc + 1, intLength - intLastSlashLoc - 7)
    
    'display the results
    MsgBox "Extension: " & strExtension & vbCrLf & _
           "Part number: " & strPartNo & vbCrLf & _
           "Component: " & strComponent
End Sub