怎样将VB中一些变量设置至INI或写进注册表,方便改程序的情况下可以重新设置其参数

来源:百度知道 编辑:UC知道 时间:2024/05/13 14:05:08
比如
picPath = "F:\back\"
中""部分
其实主要我想要的是读取其中的值,也就是说不该程序,可以改变程序参数,如果没有该文件就创建。输出默认参数,如果有则读取该文件中参数。

自己总结自用的函数,个人感觉很好用,望采纳!

Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Public Static Function GPPFS(AppName As String, KeyName As String, Optional DefaultValue As String, Optional ByVal lpFileName, Optional Buffer As Long = 1024) As String
Dim f As String
If lpFileName <> "" Then f = lpFileName
GPPFS = String(Buffer, 0)
GetPrivateProfileString AppName, KeyName, DefaultValue, GPPFS, Buffer, f
GPPFS = Left(GPPFS, InStr(GPPFS, vbNullChar) - 1)
End Function

Private Sub Command1_Click()
If GetSetting("MyApp", "Startup", "picPath") = "" Then
picPath = "F:\back\"
SaveSetting "MyApp", "Star