nach1973
Messages postés8Date d'inscriptiondimanche 11 septembre 2005StatutMembreDernière intervention11 novembre 2005
-
12 oct. 2005 à 17:54
cs_rt15
Messages postés3874Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention 7 novembre 2014
-
12 oct. 2005 à 19:36
Bonjour je test l'ouverture et enregistrement de fichier.
Quand je regarde dans le fichier mais enregistrement sont décalé. Je ne vois pas ou est le probleme
Option Explicit
Private Type TMot ' Structure des données en interne et en externe
strTitre As String * 50
strAuteur As String * 50
strEditeur As String * 50
End Type
Dim Mot As TMot ' Variable de traitement des données
Dim NrCanal As Integer ' Numéro du canal d'accès à tout fichier à l'ouverture
Dim NrFich As Integer ' Numéro du canal d'accès à un fichier ouvert
Dim NBRec As Long ' Nombre d'enregistrements
Dim FNMot As String ' Nom du fichier avec chemin d'accès
Private Sub OuvreFichier()
NrCanal = FreeFile
NrFich = NrCanal
Open FNMot For Random As NrCanal Len = Len(Mot)
NBRec = FileLen(FNMot) / Len(Mot)
End Sub
Private Sub BAjout_Click()
If Not ChkRecord Then Exit Sub
Mot.strTitre = txtTitre
Mot.strAuteur = txtAuteur
Mot.strEditeur = txtEditeur
NBRec = NBRec + 1
Put NrFich, NBRec, Mot
AffichageAJour NBRec
txtTitre = ""
txtAuteur = ""
txtEditeur = ""
txtTitre.SetFocus
End Sub
Private Sub BModif_Click()
If Not ChkRecord Then Exit Sub
Mot.strTitre = txtTitre
Mot.strAuteur = txtAuteur
Mot.strEditeur = txtEditeur
If Val(TNrRec) > 0 Then
Put NrFich, Val(TNrRec), Mot
AffichageAJour Val(TNrRec)
txtTitre.SetFocus
Else
BAjout_Click
End If
End Sub
Private Sub BEff_Click()
Dim i As Long
Dim j As Long
i = Val(TNrRec)
j = i
If i > 0 Then
While i < NBRec
Get NrFich, i + 1, Mot
Put NrFich, i, Mot
i = i + 1
Wend
NBRec = NBRec - 1
End If
AffichageAJour j
txtTitre.SetFocus
End Sub
Private Sub FermeFichier()
Dim i As Long
If NBRec < 1 Then
Close NrFich
Kill FNMot
Else
If NBRec < FileLen(FNMot) / Len(Mot) Then
NrCanal = FreeFile
Open "{~Mot~}.tmp" For Random As NrCanal Len = Len(Mot)
For i = 1 To NBRec
Get NrFich, i, Mot
Put NrCanal, i, Mot
Next i
Close NrCanal
Close NrFich
Kill FNMot
Name "{~Mot~}.tmp" As FNMot
Else
Close NrFich
End If
End If
End Sub
Private Sub Form_Load()
CDialFichier.DialogTitle = "Sélection du fichier"
CDialFichier.DefaultExt = "Txt"
CDialFichier.Filter = "*.dat|*.txt"
CDialFichier.ShowOpen
FNMot = CDialFichier.FileName
If CDialFichier.CancelError Or FNMot = "" Then End
If Dir(FNMot) > "" Then
OuvreFichier
Else
If MsgBox("Créer le fichier ?", vbYesNo, "Attention") = vbYes Then
OuvreFichier
Else
End
End If
End If
End Sub
Private Sub BPrec_Click()
Dim i As Long
i = Val(TNrRec)
If i > 1 Then
i = i - 1
Else
i = NBRec
End If
If NBRec > 0 Then Get NrFich, i, Mot
AffichageAJour i
End Sub
Private Sub BSuiv_Click()
Dim i As Long
i = Val(TNrRec)
If i < NBRec Then
i = i + 1
Else
i = 1
End If
If NBRec > 0 Then Get NrFich, i, Mot
AffichageAJour i
End Sub
Private Sub Form_Activate()
TNbRec = NBRec
If NBRec > 0 Then
Get NrFich, 1, Mot
TNrRec = 1
txtTitre = Mot.strTitre
txtAuteur = Mot.strAuteur
txtEditeur = Mot.strEditeur
BSuiv.SetFocus
Else
txtTitre = ""
txtAuteur = ""
txtEditeur = ""
txtTitre.SetFocus
End If
End Sub
Private Sub AffichageAJour(AAJ As Long)
TNbRec = NBRec
If NBRec = 0 Then
txtTitre = ""
txtAuteur = ""
txtEditeur = ""
Else
TNrRec = AAJ
txtTitre = Mot.strTitre
txtAuteur = Mot.strAuteur
txtEditeur = Mot.strEditeur
End If
End Sub
Private Function ChkRecord() As Boolean
If txtTitre < " " Or txtAuteur < " " Or txtEditeur < " " Then
MsgBox "Encodage incomplet", , "Contrôle"
ChkRecord = False
Else
ChkRecord = True
End If
End Function
Private Sub BFin_Click()
FermeFichier
End
End Sub