VB定位TXT文件某行,设行为i,如果第10行第一个字符为A时,Msgbos"哈",否则不执行任何操作!
请问我该如何书写?OpenFile1.Path&"\"&File1.FileNameForInputAs#1If?then?MsgBox"哈",vbOKOnly,"提示"...
请问我该如何书写?
Open File1.Path & "\" & File1.FileName For Input As #1
If ? then
?
MsgBox "哈", vbOKOnly, "提示"
End If
Close #1 展开
Open File1.Path & "\" & File1.FileName For Input As #1
If ? then
?
MsgBox "哈", vbOKOnly, "提示"
End If
Close #1 展开
3个回答
展开全部
看附件:
Private Sub Command1_Click()
Dim f1, L, BY, r
n = FreeFile
f1 = App.Path & "\1.txt"
Open f1 For Input As n
L = LOF(n)
Do While Not EOF(n)
Line Input #n, BY
r = r + 1
If r = 10 And Left(BY, 1) = "A" Then
MsgBox "哈"
Exit Sub
Else
Print BY
End If
Loop
Close #1
End Sub
展开全部
'''读取文本文件内的指定行.请不要设置太多.影响速度
'''FilePath 文件路径
'''LineValue 可选参数 返回指定行数
Function ReadFileLine(FilePath As String, Optional LineValue As Integer = 10) As String
If Len(Dir(FilePath)) = 0 Then Exit Function
Dim t As String, i As Integer, f As Integer
f = FreeFile
Open FilePath For Input As #f
Do While Not EOF(1)
Line Input #f, t
i = i + 1
If i = LineValue Then ReadFileLine = t: Exit Do
Loop
Close #f
End Function
上面的函数调用一下就可以返回指定行数的内容
按你的要求
dim s as string
s= ReadFileLine(File1.Path & "\" & File1.FileName,10)
if left(s,1)="A" then msgbox"哈", vbOKOnly, "提示"
'''''''''''''也可以写在一起
if left(ReadFileLine(File1.Path & "\" & File1.FileName,10),1)="A" then msgbox"哈", vbOKOnly, "提示"
就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很容易啊:
Private Sub Command1_Click()
Open "C:\a.txt" For Input Access Read As #1 'c:\a.txt 你自己改File1.Path & "\" & File1.FileName
Do While Not EOF(1)
Line Input #1, strTxt
s = s & strTxt & vbCrLf
Loop
Close #1
a = Split(s, vbCrLf)
If UBound(a) >= 10 Then
If Mid(a(9), 1, 1) = "A" Then MsgBox "哈", vbOKOnly, "提示"
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询