VB6.0 读取 INI中的多个数据,怎么写代码
发布网友
发布时间:2022-05-04 01:30
我来回答
共2个回答
热心网友
时间:2022-06-20 11:43
'使用API函数
'ini文件在有回车换行符会出错,经过测试,汉字要小于86字节,英言文要小于143字节才能返回列表框。
Option Explicit
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, 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
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 GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Private Function GetFormInfoString(ByVal lpKeyName As String, ByVal nDefault As String)
Dim ReturnedString1 As String * 32
Dim i As Integer, Temp As Integer
Dim strIniFile As String
strIniFile = "D:\1.ini"
Temp = GetPrivateProfileString("FormInfo", lpKeyName, "", ReturnedString1, 32, strIniFile)
i = InStr(ReturnedString1, vbNullChar & vbNullChar)
GetFormInfoString = VBA.Mid(ReturnedString1, 1, i - 1)
If Temp = 0 Then
GetFormInfoString = nDefault
Call WritePrivateProfileString("FormInfo", lpKeyName, nDefault, strIniFile)
End If
ReturnedString1 = ""
End Function
Private Function GetFormInfoInt(ByVal lpKeyName As String, ByVal nDefault As Long)
Dim i As Integer, Temp As Integer
strIniFile = "D:\1.ini"
GetFormInfoInt = GetPrivateProfileInt("FormInfo", lpKeyName, -1, strIniFile)
If GetFormInfoInt < 0 Then
Call WritePrivateProfileString("FormInfo", lpKeyName, CStr(nDefault), strIniFile)
GetFormInfoInt = nDefault
End If
End Function
热心网友
时间:2022-06-20 11:44
先用fso打开文件,然后用readline 或 skipline 跳到你要写的那一行写入就行了