退出程序时,在Form_Unload事件中将选项写入一个文件:
Open "opt.txt" For OutPut As #1
If Option1.Value=True Then
Print #1, 1
Else
Print #1, 0
End If
Close #1
在Form_Load事件中打开该文件,读取其中的值,如果是1,就将Option1的Value设置为True,否则将Option2的值设为Ture
Dim a
On Error Goto err1 '如果文件不存在会出错
Open "opt.txt" For InPut As #1
Line Input #1,a
If a=1 Then
Option1.Value=True
Else
Option2.Value=True
End If
Close #1
err1:
如果有多个Option控件,那么就要用到Case了
这段代码能在程序关闭时保存option1设置,程序重新运行后读取上次保存的内容,达到你的要求
Private Sub Form_Load()
If Exist("d:\1.txt") Then
Open "d:\1.txt" For Input As #1
Input #1, a
Option1.Value = a
Close (1)
Else
Open "d:\1.txt" For Output As #1
Close (1)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim a As String
a = Option1.Value
Open "d:\1.txt" For Output As #1
Write #1, a
Close (1)
End Sub
Private Function Exist(ByVal Path As String) As Boolean
On Error GoTo 1:
GetAttr Path
Exist = True
1:
End Function
在窗体的LOAD事件中设置要选择的单选按钮的值为TRUE就是了:
opt1.value=true