vb 中ini 读写问题
发布网友
发布时间:2023-07-09 08:05
我来回答
共1个回答
热心网友
时间:2024-03-17 02:19
保存图片的路径,打开程序时从ini文件读取路径,加载一次
'==========================================================================================
' 模块 功能: 读写 ini 文件 ( 或向注册表读写配置 )
'
' 函数属性用法: INIFile: 设置 ini 文件的路径
' GetFile: 读取 ini 文件, strSection 分节, strKey 关键字, strValue 字段值
' WriteFile: 写入 ini 文件, 同上, strDefault 字段默认值
'mouldy 2010-06-08
'============================================================================================
Option Explicit
Private IniPath As String
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private 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 Sub WriteFile(ByVal strSection As String, ByVal strKey As String, ByVal strValue As String)
If strKey = "-" Then
WritePrivateProfileString strSection, 0&, strValue, IniPath
Else
If strValue = "-" Then
WritePrivateProfileString strSection, strKey, 0&, IniPath
Else
WritePrivateProfileString strSection, strKey, strValue, IniPath
End If
End If
End Sub
Public Function GetFile(ByVal strSection As String, ByVal strKey As String, Optional ByVal strDefault As String) As String
Dim strValue As String * 100
GetPrivateProfileString strSection, strKey, strDefault, strValue, Len(strValue), IniPath
GetFile = Left(strValue, InStr(strValue, Chr(0)) - 1)
End Function
'Public Property Let INIFile(ByVal filePath As String)
'
' IniPath = filePath
'End Property
'
'Public Property Get INIFile() As String
'
' INIFile = IniPath
'End Property
'Private Function MakePath(ByVal strDrv As String, ByVal strDir As String) As String
'
' '// Makes an INI file: Guarantees a sub dir
' Do While Right$(strDrv, 1) = "\"
' strDrv = Left$(strDrv, Len(strDrv) - 1)
' Loop
'
' Do While Left$(strDir, 1) = "\"
' strDir = Mid$(strDir, 2)
' Loop
'
' '// Return the path
' MakePath = strDrv & "\" & strDir
'End Function
'
'
'Public Sub CreateIni(strDrv As String, strDir As String)
'
' '// Make a new ini file
' strInI = MakePath(strDrv, strDir)
'End Sub