Comment on supprime des lignes dans un fichier .ini ?????

sebaznar Messages postés 15 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 8 juin 2005 - 10 juin 2003 à 17:02
chasseurdedemon Messages postés 60 Date d'inscription mardi 23 décembre 2003 Statut Membre Dernière intervention 15 novembre 2010 - 1 juin 2005 à 14:46
Salut
Je voudrais supprimer des lignes dans un fichier .ini ...

Aidez moi SVP

bastou

4 réponses

Delbeke Messages postés 200 Date d'inscription jeudi 19 décembre 2002 Statut Membre Dernière intervention 18 novembre 2005
10 juin 2003 à 22:01
Voici un module qui emule les fonction savesetting,getsetting,deletesetting, getaallsetting.
les information ne sont pas stockée dans la base de registre mais dans un fichier ini

J'espère que çà aidera

Option Explicit

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
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Public Sub SaveSetting(AppName As String, Section As String, Key As String, Setting As String)
Dim lRet As Long
Dim Path As String
Path = App.Path
If Right(Path, 1) <> "" Then
Path = Path & ""
End If
lRet = WritePrivateProfileString(Section, Key, Setting, Path & AppName & ".ini")
End Sub
Public Function GetSetting(AppName As String, Section As String, Key As String, Optional Default As String) As String
Dim lRet As Long
Dim Path As String
Dim strTemp As String
strTemp = Space(32567)
Path = App.Path
If Right(Path, 1) <> "" Then
Path = Path & ""
End If
lRet = GetPrivateProfileString(Section, Key, Default, strTemp, Len(strTemp), Path & AppName & ".ini")
lRet = InStr(strTemp, Chr$(0))
If lRet = 0 Then
GetSetting = ""
Else
GetSetting = Left(strTemp, lRet - 1)
End If
End Function
Public Function GetAllSettings(AppName As String, Section As String) As Variant
Dim lRet As Long
Dim Path As String
Dim strTemp As String
Dim Table() As String
Dim Table2() As String
Dim iPnt As Integer
Dim iPnt2 As Integer
Dim iPosit As Integer
strTemp = Space(32567)
Path = App.Path
If Right(Path, 1) <> "" Then
Path = Path & ""
End If

lRet = GetPrivateProfileSection(Section, strTemp, Len(strTemp), Path & AppName & ".ini")
iPnt = 0
'For Redim+Preserve tables only the las index can be changed
If Left(strTemp, 2) = Chr$(0) & Chr$(0) Then
Exit Function
End If
Do While Left(strTemp, 1) <> Chr$(0)
ReDim Preserve Table(1, iPnt)
iPosit = InStr(strTemp, "=")
Table(0, iPnt) = Left$(strTemp, iPosit - 1)
strTemp = Mid$(strTemp, iPosit + 1)
iPosit = InStr(strTemp, Chr$(0))
Table(1, iPnt) = Left$(strTemp, iPosit - 1)
strTemp = Mid$(strTemp, iPosit + 1)
iPnt = iPnt + 1
Loop
ReDim Table2(iPnt - 1, 1)
For iPnt2 = 0 To iPnt - 1
Table2(iPnt2, 0) = Table(0, iPnt2)
Table2(iPnt2, 1) = Table(1, iPnt2)
Next
GetAllSettings = Table2
End Function
Public Function DeleteSetting(AppName As String, Section As String, Optional Key As String)
Dim lRet As Long
Dim Path As String
Path = App.Path
If Right(Path, 1) <> "" Then
Path = Path & ""
End If
If Key = "" Then
lRet = WritePrivateProfileString(Section, vbNullString, vbNullString, Path & AppName & ".ini")
Else
lRet = WritePrivateProfileString(Section, Key, vbNullString, Path & AppName & ".ini")
End If
End Function

Jean-Luc
0
sebaznar Messages postés 15 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 8 juin 2005
11 juin 2003 à 08:24
deja, merci

ton module, c'est du vb6 non???

tu connaitrais l'equivalent en vb .Net ???

bastou
0
Delbeke Messages postés 200 Date d'inscription jeudi 19 décembre 2002 Statut Membre Dernière intervention 18 novembre 2005
11 juin 2003 à 20:39
oui c'est du Vb classique
non je n'ai rien pour vb.net

Désolé

Jean-Luc
0
chasseurdedemon Messages postés 60 Date d'inscription mardi 23 décembre 2003 Statut Membre Dernière intervention 15 novembre 2010
1 juin 2005 à 14:46
vous pouvez donner des exmple, comment écrire, lire , supprimer une
ligne dans un fichier ini. parce que je ne c'est vraiment pas
comment on fais aprés qu'on a creer le module.

merci d'avence

cordialement


chasseur de demon
0
Rejoignez-nous