VB 求如何保存设置和读取设置
[]check2 [text2]
这样的
求写个源码保存check的状态和text1的内容,然后打开读取 展开
VB可使用Write # 语句语句保存文本框的数据或其它控件运行参数到文本顺序文件。再次运行程序上用Input # 语句从原保存的文本文件加载数据到原文本框或加载其它控件设置状态。
Write # 语句,将数据写入顺序文件。
Input # 语句,从已打开的顺序文件中读出数据并将数据指定给变量。
通常用 Input # 从文件读出 Write # 写入的数据。
Open 语句,能够对文件输入/输出 (I/O)。
保存数据代码:
Private Sub cmdExit_Click()
TxtgbwdS_sj = TxtgbwdS
Txtgbwdx_sj = Txtgbwdx
TxtZpwds_sj = TxtZpwds
TxtZpwdx_sj = TxtZpwdx
Open App.Path & "\data\data.txt" For Output As #1
Write #1, TxtgbwdS_sj, Txtgbwdx_sj, TxtZpwds_sj, TxtZpwdx_sj
Close #1
End Sub
加载代码
Private Sub Form_Load()
On Error GoTo uerror
Open App.Path & "\data\data.txt" For Input As #1
Input #1, TxtgbwdS_sj, Txtgbwdx_sj, TxtZpwds_sj, TxtZpwdx_sj
Close #1
TxtgbwdS = TxtgbwdS_sj
Txtgbwdx = Txtgbwdx_sj
TxtZpwds = TxtZpwds_sj
TxtZpwdx = TxtZpwdx_sj
uerror:
End Sub
If Dir("c:\123.dat") <> "" Then Kill "c:\123.dat"
Open "c:\123.dat" For Binary As #1
Put #1, , Check1.Value
Put #1, , Text1.Text
Close #1
MsgBox "已保存!"
End Sub
Private Sub Form_Load() '读取
Dim i As Integer
If Dir("c:\123.dat") <> "" Then
Open "c:\123.dat" For Binary As #1
Get #1, , i
Check1.Value = i
Text1.Text = StrConv(InputB(LOF(1), #1), vbUnicode)
Close #1
End If
End Sub
2012-03-20