'如果 StrChkAndSplit = Ture 則將SplitTxt$() 字串陣列填入 List1 清單內
''關鍵字設 "MJ",分割符號設 ","
'SplitTxt$() 一定要上方設定 ReDim SplitTxt$(0) 放分割後字串資料
If StrChkAndSplit(Text1.Text, "MJ", ",", SplitTxt$()) Then
For i = 0 To UBound(SplitTxt$)
List1.AddItem SplitTxt$(i)
Next
End If
End Sub
' StrChkAndSplit = True 代表有找到關鍵字
' = False 代表有找到沒有關鍵字
' Txt 待分割的字串
' L 左方開頭關鍵字
' Dot 分割符號
' SplitTxt() 存放 Dot 分割 Txt 的字串陣列
Function StrChkAndSplit(Txt As String, L As String, Dot As String, SplitTxt() As String) As Integer
Dim tlen As Long, t As String
tlen = Len(L$) '取得關鍵字的字串長度
t = LTrim(Txt) '將待分割的字串前方的空白去除
If Left(UCase(t), tlen) = UCase$(L$) Then '確認有找到關鍵字
SplitTxt$ = Split(Mid$(t, tlen + 1), Dot$) '取得要分割的字串
StrChkAndSplit = True
Else
StrChkAndSplit = False '代表左方開頭沒有找到關鍵字
End If
End Function