Attribute VB_Name = "modPublic" Option Explicit ' Public object variable to hold CustomVBProjects collection. Public CustomVBProjects As ExportToCodeLib.CustomVBProjects ' Public constants. Public Const TBL_CODE As String = "tblCode" Public Const APP_NAME As String = "ExportToCodeLib" Public Const APP_SECTION As String = "DbLocation" Public Const APP_KEY As String = "DefaultCodeDb" ' Enumeration constants used with ParsePath procedure. Public Enum opgParsePath FILE_ONLY PATH_ONLY DRIVE_ONLY FILEEXT_ONLY FILE_ONLY_NO_EXT End Enum ' Enumeration constants for items that this add-in treats ' as exportable entities. Public Enum opgComponentType INDIVIDUAL_PROC = 0 STANDARD_MODULE = 1 CLASS_MODULE = 2 VB_PROJECT = 3 End Enum ' Enumeration constants mapping to the code types available ' in the Code Librarian add-in. Public Enum opgCodeLibCodeType CODE_SNIPPET = 0 CODE_FUNCTION = 1 CODE_MODULE = 2 CODE_CLASS_MODULE = 3 End Enum ' Enumeration constants specifying pages of this wizard. Public Enum opgWizard PAGE_1 PAGE_2 PAGE_3 End Enum Function ParseProcType(strProcText As String) As opgCodeLibCodeType Dim strFirstLine As String Dim astrFirstLine() As String ' Determine type of procedure. ' VB constant doesn't distinguish between Sub and ' Function procedures, so we parse the first line ' ourselves here. strFirstLine = Left(strProcText, _ InStr(strProcText, vbCrLf)) ' Split first line into array of words. astrFirstLine() = Split(strFirstLine, , , vbTextCompare) ' First or second word will contain function type. If astrFirstLine(0) = "Sub" Or astrFirstLine(1) = "Sub" Then ParseProcType = opgCodeLibCodeType.CODE_SNIPPET ElseIf astrFirstLine(0) = "Function" Or astrFirstLine(1) = _ "Function" Then ParseProcType = opgCodeLibCodeType.CODE_FUNCTION Else ParseProcType = -1 End If End Function Function ParsePath(strPath As String, _ lngPart As opgParsePath) As String ' This procedure takes a file path and returns ' either the path portion or the file portion, ' depending on which constant was passed in. Dim lngPos As Long Dim strPart As String Dim blnIncludesFile As Boolean ' Check that this is a file path. ' Find the last path separator. lngPos = InStrRev(strPath, "\") ' Determine whether portion of string after last backslash ' contains a period. blnIncludesFile = InStrRev(strPath, ".") > lngPos If lngPos > 0 Then Select Case lngPart ' Return file name. Case opgParsePath.FILE_ONLY If blnIncludesFile Then strPart = Right$(strPath, Len(strPath) - lngPos) Else strPart = "" End If ' Return path. Case opgParsePath.PATH_ONLY If blnIncludesFile Then strPart = Left$(strPath, lngPos) Else strPart = strPath End If ' Return drive. Case opgParsePath.DRIVE_ONLY strPart = Left$(strPath, 3) ' Return file extension. Case opgParsePath.FILEEXT_ONLY If blnIncludesFile Then ' Take three characters after period. strPart = Mid(strPath, InStrRev(strPath, ".") + 1, 3) Else strPart = "" End If Case opgParsePath.FILE_ONLY_NO_EXT If blnIncludesFile Then strPart = Right$(strPath, Len(strPath) - lngPos) strPart = Left$(strPart, Len(strPart) - 4) Else strPart = "" End If Case Else strPart = "" End Select End If ParsePath = strPart ParsePath_End: Exit Function End Function Function TrimSpace(strInput As String) As String ' This procedure trims extra space from any part of ' a string. Dim astrInput() As String Dim astrText() As String Dim strElement As String Dim lngCount As Long Dim lngIncr As Long ' Split passed-in string. astrInput = Split(strInput) ' Resize second array to be same size. ReDim astrText(UBound(astrInput)) ' Initialize counter variable for second array. lngIncr = LBound(astrInput) ' Loop through split array, looking for ' non-zero-length strings. For lngCount = LBound(astrInput) To UBound(astrInput) strElement = astrInput(lngCount) If Len(strElement) > 0 Then ' Store in second array. astrText(lngIncr) = strElement lngIncr = lngIncr + 1 End If Next ' Resize new array. If lngIncr > 0 Then ReDim Preserve astrText(LBound(astrText) To lngIncr - 1) End If ' Join new array to return string. TrimSpace = Join(astrText) End Function