Classe pour la gestion des fichiers INI Windows

Classe pour la gestion des fichiers INI Windows

Messagepar oguruma » 19 Oct 2005 à 15:42

Bon allez vite fait, quelques bon vieux souvenirs de VB.
Au début la gestion des fichiers INI c'est un galère... pour se souvenir de la syntaxe, etc. etc.

une classe devrait suivre pour la gestion des fichiers ini Notes en utilisant les fonctions de l'objet NotesSession.

Cela dit l'accès au notes.ini est possible via cette classe mais on aura pas la distinction entre les variables système et non système.

Il faut aussi indiquer le chemin complet du fichier notes.ini ce qui peut être délicat si notes n'est pas installé de la même manière sur tous les postes.... ça arrive :P :oops: :cry:

[syntax="ls"]
'// Déclaration pour les fichiers INI personnalisé
Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (_
Byval lpAppName As String, _
Byval lpKeyName As String, _
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 lpAppName _
As String, Byval lpKeyName As String, Byval lpString As String, _
Byval lpFileName As String) As Long

Declare Function GetPrivateProfileIntA Lib "kernel32" (_
Byval sSectionName As String,_
Byval sKeyName As String, _
Byval lDefault As Long, _
Byval sFileName As String) As Long

'// Déclaration pour l'accès au win.ini
Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" _
(Byval sSectionName As String, _
Byval sKeyName As String, _
Byval sDefault As String, _
Byval sReturnedString As String, _
Byval lSize As Long) As Long

Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" _
(Byval sSectionName As String, _
Byval sKeyName As String, _
Byval sString As String) As Long

Declare Function GetProfileInt Lib "kernel32" Alias "GetProfileIntA" _
(Byval sSectionName As String, _
Byval sKeyName As String, _
Byval lDefault As Long) As Long

Public Class FileDotINI
Private FileName As String
Private win As Integer

Sub new(f As String)
FileName=Trim$(f)
If FileName="" Then
win=True
Else
win=False
End If
End Sub

Sub SetStringValue(section As String, keyword As String, value As String)
If Not win Then
WritePrivateProfileString section, keyword, value, FileName
Else
WriteProfileString section, keyword, value
End If
End Sub

Function GetStringValue(section As String, keyword As String, default As Variant) As String
Dim value As String * 255
Dim n As Integer
If Not win Then
n=GetPrivateProfileString (section, keyword, default, value, 255, filename)
Else
n=GetProfileString (section, keyword, default, value, 255)
End If
If n<>0 Then
GetStringValue=Left$(value,n)
Else
GetStringValue=""
End If
End Function

Function GetIntValue(section As String, keyword As String, default As Long) As Long
GetIntValue=GetPrivateProfileIntA(section,keyword,default,FileName)
End Function

End Class
[/syntax]

un petit exemple d'utilisation

[syntax="ls"]
Sub classini
Dim fdi As FileDotINI
Dim winfdi As FileDotINI
Set fdi=New FileDotINI("C:\ALPHA\Increm.ini")
Set winfdi=New FileDotINI("")
Msgbox fdi.GetStringValue("Numero","NUMERO",Date$)
Msgbox winfdi.GetStringValue("IRIS_IPE","menu","0")
Call fdi.SetStringValue("Numero","NUMERO",Cstr(Now))
Call winfdi.SetStringValue("IRIS_IPE","menu","100")
Msgbox fdi.GetStringValue("Numero","NUMERO",Date$)
Msgbox winfdi.GetStringValue("IRIS_IPE","menu","18")
End Sub
[/syntax]
Bien à vous

http://www.dominoarea.org/oguruma/

Les téléphones PORTABLES dans les TGV y en a MARRRE de ces voyageurs qui ne respectent pas les autres ! ARRET DES PORTABLES SVP - Merci

Fumeurs ! respectez les non fumeurs !!!
Fumeurs ! respectez la loi de février 2007 et les lieux publics !!! (ie. hall de gares)
Avatar de l’utilisateur
oguruma
Super V.I.P.
Super V.I.P.
 
Message(s) : 4086
Inscrit(e) le : 16 Déc 2004 à 08:50
Localisation : LILLE

Retour vers API