有一个TXT文件,内容有两种情况
第一种情况:tm.txt内容
m=A
内容只有一行,其中A也可能是其它的任何字母(只有一个字母)
第二种情况:tm.txt内容
m=
只有m=两个符号
要求:
用VB程序代码判断tm.txt内容,当为第一种情况时,弹出确定对话框,内容“输出字母”
当为第二种情况时,弹出确定对话框,内容“输出为空”!谢谢,请给出具体代码!
如何用VB判断读取TXT文本内容?
答案:4 悬赏:70
解决时间 2021-12-28 22:21
- 提问者网友:我稀罕你
- 2021-12-28 05:41
最佳答案
- 二级知识专家网友:星星坠落
- 2021-12-28 06:34
dim s as string
open "<路径>\tm.txt" for input as #1
input #1,s
if right(s,1)="=" then
msgbox "输出为空"
else
msgbox right(s,1)
end if
close #1
open "<路径>\tm.txt" for input as #1
input #1,s
if right(s,1)="=" then
msgbox "输出为空"
else
msgbox right(s,1)
end if
close #1
全部回答
- 1楼网友:悲观垃圾
- 2021-12-28 07:37
On Error Resume Next
Dim another As String
Open "c:\tm.txt" For Input As #1
Do While Not EOF(1)
Input #1, another
Close #1
if mid(another,3,1) is not null then
a=mid(another,3,1)
msgbox a
else
msgbox "输出为空"
end if
- 2楼网友:专属的偏见
- 2021-12-28 07:05
1、对于文件的操作vb提供了open语句、print #语句、input #语句等语句来处理文件。
2、读取多行文本,可以使用line input #语句,一行行读取,再连接在一起,这种方法对大一点txt文件效率不高。
3、下面提供一个高效率、一次性读入所有文本的vb6示例:
private sub command1_click()
dim r
open "d:\readme.txt" for binary as #1
r = strconv(inputb(lof(1), 1), vbunicode)
close #1
debug.print r
end sub
- 3楼网友:伤口狠精致
- 2021-12-28 06:41
private sub command1_click()
open "c:\tm.txt" for input as #1
line input #1,s
if right(s,1)="=" then
msgbox "输出为空"
else
msgbox right(s,1)
end if
close #1
end sub
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯