请问Split的分隔符可以用变量吗?我是一个新手,正在自学着VB,今天遇着一个问题就是在txt文件中以当前日期为分隔符提取当前日期前面的字符,但不知道可不可以,请不吝赐教,感激不尽.
Dim nFile As Integer
Dim strTmp As String
Dim arTmp() As String
Dim nFile As Integer
Dim d As String
Dim dn As String
Dim p As String
Dim Path As String
On Error Resume Next
d = Format(Now, "yyyy-m-d")
dn = Format(Now, "yyyy_mm")
Path = "D:\cm" & dn & ".txt"
p = Path
nFile = FreeFile
Open p For Input As #nFile
Do While Not EOF(nFile)
Line Input #nFile, strTmp
arTmp = Split(strTmp, "d")'分隔符想用上面的变量 d,就是当前日期
Loop
Close #nFile另,txt文件内容如下:
OK,张三,2009-2-6 9:16:55,2009-2-6
OK,李四,2009-2-7 22:47:37,2009-2-7
OK,王五,2009-2-7 23:25:35,2009-2-7
....
....
我希望是提取张三,李四,王五出来.
Dim nFile As Integer
Dim strTmp As String
Dim arTmp() As String
Dim nFile As Integer
Dim d As String
Dim dn As String
Dim p As String
Dim Path As String
On Error Resume Next
d = Format(Now, "yyyy-m-d")
dn = Format(Now, "yyyy_mm")
Path = "D:\cm" & dn & ".txt"
p = Path
nFile = FreeFile
Open p For Input As #nFile
Do While Not EOF(nFile)
Line Input #nFile, strTmp
arTmp = Split(strTmp, "d")'分隔符想用上面的变量 d,就是当前日期
Loop
Close #nFile另,txt文件内容如下:
OK,张三,2009-2-6 9:16:55,2009-2-6
OK,李四,2009-2-7 22:47:37,2009-2-7
OK,王五,2009-2-7 23:25:35,2009-2-7
....
....
我希望是提取张三,李四,王五出来.
另arTmp = Split(strTmp, "d")'分隔符想用上面的变量 d,就是当前日期---------这样是找字符d,不是变量d,楼上这样才是变量d
OK,张三,2009-2-6 9:16:55,2009-2-6
OK,李四,2009-2-7 22:47:37,2009-2-7
OK,王五,2009-2-7 23:25:35,2009-2-7
Private Sub Command1_Click()
Dim strA As String
Dim arr() As String
Dim strFile As String
Dim i, s As String
Open "c:\1.txt" For Input As #1
Do While Not (EOF(1))
Line Input #1, strFile
arr = Split(strFile, ",")
Text1.Text = Text1.Text & arr(1) & vbCrLf
Loop
Close #1
End Sub
OK,张三,2009-2-6 9:16:55,2009-2-6
OK,李四,2009-2-7 22:47:37,2009-2-7
OK,王五,2009-2-7 23:25:35,2009-2-7
....
....
Private Sub Command1_Click()
Dim strA As String
Dim arr() As String
Dim strFile As String
Dim Cons As String
Text1.Text = ""
Cons = Text2.Text
Open "c:\1.txt" For Input As #1
Do While Not (EOF(1))
Line Input #1, strFile
arr = Split(strFile, ",")
If Trim(Cons) = Trim(arr(3)) Then
Text1.Text = Text1.Text & arr(1) & vbCrLf
Else
End If
Loop
Close #1
End Sub
Dim strLine As String
Dim strArr() As String
Dim strToday As StringstrToday = Format(Date, "yyyy-m-d")
List1.Clear
Open "c:\1.txt" For Input As #1
Do Until EOF(1)
Line Input #1, strLine
If InStr(strLine, strToday)
strArr = Split(strLine, ",")
If Ubound(strArr) Then List1.AddItem strArr(1)
End If
Loop
Close #1
End Sub
If InStr(strLine, strToday),后面写漏了一个Then,估计各位大哥都是就这样写出来的,并不需要像我这样上机测试,这点在下十分佩服,也是我努力的方向,再次谢谢大家了!