VB读写配置文件
要解释的,谢谢!
要解释的,谢谢!
答案:WritePrivateProfileString是写Ini文件的,与注册表无关
这是API函数,使用前必须在公共部分定义,可以建公共模块,也可以在窗体最上面写.
代码:
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 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
然后GetPrivateProfileString WritePrivateProfileString 这两个函数就可以用了.
读取和写入代码如下
Private Sub SetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal ValStr As String)
Dim res%
res% = WritePrivateProfileString(SectionName, KeyWord, ValStr, "C:\123.ini")
End Sub
Private Function GetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal DefString As String) As String
Dim llLen As Long
Dim ResultString As String
ResultString = Space(100)
llLen = GetPrivateProfileString(SectionName, KeyWord, DefString, ResultString, 100, "C:\123.ini")
GetIniS = Mid(ResultString, 1, llLen)
End Function
上一个:VB数值排序问题
下一个:关于VB的sendmessage问题