Private Sub mnuStart_Click() '菜单的事件 if Option1.Value=true then SaveSetting app.exename,"SetValue", "OP1","1","1" else SaveSetting app.exename,"SetValue", "OP1","0","1" endif
if Option2.Value=true then SaveSetting app.exename,"SetValue", "OP2","1","1" else SaveSetting app.exename,"SetValue", "OP2","0","1" endif ...
End SubPrivate Sub Form_Load() if getSetting(app.exename,","SetValue", "OP1","1")="1" then Option1.Value=true else Option1.Value=false endif if getSetting(app.exename,","SetValue", "OP2","1")="1" then Option2.Value=true else Option2.Value=false endif ...
End Sub
以下是读取一个文件的操作: '要求程序目录下有个Config.txt文本文件,且已经有两行。 '比如:Config.txt内容如下: 'aaaaaaaa 'bbbbbbbb 那么读出的strA="aaaaaaaa",strB="bbbbbbbb".程序里就可以根据配置进行相应处理了 Private Sub Command1_Click() '写入文本数据,新建或覆盖 Dim filenum As Integer, strA As String filenum = FreeFile Open App.Path & "\Config.txt" For Output As filenum strA = "写入的第一行" strB="1999-1-1" Write #filenum, strA Write #filenum, strB Close (filenum) '关闭文件; End SubPrivate Sub Command2_Click() '读取文件数据 Dim filenum As Integer, strA As String filenum = FreeFile Open App.Path & "\Config.txt" For Input As filenum Input #filenum, strA '读取第一行配置给变量strA; Input #filenum, strB MsgBox strA & vbCrLf & strB Close (filenum) '关闭文件;End Sub
Option1.Value = False '没选中
Option1.Value = True '选中
Call mnuStart_Click
End Sub
Private Sub mnuStart_Click() '菜单的事件
Option1.Value = True
....End Sub
比如FlashGet里的“工具”菜单里就有个选项叫“存为默认下载设置”,我也想把我的菜单也加入这个功能,一按菜单里的“存为默认”,下次打开的时候就不用再设置了。
用getsetting 和 savesetting函数
这样不对吧?????
语法 SaveSetting appname, section, key, setting
参数 appname:字符串表达式,包含应用程序或工程的名称,是标准位置下的一个子键。
section:字符串表达式,包含区域名称,是 appname 下的一个子键。
key:字符串表达式,标准位置\appname\section子键的键名(Value Name)。
setting:字符串表达式,包含 key 的设置值。 2.GetSetting 从 Windows 注册表中的应用程序项目返回注册表项设置值
语法 GetSetting appname, section, key[, default]
参数 appname:字符串表达式,包含应用程序或工程的名称。
section:字符串表达式,包含区域名称,要求该区域有注册表项设置。
key:字符串表达式,返回注册表项设置的名称。
default:可选。表达式,如果注册表项设置中没有设置值,则返回缺省值。如果省略,则 default 取值为长度为零的字符串 ("")。
说明 如果 GetSetting 无参数,则 GetSetting 返回 default 的值
if Option1.Value=true then
SaveSetting app.exename,"SetValue", "OP1","1","1"
else
SaveSetting app.exename,"SetValue", "OP1","0","1"
endif
if Option2.Value=true then
SaveSetting app.exename,"SetValue", "OP2","1","1"
else
SaveSetting app.exename,"SetValue", "OP2","0","1"
endif
...
End SubPrivate Sub Form_Load()
if getSetting(app.exename,","SetValue", "OP1","1")="1" then
Option1.Value=true
else
Option1.Value=false
endif
if getSetting(app.exename,","SetValue", "OP2","1")="1" then
Option2.Value=true
else
Option2.Value=false
endif
...
End Sub
'要求程序目录下有个Config.txt文本文件,且已经有两行。
'比如:Config.txt内容如下:
'aaaaaaaa
'bbbbbbbb
那么读出的strA="aaaaaaaa",strB="bbbbbbbb".程序里就可以根据配置进行相应处理了
Private Sub Command1_Click() '写入文本数据,新建或覆盖
Dim filenum As Integer, strA As String
filenum = FreeFile
Open App.Path & "\Config.txt" For Output As filenum
strA = "写入的第一行"
strB="1999-1-1"
Write #filenum, strA
Write #filenum, strB
Close (filenum) '关闭文件;
End SubPrivate Sub Command2_Click() '读取文件数据
Dim filenum As Integer, strA As String
filenum = FreeFile
Open App.Path & "\Config.txt" For Input As filenum
Input #filenum, strA '读取第一行配置给变量strA;
Input #filenum, strB
MsgBox strA & vbCrLf & strB
Close (filenum) '关闭文件;End Sub