' В модуль
Private Declare Function GetPrivateProfileInt Lib "kernel32" _
Alias "GetPrivateProfileIntA" _
(ByVal strSection As String, _
ByVal strKeyName As String, _
ByVal lngDefault As Long, _
ByVal strFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" _
(ByVal strSection As String, _
ByVal strKeyName As String, _
ByVal strDefault As String, _
ByVal strReturned As String, _
ByVal lngSize As Long, _
ByVal strFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" _
(ByVal strSection As String, _
ByVal strKeyNam As String, _
ByVal strValue As String, _
ByVal strFileName As String) As Long
Public Function GetValueString(strSection As String, _
strKey As String, strFile As String) As String
Dim strBuffer As String * 256
Dim intSize As Integer
On Error GoTo PROC_ERR
intSize = GetPrivateProfileString(strSection, strKey, "", _
strBuffer, 256, strFile)
GetValueString = Left$(strBuffer, intSize)
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox "Ошибка: <" & Err.Number & "> - " & Err.Description, _
vbExclamation = vbOKOnly, "GetValueString"
Resume PROC_EXIT
End Function
Public Function SetValue(strSection As String, strKey As String, _
strValue As String, strFile As String) As Integer
Dim intStatus As Integer
On Error GoTo PROC_ERR
intStatus = WritePrivateProfileString(strSection, strKey, _
strValue, strFile)
SetValue = (intStatus <> 0)
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox "Ошибка: <" & Err.Number & "> - " & Err.Description, _
vbExclamation = vbOKOnly, "SetValue"
Resume PROC_EXIT
End Function
' В форму
чтение
GetValueString("Раздел", "Имя параметра", "Путь до ini")
запись
SetValue("Раздел", "Имя параметра", "Значение", "Путь до ini")
[devices]
device1=qwert
device2=asdfg
device3=zxcvb
.....
device15=yuiop
.....
Chuvak писал(а):вопрос к MEMBER:
а если структура INI такая
- Код: Выделить всё
[devices]
device1=qwert
device2=asdfg
device3=zxcvb
.....
device15=yuiop
.....
т.е. число ключей не известно.
Как, например, значения ключей загнать в массив?
' В форму
чтение
GetValueString("Раздел", "Имя параметра", "Путь до ini")
Chuvak писал(а):вполне понятный и ясный ответ
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
Public Function LoadProfileSection( _
ByVal SectionName As String, _
Optional ByVal IniFileName As String = vbNullString _
) As Variant
Const max_char As Long = 32767
Dim s As String
Dim i As Long
Dim arr() As String
Dim v As Variant
s = String$(max_char, vbNullChar)
i = GetPrivateProfileSection(SectionName, ByVal s, Len(s), ByVal IniFileName)
If (i = 0) Then GoTo ExitRoutine
s = Left$(s, i - 1)
v = Split(s, vbNullChar)
If (UBound(v) < 0) Then GoTo ExitRoutine
ReDim Preserve arr(1, UBound(v))
For i = 0 To UBound(v)
arr(0, i) = GetNextItemFromValueList(v(i), "=", vbTextCompare)
arr(1, i) = v(i)
Next
LoadProfileSection = arr
ExitRoutine:
On Error Resume Next
Erase v, arr
End Function
skiperski писал(а):тихо сам с собою я веду беседу...
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 4