如何循环读INI文件
Function GetFromINI(AppName As String, KeyName As String, FileName As String) As StringDim RetStr As String
RetStr = String(255, Chr(0))
GetFromINI = Left(RetStr, GetPrivateProfileString(AppName, ByVal KeyName, "", RetStr, Len(RetStr), FileName))
End Function
Private Sub cmdRead_Click()
Dim key(9) As String
Dim m As Integer
Dim no As Integer
Dim i As Integer
Dim myweb As String
myweb = String(255, 0)
no = 1
For no = 1 To Val(Text1.Text)
key(0) = "_IPAdr"
key(1) = "_Port"
key(2) = "_ModbusFC"
key(3) = "_AdrPLC_EW"
key(4) = "_AdrI/O_EW"
key(5) = "_Count_EW"
key(6) = "_AdrPLC_AW"
key(7) = "_AdrI/O_AW"
key(8) = "_Count_AW"
key(9) = "_Timeout"
For i = 0 To 9
key(i) = CStr(no) + key(i)
m = i + 1
MSFGrid1.TextMatrix(no, m) = GetFromINI("ILBETH24 ", key(i), App.Path + "\PLC43.ini)
Next i
Next no
End Sub
如果说要读取的PLC43.INI文件中的内容为
[ILBETH24]
1_IPAdr= . . .
1_Port=502
1_ModbusFC=0x03
1_AdrPLC_EW= 1
1_AdrI/O_EW= 2
1_Count_EW= 3
1_AdrPLC_AW=-
1_AdrI/O_AW=-
1_Count_AW=-
1_Timeout=2000
2_IPAdr= . . .
2_Port=502
2_ModbusFC=0x04
2_AdrPLC_EW= 11
2_AdrI/O_EW= 21
2_Count_EW= 31
2_AdrPLC_AW=-
2_AdrI/O_AW=-
2_Count_AW=-
2_Timeout=2000
3_IPAdr= . . .
3_Port=502
3_ModbusFC=0x06
3_AdrPLC_EW=-
3_AdrI/O_EW=-
3_Count_EW=-
3_AdrPLC_AW= 4
3_AdrI/O_AW= 5
3_Count_AW= 6
3_Timeout=2000
4_IPAdr= . . .
4_Port=502
4_ModbusFC=0x10
4_AdrPLC_EW=-
4_AdrI/O_EW=-
4_Count_EW=-
4_AdrPLC_AW= 41
4_AdrI/O_AW= 51
4_Count_AW= 61
4_Timeout=2000
5_IPAdr= . . .
5_Port=502
5_ModbusFC=0x17
5_AdrPLC_EW= 11
5_AdrI/O_EW= 21
5_Count_EW= 31
5_AdrPLC_AW= 41
5_AdrI/O_AW= 51
5_Count_AW= 61
5_Timeout=2000
--------------------编程问答-------------------- 项目那个地方传个VBNULLSTRING
可以返回所有项目 保存到数组
来个循环就可以了...
补充:VB , API