OVH Cloud OVH Cloud

Fichier .ini

2 réponses
Avatar
Fournier Raymond
Bounjour a tous,
Il y a environ deux semaines François ma fournie du code pour géré
les fichiers .ini. Je rencontre un petit problème.

Alors dans un module:
Public Function GetIniKeys(FileName As String, Section As String) As
String

'Va chercher l'information d'une clé dans une section.
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

Dans mon contrôle:
Dim strSplitted() As String

strSplitted = Split(modFichierINI.GetIniKeys(App.Path & "\Menu.ini",
"Bande0"))
MsgBox "Nombre de clés : " & (UBound(strSplitted) - LBound(strSplitted)
+ 1)

J'optient toujour la valeur "1", mais si je met un point d'arret sur
"GetIniKeys = Left$(GetIniKeys, ReturnCode - 1)" tout les clés sont
lister.

Quelqu'un a une idée de ce qui se passe.

Merci Raymond Fournier

2 réponses

Avatar
Zoury
Salut Raymond! :O)

Tu dois faire un Split() sur vbNullChar et non sur " " (qui est le caractère
par défaut)..

strSplitted = Split(modFichierINI.GetIniKeys(App.Path & "Menu.ini",


"Bande0"), vbNullChar)
MsgBox "Nombre de clés : " & (UBound(strSplitted) - LBound(strSplitted) +


1)

--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/
Avatar
Fournier Raymond
"Zoury" wrote in
news:#:

Salut Raymond! :O)

Tu dois faire un Split() sur vbNullChar et non sur " " (qui est le
caractère par défaut)..

strSplitted = Split(modFichierINI.GetIniKeys(App.Path & "Menu.ini",


"Bande0"), vbNullChar)
MsgBox "Nombre de clés : " & (UBound(strSplitted) -
LBound(strSplitted) +


1)




Merci une erreur d'attention

Raymond