Extraire du texte d'un fichier .ini

Résolu
comeochris Messages postés 51 Date d'inscription lundi 23 mai 2005 Statut Membre Dernière intervention 19 octobre 2014 - 29 sept. 2005 à 10:48
cs_nico1610 Messages postés 395 Date d'inscription jeudi 26 août 2004 Statut Membre Dernière intervention 19 juin 2009 - 29 sept. 2005 à 14:01
Bonjour,

Comment extraire le texte d'un fichier .ini dont la structure est celle-ci :

[enregistrement]
MODEL = N
ENTETE = c:\sci5\doc\modele\MERCICLI.ent
FICH_PRINC = MERCICLI.003
CHEDOC = c:\sci5\doc\05\09\MERCICLI.003
PRINCIPAL = MERCICLI.DOC
DONNEE = c:\sci5\doc\modele\MERCICLI.txt
FIC_A_CHARGER = c:\sci5\doc\modele\MERCICLI.DOC
TITRE_APP = Titre de l'appli
FONCTION = FUSION

Voilà, en fait, j'aimerais retrouver l'équivalent de l'instruction suivante :

FIC_A_CHARGER = WordBasic. [GetPrivateProfilestring$] ("enregistrement", "FIC_A_CHARGER", Chemin du Fichier .ini)

Quelqu'un peut-il m'aider ?
Merci d'avance.

Christophe

2 réponses

cs_nico1610 Messages postés 395 Date d'inscription jeudi 26 août 2004 Statut Membre Dernière intervention 19 juin 2009 1
29 sept. 2005 à 14:01
Dark Sidious à raison, tu n'as pas ouvert ton esprit au site VbFrance et tu na pas le savoir du fichier ini !!
La force tu as besoin, mais la route est long et tu aura besoin des connaissance du fichier ini !!
Yoda (alias nico1610) va te montrer le chemin, va donc te concentrer sur
/code.aspx?ID=33622http://www.vbfrance.com/code.aspx?ID=30552

Là quand tu serras aptes a manipuler la force tu serras, pour le moment regarde le module FichierIni.bas

Et que la force soit avec toi !!

NB : il y a des sources qui parle que et uniquement de ca , mais cette source et de moi c'est pour ca que je sais qu'il a y ce que tu cheches, de plus ce module est vraiment tres tres bien fais et gere au mieux les fichier ini !!

et voila le code : !!!!

<OL>
<LI>
Public
CheminBrowserIni As
String

<LI>
Public
CheminPlaylistIni As
String

<LI>
Public
NomSkinIni As
String

<LI>
Public
VolumeIni As Integer
<LI>
Public
RepeatIni As Boolean
<LI>
Public
RandomIni As Boolean
<LI>
<LI><SAMP>' Constantes</SAMP>
<LI>
Const
FIC_INI = <VAR>"\LecteurMP3.ini"</VAR>
<LI>
<LI><SAMP>'==========================================================================================</SAMP>
<LI><SAMP>' PROTOTYPES DES FONCTIONS API WINDOWS UTILISEES</SAMP>
<LI><SAMP>'==========================================================================================-</SAMP>
<LI>
Declare
Function
GetPrivateProfileInt Lib <VAR>"kernel32"</VAR> Alias <VAR>"GetPrivateProfileIntA"</VAR> (ByVal lpApplicationName As
String
, ByVal lpKeyName As
String
, ByVal nDefault As Long, ByVal lpFileName As
String
) As Long
<LI>
Declare
Function
GetPrivateProfileSection Lib <VAR>"kernel32"</VAR> Alias <VAR>"GetPrivateProfileSectionA"</VAR> (ByVal lpAppName As
String
, ByVal lpReturnedString As
String
, ByVal nSize As Long, ByVal lpFileName As
String
) As Long
<LI>
Declare
Function
GetPrivateProfileString Lib <VAR>"kernel32"</VAR> Alias <VAR>"GetPrivateProfileStringA"</VAR> (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
<LI>
Declare
Function
WriteProfileString Lib <VAR>"kernel32"</VAR> Alias <VAR>"WriteProfileStringA"</VAR> (ByVal lpszSection As
String
, ByVal lpszKeyName As
String
, ByVal lpszString As
String
) As Long
<LI>
Declare
Function
WritePrivateProfileString Lib <VAR>"kernel32"</VAR> Alias <VAR>"WritePrivateProfileStringA"</VAR> (ByVal lpApplicationName As
String
, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As
String
) As Long
<LI>
<LI><SAMP>'===================================================================================*/</SAMP>
<LI><SAMP>' fonctions fichier ini de base */</SAMP>
<LI><SAMP>'===================================================================================*/</SAMP>
<LI>
<LI>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI><SAMP>' GetIniInt : */</SAMP>
<LI><SAMP>'------------------------------------------------------------------------------------*/</SAMP>
<LI><SAMP>' Cette fonction permet de recuprer un nombre entier dans un fichier INI. */</SAMP>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI>
Function
GetIniInt(Rubriq$, motClef$, Default&, FicIni$) As Long
<LI>
<LI> GetIniInt = GetPrivateProfileInt(Rubriq$, motClef$, Default&, FicIni$)
<LI>
<LI>
End
Function

<LI>
<LI>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI><SAMP>' GetIniString : */</SAMP>
<LI><SAMP>'------------------------------------------------------------------------------------*/</SAMP>
<LI><SAMP>' Cette fonction permet de recuprer une chaine dans un fichier INI. */</SAMP>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI>
Function
GetIniString(Rubriq$, motClef$, Default$, FicIni$) As
String

<LI>
<LI>
Dim
titre As
String
* 1000
<LI>
Dim
pos As Integer
<LI>
<LI>GetPrivateProfileString Rubriq$, motClef$, Default$, titre, 1000, FicIni$
<LI>pos =
InStr
(titre,
Chr
(0))
<LI>
If
pos <> 0
Then

<LI> titre =
Left
(titre, pos - 1) <SAMP>' + Right(titre, Len(titre) - pos)</SAMP>
<LI>
End
If

<LI>GetIniString =
Trim
(titre)
<LI>
<LI>
End
Function

<LI>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI><SAMP>' WriteiniString : */</SAMP>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI><SAMP>' Cette fonction permet d'crire une chaine dans un fichier INI. */</SAMP>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI>
Function
WriteIniString(Rubriq$, key$, Value$, FicIni$) As Long
<LI>
If
Len
(Value) = 0
Then

<LI> WritePrivateProfileString Rubriq$, key$, Nothing, FicIni$
<LI>
Else

<LI> WritePrivateProfileString Rubriq$, key$, Value$, FicIni$
<LI>
End
If

<LI>
<LI> WriteIniString = 0
<LI>
<LI>
End
Function

<LI>
<LI><SAMP>'===================================================================================*/</SAMP>
<LI><SAMP>' fonction avec le fichier ini pour l'application</SAMP>
<LI><SAMP>'===================================================================================*/</SAMP>
<LI>
<LI>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI><SAMP>' LireParametreIni : */</SAMP>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI>
Sub
LireParametreIni()
<LI> CheminBrowserIni = GetIniString(<VAR>"CHEMIN"</VAR>, <VAR>"Browser"</VAR>, <VAR>""</VAR>, FIC_INI)
<LI> CheminPlaylistIni = GetIniString(<VAR>"CHEMIN"</VAR>, <VAR>"Playlist"</VAR>, <VAR>""</VAR>, FIC_INI)
<LI> NomSkinIni = GetIniString(<VAR>"PARAMETRES"</VAR>, <VAR>"NomSkin"</VAR>, <VAR>""</VAR>, FIC_INI)
<LI> VolumeIni = GetIniInt(<VAR>"PARAMETRES"</VAR>, <VAR>"Volume"</VAR>, 0, FIC_INI)
<LI> RepeatIni = GetIniString(<VAR>"PARAMETRES"</VAR>, <VAR>"Repeat"</VAR>, 0, FIC_INI)
<LI> RandomIni = GetIniString(<VAR>"PARAMETRES"</VAR>, <VAR>"Random"</VAR>, 0, FIC_INI)
<LI>
End
Sub

<LI><SAMP>'====================================================================================*/</SAMP>
<LI><SAMP>' EcrireCheminBrowserIni: */</SAMP>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI>
Sub
EcrireCheminBrowserIni()
<LI> WriteIniString <VAR>"CHEMIN"</VAR>, <VAR>"Browser"</VAR>, CheminBrowserIni, FIC_INI
<LI>
End
Sub

<LI><SAMP>'====================================================================================*/</SAMP>
<LI><SAMP>' EcrireCheminPlayListIni: */</SAMP>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI>
Sub
EcrireCheminPlayListIni()
<LI> WriteIniString <VAR>"CHEMIN"</VAR>, <VAR>"Playlist"</VAR>, CheminPlaylistIni, FIC_INI
<LI>
End
Sub

<LI><SAMP>'====================================================================================*/</SAMP>
<LI><SAMP>' EcrireParametresIni: */</SAMP>
<LI><SAMP>'====================================================================================*/</SAMP>
<LI>
Sub
EcrireParametresIni()
<LI> WriteIniString <VAR>"PARAMETRES"</VAR>, <VAR>"NomSkin"</VAR>, NomSkinIni, FIC_INI
<LI> WriteIniString <VAR>"PARAMETRES"</VAR>, <VAR>"Volume"</VAR>,
Str
(VolumeIni), FIC_INI
<LI> WriteIniString <VAR>"PARAMETRES"</VAR>, <VAR>"Random"</VAR>,
Str
(RandomIni), FIC_INI
<LI> WriteIniString <VAR>"PARAMETRES"</VAR>, <VAR>"Repeat"</VAR>,
Str
(RepeatIni), FIC_INI
<LI>
End
Sub
</LI></OL>
3
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
29 sept. 2005 à 11:10
Tu as cherché un peu avant de posté ta question ???


Voir les nombreuses sources parlant des fichiers ini sur le site.

_____________________________________________________________________
DarK Sidious

Un API Viewer (pour le VB, VB.NET, C, C# et Delphi) tout en français : www.ProgOtoP.com/popapi/
0
Rejoignez-nous