?? stringhandler.bas
字號:
Attribute VB_Name = "modStringHandler"
Option Explicit
'
' General purpose string handling functions.
'
Sub AddStrList(List() As String, S As String)
' Add the string "S" to the array "List"
ReDim Preserve List(LBound(List) To UBound(List) + 1)
List(UBound(List)) = S
End Sub
Sub AddStrListUnique(List() As String, S As String)
' Add string "S" to list "List" only
' if it isn't there already.
If GetElementNum(List(), S) = -32767 Then
Call AddStrList(List(), S)
End If
End Sub
Function AfterFirstToken(StrIn As String, Delim As String) As String
' Returns the portion of "String" after the
' first occurrence of "Delim".
Dim After As String
Dim Begin As Long
StrIn = Trim(StrIn)
Begin = InStr(1, StrIn, Delim)
If (Begin = 0) Or Begin = Len(StrIn) Then
After = ""
Else
After = (Trim(right$(StrIn, Len(StrIn) - Begin)))
End If
AfterFirstToken = After
End Function
Function GetArgs(InString As String) As String
' Given a command string, pull off the first
' word and return just the arguments.
Dim ArgStr As String
Dim Begin As String
InString = Trim(InString)
Begin = InStr(1, InString, " ")
If (Begin = 0) Or Begin = Len(InString) Then
ArgStr = ""
Else
ArgStr = (Trim(right$(InString, Len(InString) - Begin)))
End If
GetArgs = ArgStr
End Function
Function GetElementNum(List() As String, S As String) As Long
' find out where or if string "S" occurs in
' array "List", and return the index number.
Dim Place As Long
Dim i As Long
Place = -32767
For i = LBound(List) To UBound(List)
If List(i) = S Then
Place = i
Exit For
End If
Next i
GetElementNum = Place
End Function
Function GetFirstToken(StrIn As String, Delim As String) As String
' Gets the portion of String "S", up to the
' first occurrance of delimiter "D"
' Returns String token "T"
Dim Split As Long
Dim Tok As String
StrIn = Trim$(StrIn)
Split = InStr(1, StrIn, Delim)
If (Split <= 0) Then
' No delimiter in the string. Return the whole thing.
Tok = StrIn
Else
' Get everything up to the first delimiter.
Tok = (Trim$(left$(StrIn, Split - 1)))
End If
GetFirstToken = Tok
End Function
Function GetFirstWord(InString As String) As String
' Given a command string, return just the first
' word.
Dim CmdStr As String
Dim CmdEnd As String
InString = Trim$(InString)
CmdEnd = InStr(1, InString, " ") - 1
If (CmdEnd <= 0) Then
' No spaces in the string.
CmdStr = InString
Else
' Get everything up to the first space.
CmdStr = (Trim$(left$(InString, CmdEnd)))
End If
GetFirstWord = CmdStr
End Function
Sub RemoveStrList(List() As String, S As String)
' Remove the entry "S" from an array of strings.
Dim i As Long
Dim Found As Long
' Run through the list. Once S is found,
' shuffle all remaining elements up one position.
Found = False
For i = 1 To UBound(List)
If (List(i) = S) Or Found Then
Found = True
If i < UBound(List) Then
List(i) = List(i + 1)
End If
End If
Next i
' Free memory used by S.
If Found Then
ReDim Preserve List(UBound(List) - 1)
End If
End Sub
Sub SelListByName(ctrl As Control, fdrName As String)
' Given a list box control and a string,
' set the matching entry in the control selected.
If (ctrl.listCount > 0) Then
Dim i As Long
For i = 0 To ctrl.listCount - 1
If ctrl.List(i) = fdrName Then
ctrl.ListIndex = i
End If
Next i
End If
End Sub
Function StrInCtrl(ctrl As Control, S As String) As Long
' Given a list control, determine if S is an element
' of the list, and return its index number if it is.
' If not, return -1
Dim Ind As Long
Dim i As Long
Ind = -1
If (ctrl.listCount > 0) Then
For i = 0 To ctrl.listCount - 1
If ctrl.List(i) = S Then
Ind = i
Exit For
End If
Next i
End If
StrInCtrl = Ind
End Function
Sub Tokenize(List() As String, S As String, Delim As String)
' Tears each token out of String "S", delimited
' by "delim", and adds it to array "List"
Dim StrIn As String
StrIn = S
Do Until StrIn = ""
Call AddStrList(List(), GetFirstToken(StrIn, Delim))
StrIn = AfterFirstToken(StrIn, Delim)
Loop
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -