Bonjour a tous,
Quelqu'un sait comment utiliser cette API.
Elle permet de lire une section d'un fichier.ini,
mais qu'est que une section et comment l'utilisé ?
Merci de votre aide
Raymond Fournier
Bonjour a tous,
Quelqu'un sait comment utiliser cette API.
Elle permet de lire une section d'un fichier.ini,
mais qu'est que une section et comment l'utilisé ?
Merci de votre aide
Raymond Fournier
Bonjour a tous,
Quelqu'un sait comment utiliser cette API.
Elle permet de lire une section d'un fichier.ini,
mais qu'est que une section et comment l'utilisé ?
Merci de votre aide
Raymond Fournier
Salut,
Un ini se présente ainsi :
[Section1]
key1=value1
key2=value2
[Section2]
key1=value1
key2=value2
Voici un exemple :
'Example by Antti Häkkinen ()
'Visit his website at http://www.theredstar.f2s.com/
'require variable declaration
Option Explicit
'declares for ini controlling
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 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 WritePrivateProfileSection Lib "kernel32"
Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal
lpString As String, 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
'when form is loaded
Private Sub Form_Load()
'if error occures resume still
On Error Resume Next
'local variables
Dim File As String, OFLen As Double, _
Str As String
'set our varibles
File = "C:temp.txt"
OFLen = FileLen(File)
'write few example sections:
WriteIniSection File, "Test1", ""
WriteIniSection File, "Test2", "Here shoud be found some text"
'write few ini strings
WriteIni File, "Test3", "Ini1", "This is ini 1"
WriteIni File, "Test1", "Ini2", "This is ini 2"
'inform we're written the data
MsgBox Format((FileLen(File) - OFLen) / 1024, "0.00") & " KB data
written to " & Chr(34) & File & Chr(34)
'read the ini file
Str = Str & "Test2 section: " & vbTab & ReadIniSection(File, "Test2")
& vbCrLf
Str = Str & "Test1 section: " & vbTab & ReadIniSection(File, "Test1")
& vbCrLf
Str = Str & "Ini1 string: " & vbTab & ReadIni(File, "Test3", "Ini1") &
vbCrLf
Str = Str & "Ini2 string: " & vbTab & ReadIni(File, "Test1", "Ini2") &
vbCrLf
'show data
MsgBox Str
End Sub
'// INI CONTROLLING PROCEDURES
'reads ini string
Public Function ReadIni(Filename As String, Section As String, Key As
String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileString(Section, Key, "", RetVal, 255, Filename)
ReadIni = Left(RetVal, v - 1)
End Function
'reads ini section
Public Function ReadIniSection(Filename As String, Section As String)
As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileSection(Section, RetVal, 255, Filename)
ReadIniSection = Left(RetVal, v - 1)
End Function
'writes ini
Public Sub WriteIni(Filename As String, Section As String, Key As
String, Value As String)
WritePrivateProfileString Section, Key, Value, Filename
End Sub
'writes ini section
Public Sub WriteIniSection(Filename As String, Section As String,
Value As String)
WritePrivateProfileSection Section, Value, Filename
End Sub
Salut,
Un ini se présente ainsi :
[Section1]
key1=value1
key2=value2
[Section2]
key1=value1
key2=value2
Voici un exemple :
'Example by Antti Häkkinen (antti@theredstar.f2s.com)
'Visit his website at http://www.theredstar.f2s.com/
'require variable declaration
Option Explicit
'declares for ini controlling
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 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 WritePrivateProfileSection Lib "kernel32"
Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal
lpString As String, 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
'when form is loaded
Private Sub Form_Load()
'if error occures resume still
On Error Resume Next
'local variables
Dim File As String, OFLen As Double, _
Str As String
'set our varibles
File = "C:temp.txt"
OFLen = FileLen(File)
'write few example sections:
WriteIniSection File, "Test1", ""
WriteIniSection File, "Test2", "Here shoud be found some text"
'write few ini strings
WriteIni File, "Test3", "Ini1", "This is ini 1"
WriteIni File, "Test1", "Ini2", "This is ini 2"
'inform we're written the data
MsgBox Format((FileLen(File) - OFLen) / 1024, "0.00") & " KB data
written to " & Chr(34) & File & Chr(34)
'read the ini file
Str = Str & "Test2 section: " & vbTab & ReadIniSection(File, "Test2")
& vbCrLf
Str = Str & "Test1 section: " & vbTab & ReadIniSection(File, "Test1")
& vbCrLf
Str = Str & "Ini1 string: " & vbTab & ReadIni(File, "Test3", "Ini1") &
vbCrLf
Str = Str & "Ini2 string: " & vbTab & ReadIni(File, "Test1", "Ini2") &
vbCrLf
'show data
MsgBox Str
End Sub
'// INI CONTROLLING PROCEDURES
'reads ini string
Public Function ReadIni(Filename As String, Section As String, Key As
String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileString(Section, Key, "", RetVal, 255, Filename)
ReadIni = Left(RetVal, v - 1)
End Function
'reads ini section
Public Function ReadIniSection(Filename As String, Section As String)
As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileSection(Section, RetVal, 255, Filename)
ReadIniSection = Left(RetVal, v - 1)
End Function
'writes ini
Public Sub WriteIni(Filename As String, Section As String, Key As
String, Value As String)
WritePrivateProfileString Section, Key, Value, Filename
End Sub
'writes ini section
Public Sub WriteIniSection(Filename As String, Section As String,
Value As String)
WritePrivateProfileSection Section, Value, Filename
End Sub
Salut,
Un ini se présente ainsi :
[Section1]
key1=value1
key2=value2
[Section2]
key1=value1
key2=value2
Voici un exemple :
'Example by Antti Häkkinen ()
'Visit his website at http://www.theredstar.f2s.com/
'require variable declaration
Option Explicit
'declares for ini controlling
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 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 WritePrivateProfileSection Lib "kernel32"
Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal
lpString As String, 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
'when form is loaded
Private Sub Form_Load()
'if error occures resume still
On Error Resume Next
'local variables
Dim File As String, OFLen As Double, _
Str As String
'set our varibles
File = "C:temp.txt"
OFLen = FileLen(File)
'write few example sections:
WriteIniSection File, "Test1", ""
WriteIniSection File, "Test2", "Here shoud be found some text"
'write few ini strings
WriteIni File, "Test3", "Ini1", "This is ini 1"
WriteIni File, "Test1", "Ini2", "This is ini 2"
'inform we're written the data
MsgBox Format((FileLen(File) - OFLen) / 1024, "0.00") & " KB data
written to " & Chr(34) & File & Chr(34)
'read the ini file
Str = Str & "Test2 section: " & vbTab & ReadIniSection(File, "Test2")
& vbCrLf
Str = Str & "Test1 section: " & vbTab & ReadIniSection(File, "Test1")
& vbCrLf
Str = Str & "Ini1 string: " & vbTab & ReadIni(File, "Test3", "Ini1") &
vbCrLf
Str = Str & "Ini2 string: " & vbTab & ReadIni(File, "Test1", "Ini2") &
vbCrLf
'show data
MsgBox Str
End Sub
'// INI CONTROLLING PROCEDURES
'reads ini string
Public Function ReadIni(Filename As String, Section As String, Key As
String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileString(Section, Key, "", RetVal, 255, Filename)
ReadIni = Left(RetVal, v - 1)
End Function
'reads ini section
Public Function ReadIniSection(Filename As String, Section As String)
As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileSection(Section, RetVal, 255, Filename)
ReadIniSection = Left(RetVal, v - 1)
End Function
'writes ini
Public Sub WriteIni(Filename As String, Section As String, Key As
String, Value As String)
WritePrivateProfileString Section, Key, Value, Filename
End Sub
'writes ini section
Public Sub WriteIniSection(Filename As String, Section As String,
Value As String)
WritePrivateProfileSection Section, Value, Filename
End Sub
Salut,
'reads ini string
Public Function ReadIni(Filename As String, Section As String, Key As
String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileString(Section, Key, "", RetVal, 255, Filename)
ReadIni = Left(RetVal, v - 1)
End Function
Salut,
'reads ini string
Public Function ReadIni(Filename As String, Section As String, Key As
String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileString(Section, Key, "", RetVal, 255, Filename)
ReadIni = Left(RetVal, v - 1)
End Function
Salut,
'reads ini string
Public Function ReadIni(Filename As String, Section As String, Key As
String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileString(Section, Key, "", RetVal, 255, Filename)
ReadIni = Left(RetVal, v - 1)
End Function
"ng" wrote in
news::
Ok, Alors quel est la différence entre GetPrivateProfileSection et
GetPrivateProfileString
"ng" <ng@babeuk.net> wrote in
news:OAtMSdiIEHA.3508@TK2MSFTNGP09.phx.gbl:
Ok, Alors quel est la différence entre GetPrivateProfileSection et
GetPrivateProfileString
"ng" wrote in
news::
Ok, Alors quel est la différence entre GetPrivateProfileSection et
GetPrivateProfileString
ReadIni ne fonctionne dans ce cas que pour des chaines de 255
caractŠres. Voici un bout de code pour effectuer quelques op‚rations
suppl‚mentaires (‚num‚ration des cl‚s, des sections, lecture,
‚criture, suppression) sur le fichier ini sans limite de 255
caractŠres: Option Explicit
Private Declare Function GetPrivateProfileString _
Lib "kernel32" _
Alias "GetPrivateProfileStringA" _
( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String _
) _
As Long
Private Declare Function GetPrivateProfileSectionNames _
Lib "kernel32" _
Alias "GetPrivateProfileSectionNamesA" _
( _
ByVal lpszReturnBuffer 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 _
Public Sub SetIniEntry(FileName As String, _
Section As String, _
Key As String, _
Value As String)
If WritePrivateProfileString(Section, _
Key, _
Value, _
FileName) = 0 Then
MsgBox "Une erreur s'est produite " & _
"lors de l'‚criture des donn‚es"
End If
End Sub
Public Function GetIniEntry( _
FileName As String, _
Section As String, _
Key As String, _
Optional DefaultValue As String = "" _
) _
As String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniEntry = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileString( _
Section, _
Key, _
DefaultValue, _
GetIniEntry, _
buffersize, _
FileName _
)
'The return value is the number of characters copied to the
buffer, ' not including the terminating null character.
'
'If neither lpAppName nor lpKeyName is NULL
' and the supplied destination buffer is too small
' to hold the requested string, the string is truncated
' and followed by a null character,
' and the return value is equal to nSize minus one.
If ReturnCode = buffersize - 1 _
And Right(GetIniEntry, 1) = vbNullChar Then 'buffer trop
court buffersize = buffersize + 256 'incr‚mente par pas de
256
Else
GetIniEntry = Left$(GetIniEntry, ReturnCode)
bContinue = False
End If
Loop
End Function
Sub RemoveIniKey(strFile As String, strSection As String, strKey As
String)
WritePrivateProfileString strSection, strKey, vbNullString,
strFile
End Sub
Sub RemoveIniSection(strFile As String, strSection As String)
WritePrivateProfileString strSection, _
vbNullString, vbNullString, strFile
End Sub
Public Function GetIniKeys(FileName As String, Section As String) As
String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniKeys = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileString( _
Section, _
ByVal vbNullString, _
"", _
GetIniKeys, _
buffersize, _
FileName _
)
'If either lpAppName or lpKeyName is NULL and the
'supplied destination buffer is too small to hold
'all the strings, the last string is truncated and
'followed by two null characters. In this case,
'the return value is equal to nSize minus two.
If ReturnCode = buffersize - 2 Then 'buffer trop court
buffersize = buffersize + 256 'incr‚mente par pas de 256
Else
If ReturnCode = 0 Then
GetIniKeys = ""
Else
GetIniKeys = Left$(GetIniKeys, ReturnCode - 1)
End If
bContinue = False
End If
Loop
End Function
Public Function GetIniSections2(FileName As String) As String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniSections2 = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileString( _
ByVal vbNullString, _
ByVal vbNullString, _
"", _
GetIniSections2, _
buffersize, _
FileName _
)
'If either lpAppName or lpKeyName is NULL and the
'supplied destination buffer is too small to hold
'all the strings, the last string is truncated and
'followed by two null characters. In this case,
'the return value is equal to nSize minus two.
If ReturnCode = buffersize - 2 Then 'buffer trop court
buffersize = buffersize + 256 'incr‚mente par pas de 256
Else
If ReturnCode = 0 Then
GetIniSections2 = ""
Else
GetIniSections2 = Left$(GetIniSections2, ReturnCode -
1)
End If
bContinue = False
End If
Loop
End Function
Public Function GetIniSections(strFileName As String) As String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniSections = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileSectionNames( _
GetIniSections, _
buffersize, _
strFileName _
)
'The return value specifies the number of characters
'copied to the specified buffer, not including the
'terminating null character. If the buffer is not large
'enough to contain all the section names associated
'with the specified initialization file, the return
'value is equal to the size specified by nSize minus two.
If ReturnCode = buffersize - 2 Then 'buffer trop court
buffersize = buffersize + 256 'incr‚mente par pas de 256
Else
'on vire les caractŠres en trop
If ReturnCode = 0 Then
GetIniSections = ""
Else
GetIniSections = Left$(GetIniSections, ReturnCode - 1)
End If
bContinue = False
End If
Loop
End Function
--
ReadIni ne fonctionne dans ce cas que pour des chaines de 255
caractŠres. Voici un bout de code pour effectuer quelques op‚rations
suppl‚mentaires (‚num‚ration des cl‚s, des sections, lecture,
‚criture, suppression) sur le fichier ini sans limite de 255
caractŠres: Option Explicit
Private Declare Function GetPrivateProfileString _
Lib "kernel32" _
Alias "GetPrivateProfileStringA" _
( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String _
) _
As Long
Private Declare Function GetPrivateProfileSectionNames _
Lib "kernel32" _
Alias "GetPrivateProfileSectionNamesA" _
( _
ByVal lpszReturnBuffer 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 _
Public Sub SetIniEntry(FileName As String, _
Section As String, _
Key As String, _
Value As String)
If WritePrivateProfileString(Section, _
Key, _
Value, _
FileName) = 0 Then
MsgBox "Une erreur s'est produite " & _
"lors de l'‚criture des donn‚es"
End If
End Sub
Public Function GetIniEntry( _
FileName As String, _
Section As String, _
Key As String, _
Optional DefaultValue As String = "" _
) _
As String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniEntry = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileString( _
Section, _
Key, _
DefaultValue, _
GetIniEntry, _
buffersize, _
FileName _
)
'The return value is the number of characters copied to the
buffer, ' not including the terminating null character.
'
'If neither lpAppName nor lpKeyName is NULL
' and the supplied destination buffer is too small
' to hold the requested string, the string is truncated
' and followed by a null character,
' and the return value is equal to nSize minus one.
If ReturnCode = buffersize - 1 _
And Right(GetIniEntry, 1) = vbNullChar Then 'buffer trop
court buffersize = buffersize + 256 'incr‚mente par pas de
256
Else
GetIniEntry = Left$(GetIniEntry, ReturnCode)
bContinue = False
End If
Loop
End Function
Sub RemoveIniKey(strFile As String, strSection As String, strKey As
String)
WritePrivateProfileString strSection, strKey, vbNullString,
strFile
End Sub
Sub RemoveIniSection(strFile As String, strSection As String)
WritePrivateProfileString strSection, _
vbNullString, vbNullString, strFile
End Sub
Public Function GetIniKeys(FileName As String, Section As String) As
String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniKeys = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileString( _
Section, _
ByVal vbNullString, _
"", _
GetIniKeys, _
buffersize, _
FileName _
)
'If either lpAppName or lpKeyName is NULL and the
'supplied destination buffer is too small to hold
'all the strings, the last string is truncated and
'followed by two null characters. In this case,
'the return value is equal to nSize minus two.
If ReturnCode = buffersize - 2 Then 'buffer trop court
buffersize = buffersize + 256 'incr‚mente par pas de 256
Else
If ReturnCode = 0 Then
GetIniKeys = ""
Else
GetIniKeys = Left$(GetIniKeys, ReturnCode - 1)
End If
bContinue = False
End If
Loop
End Function
Public Function GetIniSections2(FileName As String) As String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniSections2 = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileString( _
ByVal vbNullString, _
ByVal vbNullString, _
"", _
GetIniSections2, _
buffersize, _
FileName _
)
'If either lpAppName or lpKeyName is NULL and the
'supplied destination buffer is too small to hold
'all the strings, the last string is truncated and
'followed by two null characters. In this case,
'the return value is equal to nSize minus two.
If ReturnCode = buffersize - 2 Then 'buffer trop court
buffersize = buffersize + 256 'incr‚mente par pas de 256
Else
If ReturnCode = 0 Then
GetIniSections2 = ""
Else
GetIniSections2 = Left$(GetIniSections2, ReturnCode -
1)
End If
bContinue = False
End If
Loop
End Function
Public Function GetIniSections(strFileName As String) As String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniSections = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileSectionNames( _
GetIniSections, _
buffersize, _
strFileName _
)
'The return value specifies the number of characters
'copied to the specified buffer, not including the
'terminating null character. If the buffer is not large
'enough to contain all the section names associated
'with the specified initialization file, the return
'value is equal to the size specified by nSize minus two.
If ReturnCode = buffersize - 2 Then 'buffer trop court
buffersize = buffersize + 256 'incr‚mente par pas de 256
Else
'on vire les caractŠres en trop
If ReturnCode = 0 Then
GetIniSections = ""
Else
GetIniSections = Left$(GetIniSections, ReturnCode - 1)
End If
bContinue = False
End If
Loop
End Function
--
ReadIni ne fonctionne dans ce cas que pour des chaines de 255
caractŠres. Voici un bout de code pour effectuer quelques op‚rations
suppl‚mentaires (‚num‚ration des cl‚s, des sections, lecture,
‚criture, suppression) sur le fichier ini sans limite de 255
caractŠres: Option Explicit
Private Declare Function GetPrivateProfileString _
Lib "kernel32" _
Alias "GetPrivateProfileStringA" _
( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String _
) _
As Long
Private Declare Function GetPrivateProfileSectionNames _
Lib "kernel32" _
Alias "GetPrivateProfileSectionNamesA" _
( _
ByVal lpszReturnBuffer 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 _
Public Sub SetIniEntry(FileName As String, _
Section As String, _
Key As String, _
Value As String)
If WritePrivateProfileString(Section, _
Key, _
Value, _
FileName) = 0 Then
MsgBox "Une erreur s'est produite " & _
"lors de l'‚criture des donn‚es"
End If
End Sub
Public Function GetIniEntry( _
FileName As String, _
Section As String, _
Key As String, _
Optional DefaultValue As String = "" _
) _
As String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniEntry = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileString( _
Section, _
Key, _
DefaultValue, _
GetIniEntry, _
buffersize, _
FileName _
)
'The return value is the number of characters copied to the
buffer, ' not including the terminating null character.
'
'If neither lpAppName nor lpKeyName is NULL
' and the supplied destination buffer is too small
' to hold the requested string, the string is truncated
' and followed by a null character,
' and the return value is equal to nSize minus one.
If ReturnCode = buffersize - 1 _
And Right(GetIniEntry, 1) = vbNullChar Then 'buffer trop
court buffersize = buffersize + 256 'incr‚mente par pas de
256
Else
GetIniEntry = Left$(GetIniEntry, ReturnCode)
bContinue = False
End If
Loop
End Function
Sub RemoveIniKey(strFile As String, strSection As String, strKey As
String)
WritePrivateProfileString strSection, strKey, vbNullString,
strFile
End Sub
Sub RemoveIniSection(strFile As String, strSection As String)
WritePrivateProfileString strSection, _
vbNullString, vbNullString, strFile
End Sub
Public Function GetIniKeys(FileName As String, Section As String) As
String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniKeys = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileString( _
Section, _
ByVal vbNullString, _
"", _
GetIniKeys, _
buffersize, _
FileName _
)
'If either lpAppName or lpKeyName is NULL and the
'supplied destination buffer is too small to hold
'all the strings, the last string is truncated and
'followed by two null characters. In this case,
'the return value is equal to nSize minus two.
If ReturnCode = buffersize - 2 Then 'buffer trop court
buffersize = buffersize + 256 'incr‚mente par pas de 256
Else
If ReturnCode = 0 Then
GetIniKeys = ""
Else
GetIniKeys = Left$(GetIniKeys, ReturnCode - 1)
End If
bContinue = False
End If
Loop
End Function
Public Function GetIniSections2(FileName As String) As String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniSections2 = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileString( _
ByVal vbNullString, _
ByVal vbNullString, _
"", _
GetIniSections2, _
buffersize, _
FileName _
)
'If either lpAppName or lpKeyName is NULL and the
'supplied destination buffer is too small to hold
'all the strings, the last string is truncated and
'followed by two null characters. In this case,
'the return value is equal to nSize minus two.
If ReturnCode = buffersize - 2 Then 'buffer trop court
buffersize = buffersize + 256 'incr‚mente par pas de 256
Else
If ReturnCode = 0 Then
GetIniSections2 = ""
Else
GetIniSections2 = Left$(GetIniSections2, ReturnCode -
1)
End If
bContinue = False
End If
Loop
End Function
Public Function GetIniSections(strFileName As String) As String
Dim ReturnCode As Long, bContinue As Boolean, buffersize As Long
bContinue = True
buffersize = 256
Do While bContinue
GetIniSections = String$(buffersize, vbNullChar)
ReturnCode = GetPrivateProfileSectionNames( _
GetIniSections, _
buffersize, _
strFileName _
)
'The return value specifies the number of characters
'copied to the specified buffer, not including the
'terminating null character. If the buffer is not large
'enough to contain all the section names associated
'with the specified initialization file, the return
'value is equal to the size specified by nSize minus two.
If ReturnCode = buffersize - 2 Then 'buffer trop court
buffersize = buffersize + 256 'incr‚mente par pas de 256
Else
'on vire les caractŠres en trop
If ReturnCode = 0 Then
GetIniSections = ""
Else
GetIniSections = Left$(GetIniSections, ReturnCode - 1)
End If
bContinue = False
End If
Loop
End Function
--
Bonjour,
Est-ce que c'est possible de connaître le nombre de clé dans une
section d'un fichier.ini ?
Ceci dans le but d'extraire la valeur de chaque clé de la section.
Merci Raymond Fournier
Bonjour,
Est-ce que c'est possible de connaître le nombre de clé dans une
section d'un fichier.ini ?
Ceci dans le but d'extraire la valeur de chaque clé de la section.
Merci Raymond Fournier
Bonjour,
Est-ce que c'est possible de connaître le nombre de clé dans une
section d'un fichier.ini ?
Ceci dans le but d'extraire la valeur de chaque clé de la section.
Merci Raymond Fournier
-----Message d'origine-----
Bonjour,
Est-ce que c'est possible de connaître le nombre de clé
d'un fichier.ini ?
Ceci dans le but d'extraire la valeur de chaque clé de la
Merci Raymond Fournier
.
-----Message d'origine-----
Bonjour,
Est-ce que c'est possible de connaître le nombre de clé
d'un fichier.ini ?
Ceci dans le but d'extraire la valeur de chaque clé de la
Merci Raymond Fournier
.
-----Message d'origine-----
Bonjour,
Est-ce que c'est possible de connaître le nombre de clé
d'un fichier.ini ?
Ceci dans le but d'extraire la valeur de chaque clé de la
Merci Raymond Fournier
.