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 6 et antérieur Discussion :

renvoyer toutes les section d'un fichier .ini


Sujet :

VB 6 et antérieur

  1. #1
    Nouveau Candidat au Club
    Inscrit en
    Novembre 2004
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Novembre 2004
    Messages : 3
    Points : 1
    Points
    1
    Par défaut renvoyer toutes les section d'un fichier .ini
    Comment utiliser "GetPrivateProfileString" pour renvoyer toutes les section d'un fichier de type .ini?

  2. #2
    Candidat au Club
    Inscrit en
    Août 2003
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Août 2003
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    Je ne pense pas que ce sois possible par contre tu peux très bien lire tout ton fichier .ini et quand une ligne commence par la caractère c'est que c'est le début d'une section.

    C'est un peu laborieux mais là je vois que ça.

  3. #3
    Membre éclairé
    Avatar de Catbull
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    542
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 542
    Points : 854
    Points
    854
    Par défaut
    Tu peux utiliser l'api GetPrivateProfileSectionNames.

  4. #4
    Candidat au Club
    Inscrit en
    Août 2003
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Août 2003
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    C'est bon à savoir Catbull.

    Connaissait pas. Merci

  5. #5
    Membre éclairé
    Avatar de Catbull
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    542
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 542
    Points : 854
    Points
    854
    Par défaut
    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
    Private Declare Function GetPrivateProfileSectionNames Lib "kernel32" Alias "GetPrivateProfileSectionNamesA" ( _
            ByVal lpszReturnBuffer As String, _
            ByVal nSize As Long, _
            ByVal lpFileName As String) As Long
     
    Public Function ListeSection(Path As String, Section() As String)
        Dim strReturn As String
        strReturn = String(255, 0)
     
        GetPrivateProfileSectionNames strReturn, Len(strReturn), Path
     
        Section = Split(Left(strReturn, InStr(1, strReturn, Chr(0) & Chr(0)) - 1), Chr(0))
    End Function
     
    Public Sub MainSection()
        Dim Section() As String
     
        ListeSection "C:\test.ini", Section
        For Index = LBound(Section) To UBound(Section)
            Debug.Print "-" & Section(Index) & "-"
        Next
    End Sub

  6. #6
    Nouveau Candidat au Club
    Inscrit en
    Novembre 2004
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Novembre 2004
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    Merci beaucoup

  7. #7
    Nouveau Candidat au Club
    Inscrit en
    Novembre 2004
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Novembre 2004
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    Est il possible d'avoir le même type de fonction qui renvoie toutes les clés d'une section donnée dans un fichier ini???

  8. #8
    Membre à l'essai
    Inscrit en
    Mars 2003
    Messages
    20
    Détails du profil
    Informations forums :
    Inscription : Mars 2003
    Messages : 20
    Points : 13
    Points
    13
    Par défaut
    Hum ça fait longtemps que la question a été posée mais si quelqu'un peut me dire si il existe une fonction permettant de récupérer toutes les clés d'une section donnée d'un ficheir INI ça me serait bien utile

    Merci!

  9. #9
    Membre à l'essai
    Inscrit en
    Mars 2003
    Messages
    20
    Détails du profil
    Informations forums :
    Inscription : Mars 2003
    Messages : 20
    Points : 13
    Points
    13
    Par défaut
    Si quelqu'un est intéressé j'ai modifié une fonction que j'ai trouvée sur internet. Elle renvoie une string contenant tout les clés d'un section séparées par ";" (pratique pour source de combobox) :

    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
     
    Public Function GetSectionKeys(section As String)
    Dim pos As Long 'current position in section
    Dim nextPos As Long 'next position in section
    Dim currentKey As String 'current key retreived in section
    Dim sourceKeys As String 'keys in source string
     
    Dim buffer As String 'buffer to retrieve the section
    Dim size As String 'buffer size
    Dim retCode As Integer 'return code of GetPrivateProfileString to handle errors
    Dim INISection As String 'the complete section
     
        'retrieve the complete section
        buffer = Space$(8192)
        size = Len(buffer)
        retCode = GetPrivateProfileString(section, 0&, "default", buffer, size, configPath) 'all the keys in the section
        If (size > 0) Then
            INISection = Left$(buffer, retCode)
        Else
            INISection = ""
        End If
     
        'retrieve keys inside INISection
        If (Len(INISection) > 0) Then
            pos = 1
            nextPos = InStr(pos, INISection, Chr$(0)) 'nextPos = next new line in INISection
            Do While nextPos <> 0 'for all the lines in the section
                currentKey = Mid$(INISection, pos, (nextPos - pos)) 'retrieve the key
                If (currentKey <> Chr$(0)) Then 'add the key to sourceKeys
                    sourceKeys = sourceKeys & ";" & Mid$(INISection, pos, (nextPos - pos))
                    pos = nextPos + 1
                    nextPos = InStr(pos, INISection, Chr$(0))
                End If
            Loop
     
            'delete the first ";" in sourceKeys
            Dim length As Integer
            length = Len(sourceKeys) - 1
            sourceKeys = Right$(sourceKeys, length)
            GetSectionKeys = sourceKeys
        Else 'empty INISection
            GetSectionKeys = ""
        End If
    End Function
    Désolé pour les commentaires en anglais, je programme pour des anglophones Il faut bien sûr avoir déclaré la fonction GetPrivateProfileString auparavant comme expliqué dans la FAQ et dans ce sujet.

    Tchuss!

Discussions similaires

  1. Vb.Net Lire toutes les sections d'un fichier INI
    Par Magdix dans le forum VB.NET
    Réponses: 8
    Dernier message: 21/01/2009, 17h12
  2. Réponses: 5
    Dernier message: 27/08/2008, 15h29
  3. Lire toutes les sections d'un fichier INI
    Par soso78 dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 17/10/2007, 09h09
  4. Fusionner toutes les lignes d'un fichier
    Par _Mac_ dans le forum Linux
    Réponses: 2
    Dernier message: 02/12/2005, 14h18
  5. fichier ini -> recuperer toute les sections
    Par abignon dans le forum MFC
    Réponses: 2
    Dernier message: 08/04/2004, 18h46

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