code111a.txt

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

TXT
46
字号
Public Sub Find_String(ByVal String1 As String, ByVal String2 As String, ByRef StartPos, ByRef strLength, ByRef Endpos)
  Dim I As Integer

  strLength = Len(String2)
  For I = 1 To (Len(String1) - strLength - 1)
    If Mid(String1, I, strLength) = String2 Then
      StartPos = I
      Endpos = strStart + strLength - 1
      Exit Sub
    End If
  Next
  StartPos = 0
End Sub
Public Sub Main()
  Dim strStart As Integer, strLength As Integer, Endpos As Integer
  
  StartPos = 0
  Endpos = 0
  strLength = 0

  Debug.Print "Looking for Abc in AbcDef"
  Find_String "AbcDef", "Abc", StartPos, Length, Endpos
  If StartPos > 0 Then
    Debug.Print "Start, Length, End:", StartPos, strLength, Endpos
  Else
    Debug.Print "Not found."
  End If

  Debug.Print "Looking for Abc in abcDef"
  Find_String "abcDef", "Abc", StartPos, strLength, Endpos
  If StartPos > 0 Then
    Debug.Print "Start, Length, End:", StartPos, strLength, Endpos
  Else
    Debug.Print "Not found."
  End If

  Debug.Print "Looking for Abc in AbcAbc"
  Find_String "AbcAbc", "Abc", StartPos, strLength, Endpos
  If StartPos > 0 Then
    Debug.Print "Start, Length, End:", StartPos, strLength, Endpos
  Else
    Debug.Print "Not found."
  End If

End Sub

⌨️ 快捷键说明

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