Enregistrement chemin et fichiers dans un ini et recherche dans fichier ini

nanard - 25 nov. 2001 à 18:19
cs_Steff Messages postés 34 Date d'inscription vendredi 9 novembre 2001 Statut Membre Dernière intervention 29 mars 2007 - 2 janv. 2002 à 17:04
Bonjour à tous
J’ai créé une appli sous VB5, et je voudrai que l’utilisateur l’installe, mais que le CD soit obligatoire pour la recherche des fichiers .
Comment examiner les lecteurs pour la présence des fichiers, enregistrer le chemin dans un « ini » et la recherche dans le
Fichier « ini ».
Exemple de codes SVP.
merci

1 réponse

cs_Steff Messages postés 34 Date d'inscription vendredi 9 novembre 2001 Statut Membre Dernière intervention 29 mars 2007
2 janv. 2002 à 17:04
Salut,

cree un module et colle ce code dedans.

Attribute VB_Name = "Module1"
Function lectureINI(rubr As String, motclef As String, nom_file As String) As String
Dim pos1, pos2, pos3
canal = FreeFile
Open nom_file For Input As canal
Do Until EOF(canal)
Line Input #canal, nextline
inivar = inivar + nextline + vbCrLf
Loop
Close canal
lectureINI = vbNullString
rubr = "[" + rubr + "]"
pos1 = InStr(1, inivar, rubr) + Len(rubr) + 2
motclef = motclef + "="
pos2 = InStr(pos1, inivar, motclef) + Len(motclef)
pos3 = InStr(pos2, inivar, Chr(13))
lectureINI = Mid(inivar, pos2, pos3 - pos2)
End Function
Function EcritureINI(rubr As String, motclef As String, param As String, nom_file As String) As String

nb_ligne = 0
Dim canal As Byte
canal8 = FreeFile
Open nom_file For Input As canal8
Do Until EOF(canal8)
Line Input #canal8, nextline
inivar = inivar + nextline + vbCrLf
nb_ligne = nb_ligne + 1
Loop
Close canal8

rubr = "[" + rubr + "]"
motclef = motclef + "="
'test pour voir si la clef existe
If (InStr(1, inivar, rubr) <> 0) Then
pos1 = InStr(1, inivar, rubr) + Len(rubr) + 2
'test pour voir si le mot clef existe
If (InStr(pos1, inivar, motclef) <> 0) Then
'le mot clef existe
pos2 = InStr(pos1, inivar, motclef) + Len(motclef)
pos3 = InStr(pos2, inivar, Chr(13))
'modification de la clef existante
inivar = Left(inivar, pos2 - 1) + param + Mid(inivar, pos3)
Else
'Le mot clef n'existe pas
'rechcerche du début de rubrique suivant
pos2 = InStr(pos1, inivar, "[", 1)
If pos2 = 0 Then
'la rubrique suivante n'existe pas
lg = Len(inivar)
stop_loop = False
Do
car = Mid(inivar, lg - 1, 1)
If (car <> Chr(10)) And (car <> Chr(13)) Then
stop_loop = True
End If
lg = lg - 1
Loop Until stop_loop = True
'creation d'une nouvelle clef en fin de fichier
inivar = Left(inivar, lg - 1) + vbCrLf + motclef + param + vbCrLf
Else
'la rubrique suivante existe
lg = pos2
stop_loop = False
Do
car = Mid(inivar, lg - 1, 1)
If (car <> Chr(10)) And (car <> Chr(13)) Then
stop_loop = True
End If
lg = lg - 1
Loop Until stop_loop = True
'creation d 'une nouvelle clef dans le fichier
inivar = Left(inivar, lg - 1) + vbCrLf + motclef + param + vbCrLf + vbCrLf + Mid(inivar, pos2)
End If
End If
Else
'La nouvelle rubrique n'existe pas. Création en fin de fichier
'd'une nouvelle rubrique et d'une nouvelle clef.
inivar = inivar + rubr + vbCrLf + motclef + param + vbCrLf
End If

canal = FreeFile
Open nom_file For Output As canal
Print #canal, inivar
Close canal
End Function

Pour l'utilisation, c'est pas sorcier. Je pense que tu comprendras aisaiment.
0
Rejoignez-nous