代运营公司上班怎么样:vb open 问题!在线等待!!

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/10 13:49:57
比如我要把text1.text的内容写入c:\p.txt里面,给个例子好不,最好是详细点,我能读出来,读出来是这样写的
Private Sub Command1_Click()
Dim a As String
Open "c:\p.txt" For Input As #1
Input #1, p
Close #1
If p = Val(Text1.Text) Then
Command2.Enabled = True
Command3.Enabled = True
Label1.Caption = "密码正确"
Else
Command2.Enabled = False
Command3.Enabled = False
Label1.Caption = "密码错误"
End If
End Sub
Private Sub Command1_Click()
Dim a As String
Open "c:\p.txt" For Input As #1
Input #1, a
If a = Val(Text1.Text) Then
Open "c:\p.txt" For Input As #2
Print #2, a
Close #1
Close #2
MsgBox "密码修改成功"
Else
Label1.Caption = "旧密码错误"
End If
End Sub
我是这样写的,我的意思是编个密码修改,
你们的意思我明白,
读就是open "c:\p.txt" for input as #1
input #1,a
写就是open "c\p.txt" for output as #1
output #1,a
是吧,但是我这样就写就不行
我试过open "c\p.txt" for output as #1
print #1,a
运行正常,但是写进入的东西没什么变化,就多了一个空格,我给它的命令不是一个空格,是一些数字,我要的效果是把以前的覆盖,
Private Sub Command1_Click()
Dim a As String
Open "c:\p.txt" For Input As #1
Input #1, a
If a = Val(Text1.Text) Then
Print #1, a
Close #1
MsgBox "密码修改成功"
Else
Label1.Caption = "旧密码错误"
End If
End Sub

把程序外面的文本信息("C:\p.txt")读取到程序中,使用Input.
把程序里信息(Text1.Text)写到程序外面的文档中,使用Output.

“问题补充:写进去我是用
Dim a As String
Open "c:\p.txt" For Output As #1
Input #1, a
Close #1
但是不行???”
-----------这是你的问题补充。

你既然用For OutPut,意思是向文档写东西,但又为什么下面用Input #1, a呢?
应该改成Output #1 ,a 或者Print #1,a

Dim a As String
Open "c:\p.txt" For Output As #1
Input #1, a-????????????????????
Close #1

已经说了是Output,为什么还要使用Input
既然是读取文本文件,解决很简单

输出时为
Open Pathname for output as #1'空闲的文件号
print #1,String'String为你要写入的文字
close #1'必要,否则下次会出错

读取时就像你刚才写的一样,不过更一般的,我们使用Line Input逐行读入
open pathname for input as #1
line input #1,String
close #1