[aaa] Count=3 [1] x=0 y=1 z=2 [2] x=4 y=3 z= [3] x=3 y=2 z=5 '建议写成这样的格式.getiniStr "aaa" ,"Count"for i=1 to count getinistr i ,"X" getinistr i ,"Y" getinistr i ,"Z" next
Option ExplicitPrivate Declare Function GetPrivateProfileSection Lib "KERNEL32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As LongPublic Function GetInfoSection(strSection As String, strIniFile As String) As String() Dim strReturn As String * 32767 Dim strTmp As String Dim nStart As Integer Dim nEnd As Integer Dim i As Integer Dim sArray() As String
strTmp = strReturn i = 1 Do While strTmp <> "" nStart = nEnd + 1 nEnd = InStr(nStart, strReturn, vbNullChar) strTmp = Mid$(strReturn, nStart, nEnd - nStart) If Len(strTmp) > 0 Then ReDim Preserve sArray(1 To i) sArray(i) = strTmp i = i + 1 End If Loop GetInfoSection = sArray
End FunctionPrivate Sub Command1_Click() Dim i As Long Dim A() As String A = GetInfoSection("aaa", "c:\1.ini") 'C:\1.ini 改为你的文件名 For i = 1 To UBound(A) MsgBox A(i) Next End Sub
我上学时写的读写INI文件的模块代码,直接保存成一个.bas文件,然后把里面的变量换成你需要的就可以了。 更多例程http://download.csdn.net/user/mokton Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long 'GetPrivateProfileString(Section , KeyWord , 读取失败的代替值 ,KeyWordValue返回值 , Value值缓冲区大小 , INI路径) Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName As String) As Long 'WritePrivateProfileString(Section , KeyWord ,KeyWordValue ,INI路径)Public IniPath As String Public netName As String Public TimeInterval As String Public sEnableVerb As String Public sDisableVerb As StringPublic Function Loadings() As Boolean On Error GoTo EE IniPath = App.Path + "\Net.ini" netName = GetFromINI("NetConfig", "ConName", IniPath) TimeInterval = GetFromINI("NetConfig", "TimeInterval", IniPath) sEnableVerb = GetFromINI("NetConfig", "Enable", IniPath) sDisableVerb = GetFromINI("NetConfig", "Disable", IniPath) If netName = "" Then GoTo EE Loadings = True Exit Function EE: Loadings = False End FunctionPrivate Function GetFromINI(AppName As String, KeyName As String, FileName As String) As String Dim RetStr As String Dim Result As Long RetStr = String(255, Chr$(0)) Result = GetPrivateProfileString(AppName, ByVal KeyName, "", RetStr, Len(RetStr), FileName) RetStr = TrimNull(RetStr) GetFromINI = RetStr End FunctionPrivate Function TrimNull(Item As String) As String Dim pos As Integer pos = InStr(Item, Chr$(0)) If pos Then Item = Left$(Item, pos - 1) TrimNull = Item End Function
Count=3
[1]
x=0
y=1
z=2
[2]
x=4
y=3
z=
[3]
x=3
y=2
z=5
'建议写成这样的格式.getiniStr "aaa" ,"Count"for i=1 to count
getinistr i ,"X"
getinistr i ,"Y"
getinistr i ,"Z"
next
Option ExplicitPrivate Declare Function GetPrivateProfileSection Lib "KERNEL32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As LongPublic Function GetInfoSection(strSection As String, strIniFile As String) As String()
Dim strReturn As String * 32767
Dim strTmp As String
Dim nStart As Integer
Dim nEnd As Integer
Dim i As Integer
Dim sArray() As String
Call GetPrivateProfileSection(strSection, strReturn, Len(strReturn), strIniFile)
strTmp = strReturn
i = 1
Do While strTmp <> ""
nStart = nEnd + 1
nEnd = InStr(nStart, strReturn, vbNullChar)
strTmp = Mid$(strReturn, nStart, nEnd - nStart)
If Len(strTmp) > 0 Then
ReDim Preserve sArray(1 To i)
sArray(i) = strTmp
i = i + 1
End If
Loop
GetInfoSection = sArray
End FunctionPrivate Sub Command1_Click()
Dim i As Long
Dim A() As String
A = GetInfoSection("aaa", "c:\1.ini") 'C:\1.ini 改为你的文件名
For i = 1 To UBound(A)
MsgBox A(i)
Next
End Sub
一行中根据“=”位置直接提取出id、x、y、z的值。
更多例程http://download.csdn.net/user/mokton
Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'GetPrivateProfileString(Section , KeyWord , 读取失败的代替值 ,KeyWordValue返回值 , Value值缓冲区大小 , INI路径)
Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName As String) As Long
'WritePrivateProfileString(Section , KeyWord ,KeyWordValue ,INI路径)Public IniPath As String
Public netName As String
Public TimeInterval As String
Public sEnableVerb As String
Public sDisableVerb As StringPublic Function Loadings() As Boolean
On Error GoTo EE
IniPath = App.Path + "\Net.ini"
netName = GetFromINI("NetConfig", "ConName", IniPath)
TimeInterval = GetFromINI("NetConfig", "TimeInterval", IniPath)
sEnableVerb = GetFromINI("NetConfig", "Enable", IniPath)
sDisableVerb = GetFromINI("NetConfig", "Disable", IniPath)
If netName = "" Then GoTo EE
Loadings = True
Exit Function
EE:
Loadings = False
End FunctionPrivate Function GetFromINI(AppName As String, KeyName As String, FileName As String) As String
Dim RetStr As String
Dim Result As Long
RetStr = String(255, Chr$(0))
Result = GetPrivateProfileString(AppName, ByVal KeyName, "", RetStr, Len(RetStr), FileName)
RetStr = TrimNull(RetStr)
GetFromINI = RetStr
End FunctionPrivate Function TrimNull(Item As String) As String
Dim pos As Integer
pos = InStr(Item, Chr$(0))
If pos Then Item = Left$(Item, pos - 1)
TrimNull = Item
End Function
SupermanKing 发表于:2008-08-24 17:02:327楼 得分:0
说白了就是字符串处理,还要“绝顶高手请进...”,
都不知道你是想讽刺帮你答题的人还是赞扬帮你答题的人。