Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Other Code Examples

Formating a path to always end with a backslash

Formating a path to always end with a backslash The following function is useful for adding the trailing backslash to a path and for combining lots of paths sub paths into a single path. 'Purpose : Ensures a path always finishes with a trailing backslash 'Inputs : sPath The path to complete ' [avPaths] Optional paths to append to sPath 'Outputs : Returns a path with a trailing backslash Function FormatPath(sPath As String, ParamArray avPaths() As Variant) As String Dim vThisPath As Variant FormatPath = sPath If Right$(FormatPath, 1) <> "\" Then 'Add backslash FormatPath = FormatPath & "\" End If 'Append with a sub paths For Each vThisPath In avPaths If Len(vThisPath) Then If Left(vThisPath, 1) = "\" Then FormatPath = FormatPath & Mid$(vThisPath, 2) Else FormatPath = FormatPath & vThisPath End If End If Next If Right$(FormatPath, 1) <> "\" Then 'Add backslash FormatPath = FormatPath & "\" End If End Function