Hello,
Comme j'ai déjà fait une petite routine en utilisant l'API PrivateProfile, un tours de magie et la voici...
A++
PS: en cas de prob(s), laisse un message en indiquant comme sujet "PrivateProfile...".
Option Explicit
' Déclaration du tableau des Property.
Private Type Property
Property As String
Value As String
End Type
' Déclaration pour l'Utilisation des INI.
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
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
Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
' Déclaration des variables de l'INI.
Public strINI_APPFILE As String
Public strUSERName As String
Public strSociete As String
Public strRegistred As String
Public strLOADPath As String
Public strSAVEPath As String
Public strWordDot As String
Public strProterty() As Property
Public Sub Initialisation()
' Déclarations des variables.
Dim intNb As Integer
Dim lngPos As Long
Dim strTemp01 As String
Dim strTemp02 As String
strINI_APPFILE = App.Path + "" + App.EXEName + ".ini"
If FileExist(strINI_APPFILE) Then
ReDim strProterty(0)
' Lecture de la "Configuration générale".
strUSERName = Decoder(LectureINI(strINI_APPFILE, "GENERAL", "USERName"))
strSociete = Decoder(LectureINI(strINI_APPFILE, "GENERAL", "Societe"))
strRegistred = Decoder(LectureINI(strINI_APPFILE, "GENERAL", "Registred"))
strLOADPath = LectureINI(strINI_APPFILE, "GENERAL", "LOADPath")
strSAVEPath = LectureINI(strINI_APPFILE, "GENERAL", "SAVEPath")
strWordDot = LectureINI(strINI_APPFILE, "GENERAL", "WordDot")
' Lecture de la "Configuration property".
Do
strTemp01 = LectureINI(strINI_APPFILE, "PROPERTYSCAN", "Property" & Trim(Str(intNb)))
If strTemp01 = "" Then
Exit Do
Else
lngPos = InStr(strTemp01, "")
strTemp02 = Mid$(strTemp01, 1, lngPos - 1)
strTemp01 = Mid$(strTemp01, lngPos + 1, Len(strTemp01) - lngPos)
ReDim Preserve strProterty(intNb)
strProterty(intNb).Property = strTemp02
strProterty(intNb).Value = strTemp01
intNb = intNb + 1
End If
Loop
End If
If strUSERName "" Then strUSERName "??" If strSociete "" Then strSociete "??" If strRegistred "" Then strRegistred "??"
End Sub
Public Function LectureINI(ByVal Fichier As String, ByVal Section As String, ByVal Cle As String)
' Lecture du fichier INI et de la Clef.
Dim Valeur As String
Dim Res As Integer
Dim Message As String
Valeur = Space(255)
Res = GetPrivateProfileString(Section, Cle, "", Valeur, Len(Valeur), Fichier)
If Res <> 0 Then
LectureINI = Left(Valeur, Res)
End If
End Function
Public Function EcritureSection(ByVal sNomSection As String, ByVal sValeur As String, ByVal sFileName As String) As Long
' Ecriture de Valeur dans le fichier INI.
EcritureSection = WritePrivateProfileSection(sNomSection, sValeur, sFileName)
End Function
Public Function EcritureINI(ByVal sSection As String, ByVal sKeyName As String, ByVal sNewString As String, sFileName) As Integer
' Ecriture de Clefs et Valeur dans le fichier INI.
Dim Res As Integer
Res = WritePrivateProfileString(sSection, sKeyName, sNewString, sFileName)
End Function
Public Function Encoder(Text As String) As String
Encoder = Text
End Function
Public Function Decoder(Text As String) As String
Decoder = NewText
End Function