IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

VB 2010 lire / écrire dans fichier ini


Sujet :

VB.NET

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 183
    Points : 66
    Points
    66
    Par défaut VB 2010 lire / écrire dans fichier ini
    Bonjour à tous,

    J'ai des données utilisateur couplées à des données application que je ne peux pas stocker dans les ApplicationSettings pas plus que dans la base de registre. Il y en a trop et elle n'est pas faite pour ça. Je souhaite donc en revenir à mon bon vieux fichier ini.

    Mais tous les scripts que je trouve de lecture, soit pour lire la collection de Sections, soit pour lire la collection de Clés, soit pour lire la valeur d'une clé, ne fonctionnent pas. Même ceux du tutorial de Plasserre. J'ai trouvé une dizaine de classes mais chaque fois le debogeur coince et affiche, en vert, :

    PInvokeStackImbalance a été détecté
    Un appel à la fonction PInvoke 'ASE!ASE.Functions::GetPrivateProfileString' a déséquilibré la pile. Cela peut se produire, car la signature PInvoke managée ne correspond pas à la signature cible non managée. Vérifiez que la convention d'appel et les paramètres de la signature PInvoke correspondent à la signature non managée cible.
    où ASE est le nom de l'appli.

    La seule ligne que j'ai changée sur les scripts trouvés c'est celle là :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    strReturn = String(255, chr(0))
    Mon VB ne prend pas la fonction String et j'y pallie en écrivant soit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Dim i as integer=0
    Dim strReturn as string = string.Empty
     
    For i = 1 to 255
        strReturn = strReturn & chr(0)
    next
    soit celle-ci (j'ai testé les deux... :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Dim strReturn as string = space(chr(0))
    Je mets ici les 6 cas possibles qui, tous, coincent...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
     
         Private Declare Function GetPrivateProfileSection Lib "kernel32.dll" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
        Private Declare Function GetPrivateProfileSectionNames Lib "kernel32.dll" Alias "GetPrivateProfileSectionNamesA" (ByVal lpszReturnBuffer As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
        Private Declare Function GetPrivateProfileString Lib "kernel32.dll" 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 WritePrivateProfileSection Lib "kernel32.dll" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
        Private Declare Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
     
     
    'premier cas
    '---------------
     
    Public Function GetSectionsCollection(ByVal strINIFile As String) As Collection
     
            Dim strBuf As String = = Space(500)
            Dim col As Object = Nothing
            Dim bufCol As Collection = Nothing
            Dim I As Long = 0
            Dim lngRet As Long = 0
     
            lngRet = GetPrivateProfileSectionNames(strBuf, Len(strBuf), strINIFile)
     
            If lngRet <> 0 Then
                strBuf = Microsoft.VisualBasic.Left(strBuf, lngRet)
            Else
                GetSectionsCollection = Nothing
                Exit Function
            End If
     
            col = Split(strBuf, Chr(0))
            bufCol = New Collection
     
            For I = 0 To UBound(col)
                If (col(I)).Trim IsNot String.Empty Then bufCol.Add(col(I))
            Next
     
            col = Nothing
            GetSectionsCollection = bufCol
            bufCol = Nothing
     
        End Function
     
        Private Sub lireIni()
     
            Dim FichierIni As String = CheminConfig & "Repart.ini"        
            Dim Coll As Collection
            Dim msg As String = String.Empty
            Dim i As Integer = 0
     
            Coll = GetSectionsCollection(FichierIni)
     
            For i = 1 To Coll.Count
                msg = msg & Coll(i)
            Next
     
            MessageBox.Show(msg)
     
        End Sub
     
    '---------------------------------------------------------
     
    'deuxième cas :
    '----------------
     
    Private Function ListeSectionIni(ByVal Path As String, Section() As String)
        Dim strReturn As String
        strReturn = String(8192, 0)
     
        GetPrivateProfileSectionNames strReturn, Len(strReturn), Path
     
        Section = Split(Left(strReturn, InStr(1, strReturn, vbNullChar & vbNullChar) - 1), vbNullChar)
    End Function
     
        Private Sub LireIni()
     
            Dim strINIFile As String = CheminConfig & "Repart.ini"
            Dim strSection As String = "Marchés français"    'Nom de la rubrique        
            Dim Coll As Collection
            Dim msg As String = String.Empty
            Dim i As Integer = 0
     
            Coll=ListeSectionKey(strINIFile, "", Key() As String)
            For i = 1 To Coll.Count
                msg = msg & Coll(i)
            Next
     
            MessageBox.Show(msg)
     
        End Sub
     
     
    '---------------------------------------------------------
     
    'troisième cas :
    '----------------
     
    Public Function GetKeysCollection(ByVal strINIFile As String, ByVal strSection As String, Optional ByVal bWithValues As Boolean = True) As Collection
     
            Dim strBuf As String = Space(500)
            Dim col As Object = Nothing
            Dim Col2 As Object = Nothing
            Dim bufCol As Collection = Nothing
            Dim I As Long = 0
            Dim lngRet As Long = 0
     
            lngRet = GetPrivateProfileSection(strSection, strBuf, Len(strBuf), strINIFile)
     
            If lngRet <> 0 Then
                strBuf = Microsoft.VisualBasic.Left(strBuf, lngRet)
            Else
                GetKeysCollection = Nothing
                Exit Function
            End If
     
            col = Split(strBuf, Chr(0))
            bufCol = New Collection
     
            For I = 0 To UBound(col)
                If (col(I)).Trim IsNot String.Empty Then
                    If Microsoft.VisualBasic.Left(col(I), 1) <> ";" Then
                        If bWithValues = True Then
                            bufCol.Add(col(I))
                        Else
                            Col2 = Split(col(I), "=", 2)
                            bufCol.Add(Col2(0))
                        End If
                    End If
                End If
            Next
     
            col = Nothing
            Col2 = Nothing
            GetKeysCollection = bufCol
            bufCol = Nothing
     
        End Function
     
        Private Sub LireIni()
     
            Dim FichierIni As String = CheminConfig & "Repart.ini"
            Dim strSection As String = "Marchés français"
            Dim Coll As Collection
            Dim msg As String = String.Empty
            Dim i As Integer = 0
     
            Coll = GetKeysCollection(FichierIni, strSection)
     
            For i = 1 To Coll.Count
                msg = msg & Coll(i)
            Next
     
            MessageBox.Show(msg)
     
        End Sub
     
     
    '---------------------------------------------------------
     
    'quatrième cas :
    '----------------
     
        Public Function ListeSectionKey(ByVal Path As String, ByVal Section As String, Key() As String)
     
            Dim strReturn As String = Space(8192)
     
            strReturn = GetPrivateProfileSection(Section, strReturn, 8192, Path)
     
            ListeSectionKey = Split(Left(strReturn, InStr(1, strReturn, vbNullChar & vbNullChar) - 1), vbNullChar)
     
        End Function
     
        Private Sub LireIni()
     
            Dim FichierIni As String = CheminConfig & "Repart.ini"
            Dim strSection As String = "Marchés français"
            Dim Key() As String
            Dim msg As String = String.Empty
            Dim i As Integer = 0
     
            ListeSectionKey(FichierIni, strSection, Key)
     
            For i = LBound(Key) To UBound(Key)
                msg = msg & Key(i)
            Next
     
            MessageBox.Show(msg)
     
        End Sub
     
    '------------------------------------------------------------
     
    ' et de façon générale
    '-----------------------
    '
    '1er Cas
    '-----------
     
        Public Function GetINIKeyValue(ByVal strINIFile As String, ByVal strSection As String, ByVal strKey As String) As String
     
            Dim strBuf As String = Space(255)
            Dim lngRet As Long = 0
     
            lngRet = GetPrivateProfileString(strSection, strKey, "", strBuf, Len(strBuf), strINIFile)
            If lngRet <> 0 Then
                GetINIKeyValue = Left$(strBuf, lngRet)
            Else
                GetINIKeyValue = String.Empty
            End If
     
        End Function
     
        Private Sub LireIni()
     
            Dim FichierIni As String = CheminConfig & "Repart.ini"
            Dim strSection As String = "Marchés français"
            Dim strKey As String = "Categ5"
            Dim msg As String = String.Empty
            Dim i As Integer = 0
     
            msg = GetINIKeyValue(FichierIni, strSection, strKey)
     
            MessageBox.Show(msg)
     
        End Sub
     
    '---------------------------------
     
    'second cas
    '--------------
     
        Public Function LitDansFichierIni(Section As String, Cle As String, Fichier As String, Optional ValeurParDefaut As String = "") As String
     
            Dim strReturn As String = Space(255)
     
            GetPrivateProfileString(Section, Cle, ValeurParDefaut, strReturn, Len(strReturn), Fichier)
            LitDansFichierIni = Left(strReturn, InStr(strReturn, Chr(0)) - 1)
     
        End Function
     
        Private Sub LireIni()
     
            Dim FichierIni As String = CheminConfig & "Repart.ini"
            Dim strSection As String = "Marchés français"
            Dim strKey As String = "Categ5"
            Dim msg As String = String.Empty
            Dim i As Integer = 0
     
            msg = LitDansFichierIni(strSection, strKey, FichierIni, "")
     
            MessageBox.Show(msg)
     
        End Sub
    J'espère que ça aura éclairé quelqu'un...

  2. #2
    Membre actif Avatar de Neiflheim
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2011
    Messages
    135
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Mai 2011
    Messages : 135
    Points : 269
    Points
    269
    Par défaut
    Salut,

    J'ai pas très bien compris le problème.

    Tu as un fichier ini de la sorte :

    [Path]=C:/....
    [Name]=Test

    etc (je ne sais plus très bien le format des .ini), et tu veux une fonction qui obtienne la valeur à partir de la clé?
    si mon message a été utile - si je suis à côté de la plaque - quand vous avez la réponse à votre question

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 183
    Points : 66
    Points
    66
    Par défaut
    Merci pour ta réponse.

    Il y a audessus les 5 déclarations des API windows. Hors celles qui écrivent dans les fichiers ini (et qui fonctionnent) il y a les fonctions qui se servent de ces API pour aller chercher :
    1) la liste des sections d'un fichier ini
    2) la liste des clés pour une section donnée
    3) la valeur de la clé pour la section et la clé donnés.

    A noter que pour la liste des sections et la liste des clés, il y a deux écoles, donc deux fonctions différentes avec la même API. J'ai donc testé les 2 écoles et je joins ici les fonctions trouvées et testées avec le code que j'ai appliqué.

    Je veux simplement réussir les points 1, 2 et 3...

    Juste ça... Ben, c'est pas aussi facile que de jouer au bouchon...

    Il doit y'avoir un truc, mais où ? Je suis un débutant en .Net et je vois pas, surtout que ces API, fonctions et codes viennent de tutoriaux, notamment de ce site. Gage de fiabilité.

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 183
    Points : 66
    Points
    66
    Par défaut
    Bonjour,

    Personne n'écrit dans un fichier Ini ? Depuis VB 2008 ou 2010 ? Il y a juste à comparer et me dire où mes scripts coincent... Soyez chic, j'en ai vraiment besoin.

    Merci de votre aide.

  5. #5
    Futur Membre du Club
    Profil pro
    Dirigeant
    Inscrit en
    Mai 2003
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Dirigeant

    Informations forums :
    Inscription : Mai 2003
    Messages : 4
    Points : 5
    Points
    5
    Par défaut
    ahhh lalal le typage...

    pour tout ceux qui tomberont sur cette page
    voici la solution :

    un import en plus (important pour caster)

    les fonctions faisant appel aux apis

    et deux fonctions (get et set) d'une clef

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    Imports System.Runtime.InteropServices.Marshal
     
    Private Declare Function GetPrivateProfileSection Lib "kernel32.dll" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedBuffer As IntPtr, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
    Private Declare Function GetPrivateProfileSectionNames Lib "kernel32.dll" Alias "GetPrivateProfileSectionNamesA" (ByVal lpszReturnBuffer As IntPtr, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
    Private Declare Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedBuffer As IntPtr, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
    Private Declare Function WritePrivateProfileSection Lib "kernel32.dll" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
    Private Declare Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
     
     
        'fonction retournant la valeur de la clé "Cle" de la section "Section" du fichier "File"
        Public Function GetCle(ByVal File As String, ByVal Section As String, ByVal Cle As String) As String
            Dim PtrCh As IntPtr
            Dim Lng As Integer
            Dim Chaine As String
     
            PtrCh = StringToHGlobalAnsi(New String(vbNullChar, 1024))
            Lng = GetPrivateProfileString(Section, Cle, "", PtrCh, 255, File)
            Chaine = PtrToStringAnsi(PtrCh, Lng)
            FreeHGlobal(PtrCh)
     
            GetCle = Chaine
        End Function
     
        'fonction Insèrant une section dans le fichier "File"
        Public Function SetSection(ByVal File As String, ByVal Section As String, ByVal Valeur As String) As Boolean
            SetSection = WritePrivateProfileSection(Section, Valeur, File)
        End Function

    Pour plus d'info voici le lien d'explication : http://dotnet.developpez.com/cours/?page=vbnet

  6. #6
    Expert confirmé
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Points : 4 005
    Points
    4 005
    Billets dans le blog
    7
    Par défaut
    ....il existe aussi cette classe très simple d'usage :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    Imports System.Runtime.InteropServices
    Imports System.IO
    Imports System.Text
     
    Public Class Cls_Ini
     
    #Region "Natives Methods"
     
        Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
    Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
        ByVal lpKeyName As String, ByVal lpDefault As String, _
        ByVal lpReturnedString As String, ByVal nSize As Int32, _
        ByVal lpFileName As String) As Int32
     
        <DllImport("kernel32")> _
        Private Shared Function GetPrivateProfileString(ByVal Section As String, ByVal Key As Integer, ByVal Value As String, <MarshalAs(UnmanagedType.LPArray)> ByVal Result As Byte(), ByVal Size As Integer, ByVal FileName As String) As Integer
        End Function
     
        <DllImport("kernel32")> _
        Private Shared Function GetPrivateProfileString(ByVal Section As Integer, ByVal Key As String, ByVal Value As String, <MarshalAs(UnmanagedType.LPArray)> ByVal Result As Byte(), ByVal Size As Integer, ByVal FileName As String) As Integer
        End Function
     
        Private Declare Unicode Function WritePrivateProfileString Lib "kernel32" _
        Alias "WritePrivateProfileStringW" (ByVal lpApplicationName As String, _
        ByVal lpKeyName As String, ByVal lpString As String, _
        ByVal lpFileName As String) As Int32
     
    #End Region
     
    #Region "Méthodes publiques"
     
        'Suppression de section
        Public Shared Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String)
            Dim lpKeyName As String = Nothing
            Dim lpString As String = Nothing
            WritePrivateProfileString(SectionName, lpKeyName, lpString, INIPath)
        End Sub
     
        'Suppression de clé
        Public Shared Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String)
            Dim lpString As String = Nothing
            WritePrivateProfileString(SectionName, KeyName, lpString, INIPath)
        End Sub
     
        'Lecture sections (Clés/Valeurs)
        Public Shared Function INIRead(ByVal INIPath As String) As String
            Return INIRead(INIPath, Nothing, Nothing, "")
        End Function
     
        'Lecture Clés/Valeurs d'une section spécifiée
        Public Shared Function INIRead(ByVal INIPath As String, ByVal SectionName As String) As String
            Return INIRead(INIPath, SectionName, Nothing, "")
        End Function
     
        'Lecture Valeur d'une section et clé spécifiée
        Public Shared Function INIRead(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String) As String
            Return INIRead(INIPath, SectionName, KeyName, "")
        End Function
     
        'Lecture Valeur d'une section et clé spécifiée (retourne vaneur par défaut si elle n'existe pas)
        Public Shared Function INIRead(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String, ByVal DefaultValue As String) As String
            Dim lpReturnedString As String = Strings.Space(2048)
            Dim length As Integer = GetPrivateProfileString(SectionName, KeyName, DefaultValue, lpReturnedString, lpReturnedString.Length, INIPath)
            If length > 0 Then
                Return lpReturnedString.Substring(0, length)
            End If
            Return ""
        End Function
     
        'Ecriture Clés/Valeurs dans une section spécifiée
        Public Shared Sub INIWrite(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String, ByVal TheValue As String)
            WritePrivateProfileString(SectionName, KeyName, TheValue, INIPath)
        End Sub
     
        'Détecte si section spécifiée existe
        Public Shared Function INISectionExist(ByVal INIPath As String, ByVal SectionName As String) As Boolean
            For Each sect In INISectionNames(INIPath)
                If sect.ToLower = SectionName.ToLower Then
                    Return True
                End If
            Next
            Return False
        End Function
     
        'Retourne tous les noms des sections existantes dans le fichier de configuration
        Public Shared Function INISectionNames(ByVal INIPath As String) As String()
            Dim maxsize As Integer = 500
            While True
                Dim bytes As Byte() = New Byte(maxsize - 1) {}
                Dim size As Integer = GetPrivateProfileString(0, "", "", bytes, maxsize, INIPath)
                If size < maxsize - 2 Then
                    Dim Selected As String = Encoding.ASCII.GetString(bytes, 0, size - (If(size > 0, 1, 0)))
                    Return Selected.Split(New Char() {ControlChars.NullChar})
                End If
                maxsize *= 2
            End While
            Return Nothing
        End Function
     
        'Retourne toutes les clés existantes d'une section spécifiée
        Public Shared Function INIEntryNames(ByVal INIPath As String, ByVal section As String) As String()
            Dim maxsize As Integer = 500
            While True
                Dim bytes As Byte() = New Byte(maxsize - 1) {}
                Dim size As Integer = GetPrivateProfileString(section, 0, "", bytes, maxsize, INIPath)
                If size < maxsize - 2 Then
                    Dim entries As String = Encoding.ASCII.GetString(bytes, 0, size - (If(size > 0, 1, 0)))
                    Return entries.Split(New Char() {ControlChars.NullChar})
                End If
                maxsize *= 2
            End While
            Return Nothing
        End Function
     
    #End Region
     
    End Class

    Comment l'utiliser :

    1- Ecrire une valeur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Cls_Ini.INIWrite("C:\YourIniFile.ini", "Section0", "Key0","Value0")
    2- Lire une valeur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Dim Val as string = Cls_Ini.INIRead("C:\YourIniFile.ini", "Section0","Key1")
    3- Exemple de contenu du fichier .ini :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    [Section0]
    Key0=Value0
    Key1=Value1
    Bonne soirée.

  7. #7
    Inactif  

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2012
    Messages
    4 904
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2012
    Messages : 4 904
    Points : 10 168
    Points
    10 168
    Billets dans le blog
    36
    Par défaut
    Bonjour,

    Dans la foulée des classes toutes prêtes, il y a celle-ci chez CodeProject.
    À ma connaissance, le seul personnage qui a été diagnostiqué comme étant allergique au mot effort. c'est Gaston Lagaffe.

    Ô Saint Excel, Grand Dieu de l'Inutile.

    Excel n'a jamais été, n'est pas et ne sera jamais un SGBD, c'est pour cela que Excel s'appelle Excel et ne s'appelle pas Access junior.

  8. #8
    Nouveau Candidat au Club
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Novembre 2014
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Auditeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Novembre 2014
    Messages : 1
    Points : 1
    Points
    1
    Par défaut UN GRAND MERCI A VOUS
    Bonjour
    Vous m'avez bien aidé
    Merci

  9. #9
    Expert confirmé
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Points : 4 005
    Points
    4 005
    Billets dans le blog
    7
    Par défaut
    Citation Envoyé par fethione Voir le message
    BONJOUR
    VOUS M'AVAIS BIEN AIDER
    MERCI
    Bonsoir,

    Il serait alors temps de passer ce sujet en résolu.

Discussions similaires

  1. Réponses: 3
    Dernier message: 06/12/2013, 10h24
  2. lire/écrire un fichier stocké dans le JAR ?
    Par SheikYerbouti dans le forum Entrée/Sortie
    Réponses: 11
    Dernier message: 24/03/2006, 10h37
  3. [C#] Comment lire/ecrire dans fichier ini ?
    Par meli0207 dans le forum C#
    Réponses: 2
    Dernier message: 20/03/2006, 16h53
  4. lire / écrire dans un fichier excel au format xml
    Par crisflo dans le forum Format d'échange (XML, JSON...)
    Réponses: 7
    Dernier message: 28/01/2006, 10h50
  5. Lire/écrire dans.zip comme si c'était un répertoire
    Par LadyWasky dans le forum Langage
    Réponses: 2
    Dernier message: 25/11/2005, 15h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo