code285a.txt

来自「VB大全(精华版)源代码」· 文本 代码 · 共 37 行

TXT
37
字号
Public Sub SplitPath(ByVal Path As String, ByRef Drive As String, _
    ByRef subdirs As String, ByRef Filename As String, _
    ByRef Suffix As String)
  Dim LastBracket As Long
  Const Backslash = "\"

  Drive = Left(Path, 3)
  LastBracket = LastCharacter(Path, Backslash)
  subdirs = Mid(Path, 4, LastBracket - 4)
  Filename = Mid(Path, LastBracket, Len(Path) - LastBracket - 3)
  Suffix = Right(Path, 4)
End Sub

Public Function LastCharacter(ByVal SearchString As String, _
    ByVal SearchFor As String) As Long
  Dim Current_Pos As Integer, Next_Pos As Integer

  Next_Pos = 0
  Do
    Current_Pos = Next_Pos
    Next_Pos = InStr(Current_Pos + 1, SearchString, SearchFor)
  Loop Until Next_Pos = 0
  LastCharacter = Current_Pos + 1
End Function

Public Sub Main()
  Dim Dir$, subdirs$, File$, Ending As String
  Const PathName = "c:\windows\system\SampleFile.ini"

  SplitPath PathName, Dir, subdirs, File, Ending
  Debug.Print PathName
  Debug.Print Dir
  Debug.Print subdirs
  Debug.Print File
  Debug.Print Ending
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?