vb中关于GetPrivateProfileSection取值
[appversion]host=192.KEY=....我现在只想要取出[appversion]这一节点下所有的值,该怎么写,...
[appversion]
host=192.
KEY=....
我现在只想要取出[appversion]这一节点下所有的值,该怎么写, 展开
host=192.
KEY=....
我现在只想要取出[appversion]这一节点下所有的值,该怎么写, 展开
1个回答
展开全部
Option Explicit
Private Type INI
KeyName As String '保存键名
Key As String '保存健值
End Type
Private Const MaxSTRLen = 32700
Private INIList() As INI
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 Sub Form_Load()
Dim TempSTR As String
Dim STRS1() As String
Dim I As Long
Dim J As Long
Me.AutoRedraw = True
ReDim INIList(0)
TempSTR = String(MaxSTRLen, vbNullChar)
I = GetPrivateProfileSection("appversion", TempSTR, MaxSTRLen, "C:\1.INI")
If I > 0 Then
J = InStrRev(TempSTR, vbNullChar, I)
If J Then I = J
TempSTR = Left(TempSTR, I - 1)
STRS1 = Split(TempSTR, vbNullChar)
J = 0
For I = 0 To UBound(STRS1)
If InStr(STRS1(I), "=") Then '忽略没有键名的行
ReDim Preserve INIList(J)
INIList(J).KeyName = Trim(Left(STRS1(I), InStr(STRS1(I), "=") - 1))
INIList(J).Key = Trim(Mid(STRS1(I), InStr(STRS1(I), "=") + 1, Len(STRS1(I))))
J = J + 1
End If
Next
For I = 0 To UBound(INIList)
Print INIList(I).Key '输出"[appversion]"下所有的值
Next
End If
End Sub
Private Type INI
KeyName As String '保存键名
Key As String '保存健值
End Type
Private Const MaxSTRLen = 32700
Private INIList() As INI
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 Sub Form_Load()
Dim TempSTR As String
Dim STRS1() As String
Dim I As Long
Dim J As Long
Me.AutoRedraw = True
ReDim INIList(0)
TempSTR = String(MaxSTRLen, vbNullChar)
I = GetPrivateProfileSection("appversion", TempSTR, MaxSTRLen, "C:\1.INI")
If I > 0 Then
J = InStrRev(TempSTR, vbNullChar, I)
If J Then I = J
TempSTR = Left(TempSTR, I - 1)
STRS1 = Split(TempSTR, vbNullChar)
J = 0
For I = 0 To UBound(STRS1)
If InStr(STRS1(I), "=") Then '忽略没有键名的行
ReDim Preserve INIList(J)
INIList(J).KeyName = Trim(Left(STRS1(I), InStr(STRS1(I), "=") - 1))
INIList(J).Key = Trim(Mid(STRS1(I), InStr(STRS1(I), "=") + 1, Len(STRS1(I))))
J = J + 1
End If
Next
For I = 0 To UBound(INIList)
Print INIList(I).Key '输出"[appversion]"下所有的值
Next
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询