thierrydelepine
Messages postés521Date d'inscriptionmardi 24 décembre 2002StatutMembreDernière intervention11 septembre 2008
-
7 nov. 2004 à 13:58
Scofield 60
Messages postés2Date d'inscriptionsamedi 9 juin 2007StatutMembreDernière intervention 9 juin 2007
-
9 juin 2007 à 18:44
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.
Scofield 60
Messages postés2Date d'inscriptionsamedi 9 juin 2007StatutMembreDernière intervention 9 juin 2007 9 juin 2007 à 18:44
je te met 10 c'est exactement ce que je voulait !
(Je ne voulais pas passé par un module)
trcdl
Messages postés78Date d'inscriptionjeudi 25 septembre 2003StatutMembreDernière intervention25 juin 2007 27 févr. 2007 à 21:19
merci , mais depuis 3 ans j'ai oublié cette source , cordialement , Did
zonebleue
Messages postés73Date d'inscriptionsamedi 15 janvier 2005StatutMembreDernière intervention16 octobre 2007 27 févr. 2007 à 18:01
ca va, je te met 8/10 pour t'encourager ;)
@+
objectifweb
Messages postés25Date d'inscriptionmardi 22 décembre 2009StatutMembreDernière intervention 6 janvier 2010 27 sept. 2005 à 17:27
Bonjour,
Tu aurais la même chose pour vb.net ?
Il aime pas le As Any etc.... quel namespace etc...
Amicalement
Patrick
trcdl
Messages postés78Date d'inscriptionjeudi 25 septembre 2003StatutMembreDernière intervention25 juin 2007 7 nov. 2004 à 17:51
oups !! ça c'est du commentaire ....
merci pour le 8
amicalement
did
thierrydelepine
Messages postés521Date d'inscriptionmardi 24 décembre 2002StatutMembreDernière intervention11 septembre 20086 7 nov. 2004 à 13:58
bof,
tu met ca dans un module et tu as tout plein de fonction toutes pretes, c'est mieux je trouve :
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 WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function LireINI(Fichier As String, Entete As String, Variable As String) As String
Dim retour As String
retour = String(255, Chr(0))
LireINI = Left$(retour, GetPrivateProfileString(Entete, ByVal Variable, "", retour, Len(retour), Fichier))
End Function
Public Function EcrireINI(Fichier As String, Entete As String, Variable As String, Valeur As String) As String
'Fonction pour supprimer une valeur dans un fichier INI
Public Function DeleteVariableINI(Fichier As String, Entete As String, Variable As String) As String
DeleteVariableINI = WritePrivateProfileString(Entete, Variable, 0&, Fichier)
End Function
'Fonction pour supprimer une section dans un fichier INI
Public Function DeleteSectionINI(FichierINI As String, Section As String)
Dim a As Long
Dim i As Long
Dim Lettre As String
Dim Ligne As String
Dim Found As String
Dim INI As String
Dim Detect As Boolean
Dim LongeurChaine As Long
Detect = True
i = 0
a = FreeFile()
Open FichierINI For Input As #a
While Not EOF(a)
Line Input #a, Ligne
Lettre = Left(Ligne, 1)
If Lettre = "[" Then
i = i + 1
Found = InStr(Ligne, "[" & Section & "]")
If Found 0 Then INI INI & vbCrLf & Ligne: Detect = True Else Detect = False
ElseIf Lettre <> "" And Lettre <> "[" Then
If Detect = True Then
Found = InStr(Ligne, "=")
If Found <> 0 Then INI = INI & vbCrLf & Ligne
End If
ElseIf Lettre "" Then INI INI & vbCrLf
End If
Wend
Close #a
LongeurChaine = Len(INI)
Open FichierINI For Output As a
If LongeurChaine = 0 Then
Print #a, INI
Else
Print #a, Right(INI, LongeurChaine - 2)
End If
Close a
End Function
'Fonction pour eviter les trous dans une suite de section d'un fichier INI
'ou les numeros doivent se suivrent
'NB la variable d'entrée Sectino doit comproter le nom de la section sans son numero
'exemple pour [MONPC:PRINTER1] fournir section = MONPC:PRINTER
Public Function ReorganiseSectionINI(FichierINI As String, Section As String)
Dim a As Long
Dim i As Long
Dim Lettre As String
Dim Ligne As String
Dim Found As String
Dim INI As String
Dim Detect As Boolean
Dim LongeurChaine As Long
Detect = True
i = 1
a = FreeFile()
Open FichierINI For Input As #a
While Not EOF(a)
Line Input #a, Ligne
Found = InStr(1, Ligne, "[" & Section, vbTextCompare)
If Found = 1 Then
INI = INI & vbCrLf & "[" & Section & i & "]"
i = i + 1
Else
INI = INI & vbCrLf & Ligne
End If
Wend
Close #a
LongeurChaine = Len(INI)
Open FichierINI For Output As a
If LongeurChaine = 0 Then
Print #a, INI
Else
Print #a, Right(INI, LongeurChaine - 2)
End If
Close a
End Function
9 juin 2007 à 18:44
(Je ne voulais pas passé par un module)
27 févr. 2007 à 21:19
27 févr. 2007 à 18:01
@+
27 sept. 2005 à 17:27
Tu aurais la même chose pour vb.net ?
Il aime pas le As Any etc.... quel namespace etc...
Amicalement
Patrick
7 nov. 2004 à 17:51
merci pour le 8
amicalement
did
7 nov. 2004 à 13:58
tu met ca dans un module et tu as tout plein de fonction toutes pretes, c'est mieux je trouve :
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 WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function LireINI(Fichier As String, Entete As String, Variable As String) As String
Dim retour As String
retour = String(255, Chr(0))
LireINI = Left$(retour, GetPrivateProfileString(Entete, ByVal Variable, "", retour, Len(retour), Fichier))
End Function
Public Function EcrireINI(Fichier As String, Entete As String, Variable As String, Valeur As String) As String
EcrireINI = WritePrivateProfileString(Entete, Variable, Valeur, Fichier)
End Function
'Fonction pour supprimer une valeur dans un fichier INI
Public Function DeleteVariableINI(Fichier As String, Entete As String, Variable As String) As String
DeleteVariableINI = WritePrivateProfileString(Entete, Variable, 0&, Fichier)
End Function
'Fonction pour supprimer une section dans un fichier INI
Public Function DeleteSectionINI(FichierINI As String, Section As String)
Dim a As Long
Dim i As Long
Dim Lettre As String
Dim Ligne As String
Dim Found As String
Dim INI As String
Dim Detect As Boolean
Dim LongeurChaine As Long
Detect = True
i = 0
a = FreeFile()
Open FichierINI For Input As #a
While Not EOF(a)
Line Input #a, Ligne
Lettre = Left(Ligne, 1)
If Lettre = "[" Then
i = i + 1
Found = InStr(Ligne, "[" & Section & "]")
If Found 0 Then INI INI & vbCrLf & Ligne: Detect = True Else Detect = False
ElseIf Lettre <> "" And Lettre <> "[" Then
If Detect = True Then
Found = InStr(Ligne, "=")
If Found <> 0 Then INI = INI & vbCrLf & Ligne
End If
ElseIf Lettre "" Then INI INI & vbCrLf
End If
Wend
Close #a
LongeurChaine = Len(INI)
Open FichierINI For Output As a
If LongeurChaine = 0 Then
Print #a, INI
Else
Print #a, Right(INI, LongeurChaine - 2)
End If
Close a
End Function
'Fonction pour eviter les trous dans une suite de section d'un fichier INI
'ou les numeros doivent se suivrent
'NB la variable d'entrée Sectino doit comproter le nom de la section sans son numero
'exemple pour [MONPC:PRINTER1] fournir section = MONPC:PRINTER
Public Function ReorganiseSectionINI(FichierINI As String, Section As String)
Dim a As Long
Dim i As Long
Dim Lettre As String
Dim Ligne As String
Dim Found As String
Dim INI As String
Dim Detect As Boolean
Dim LongeurChaine As Long
Detect = True
i = 1
a = FreeFile()
Open FichierINI For Input As #a
While Not EOF(a)
Line Input #a, Ligne
Found = InStr(1, Ligne, "[" & Section, vbTextCompare)
If Found = 1 Then
INI = INI & vbCrLf & "[" & Section & i & "]"
i = i + 1
Else
INI = INI & vbCrLf & Ligne
End If
Wend
Close #a
LongeurChaine = Len(INI)
Open FichierINI For Output As a
If LongeurChaine = 0 Then
Print #a, INI
Else
Print #a, Right(INI, LongeurChaine - 2)
End If
Close a
End Function