我的代码是这样的,看看为什么不对啊
Private Sub Command1_Click()
If Text1.Text = "123" Then
MsgBox "y", 0
Else
MsgBox "n", 0
End If
If Check1.Value = 1 Then
Open "c:\abc.txt" For Output As #1
Print #1, Text1.Text
Close #1
Else
If Dir("c:\abc.txt", vbDirectory) <> "" Then
Kill "c:\abc.txt"
End If
End If
End Sub
Private Sub Form_Load()
If Dir("c:\abc.txt", vbDirectory) <> "" Then
Check1.Value = 1
Dim sA As String * 65400 '声明定长String变量
Open "c:\abc.txt" For Binary As #1 '用二进制打开文件
Get #1, , sA '用Get语句从文件中获取字节
Text1 = sA '显示打开的文件
Close #1 '关闭文件
Else
Check1.Value = 0
End If
End Sub
Private Sub Form_Load()
If Dir("c:\abc.txt", vbDirectory) <> "" Then
Check1.Value = 1
Dim sA As String * 65400 '声明定长String变量
Open "c:\abc.txt" For Binary As #1 '用二进制打开文件
Get #1, , sA '用Get语句从文件中获取字节
Text1 = sA '显示打开的文件
Close #1 '关闭文件
Else
Check1.Value = 0
End If
End Sub
问题出在sA上,代码修改如下
Private Sub Form_Load()
If Dir("c:\abc.txt", vbDirectory) <> "" Then
Check1.Value = 1
Dim sA As String * 65400 '声明定长String变量
sA = String(LOF(1), Chr(0))
Open "c:\abc.txt" For Binary As #1 '用二进制打开文件
Get #1, , sA '用Get语句从文件中获取字节
sA = Left(sA, InStr(sA, Chr(0)) - 1) '该sA才是真正的内容
Text1 = sA '显示打开的文件
Close #1 '关闭文件
Else
Check1.Value = 0
End If
End Sub