Comment atteindre l'enregistrement suivant

Résolu
blob73 Messages postés 55 Date d'inscription dimanche 15 août 2004 Statut Membre Dernière intervention 20 juin 2005 - 1 sept. 2004 à 23:26
blob73 Messages postés 55 Date d'inscription dimanche 15 août 2004 Statut Membre Dernière intervention 20 juin 2005 - 3 sept. 2004 à 17:13
Bonjour,

j'ai un fichier texte dans lequle j'enregistre des informations obtenues depuis un formulaire et une structure , lorque que réouvre le forumlaire j'arrive a afficher le premier enregistrement du fichier sans probleme mais je voudrais pouvoir lire le suivant quand je clique sur le bouton suivant et je n'y arrive pas !! et je voudrais egalement(il est chiant celui la il en veut des choses lol) prendre ne compte le numero du dernier enregistrement afin que le suivant corresponde au dernier numero+1

si vous pouviez m'aider ce serais gentil!!!

Merci bcp

4 réponses

cs_rene38 Messages postés 1858 Date d'inscription samedi 29 juin 2002 Statut Membre Dernière intervention 17 octobre 2013 11
2 sept. 2004 à 02:16
Bonjour
Fichier ouvert en mode Random
(As #NumFich et Enregistrement = la structure)
écrit avec Put ?

Lecture du 1er enregistrement :
Get NumFich, 1, Enregistrement

Lecture de l'enregistrement suivant :
Get NumFich, , Enregistrement

Numero du dernier enregistrement = LOF(NumFich) / Len(Enregistrement)
3
cs_EBArtSoft Messages postés 4525 Date d'inscription dimanche 29 septembre 2002 Statut Modérateur Dernière intervention 22 avril 2019 9
2 sept. 2004 à 09:34
Attention si c'est un fichier texte et que la longueur des champs
varie le code ne marche plus...

@+

E.B.
3
blob73 Messages postés 55 Date d'inscription dimanche 15 août 2004 Statut Membre Dernière intervention 20 juin 2005
2 sept. 2004 à 14:28
merci a tous les deux mais j'ai oublié de mettre que c'etait en vb.net excusez moi !!!

bon voila le code

1) la structure de l'enregistrement

Structure contacts
        Public num As String
        Public cat As String
        Public nom As String
        Public prenom As String
        Public adr As String
        Public vil As String
        Public cp As String
        Public digi As String
        Public tel As String
        Public mob As String
        Public fax As String
        Public mail As String
        Public adr2 As String
        Public vil2 As String
        Public cp2 As String
        Public digi2 As String
        Public tel2 As String
        Public fax2 As String
        Public comm As String
    End Structure
    Public contact(5000) As contacts
    Public nbrctc As Integer


2) l'enregistrement

 Public Sub ecritperson()

        With contact(nbrctc)
            .num = nbrctc
            .cat = Cbxcat.Text
            .nom = Textnom.Text
            .prenom = Textprénom.Text
            .adr = Textadr.Text
            .vil = TextVil.Text
            .cp = textcp.Text
            .digi = Textdig.Text
            .tel = TextPhone.Text
            .mob = TextMob.Text
            .fax = TextFax.Text
            .mail = Textmail.Text
            .adr2 = Textadr2.Text
            .vil2 = Textvil2.Text
            .cp2 = TextCp2.Text
            .digi2 = Textdigi2.Text
            .tel2 = Textphone2.Text
            .fax2 = Textfax2.Text
            .comm = Textcomments.Text
        End With

        Dim sr As StreamWriter = File.AppendText("\person.txt")

        sr.WriteLine(contact(nbrctc).num)
        sr.WriteLine(contact(nbrctc).cat)
        sr.WriteLine(contact(nbrctc).nom)
        sr.WriteLine(contact(nbrctc).prenom)
        sr.WriteLine(contact(nbrctc).adr)
        sr.WriteLine(contact(nbrctc).vil)
        sr.WriteLine(contact(nbrctc).cp)
        sr.WriteLine(contact(nbrctc).digi)
        sr.WriteLine(contact(nbrctc).tel)
        sr.WriteLine(contact(nbrctc).mob)
        sr.WriteLine(contact(nbrctc).fax)
        sr.WriteLine(contact(nbrctc).mail)
        sr.WriteLine(contact(nbrctc).adr2)
        sr.WriteLine(contact(nbrctc).vil2)
        sr.WriteLine(contact(nbrctc).cp2)
        sr.WriteLine(contact(nbrctc).digi2)
        sr.WriteLine(contact(nbrctc).tel2)
        sr.WriteLine(contact(nbrctc).fax2)
        sr.WriteLine(contact(nbrctc).comm)

        sr.Close()

    End Sub


3) la lecture du fichier

 Public Sub lecturectc()

        Dim sh As StreamReader = File.OpenText("\person.txt")

        With contact(nbrctc)
            nbrctc = .num
            Cbxcat.Text = .cat
            Textnom.Text = .nom
            Textprénom.Text = .prenom
            Textadr.Text = .adr
            TextVil.Text = .vil
            textcp.Text = .cp
            Textdig.Text = .digi
            TextPhone.Text = .tel
            TextMob.Text = .mob
            TextFax.Text = .fax
            Textmail.Text = .mail
            Textadr2.Text = .adr2
            Textvil2.Text = .vil2
            TextCp2.Text = .cp2
            Textdigi2.Text = .digi2
            Textphone2.Text = .tel2
            Textfax2.Text = .fax2
            Textcomments.Text = .comm
        End With

        nbrctc = sh.ReadLine
        Cbxcat.Text = sh.ReadLine
        Textnom.Text = sh.ReadLine
        Textprénom.Text = sh.ReadLine
        Textadr.Text = sh.ReadLine
        TextVil.Text = sh.ReadLine
        textcp.Text = sh.ReadLine
        Textdig.Text = sh.ReadLine
        TextPhone.Text = sh.ReadLine
        TextMob.Text = sh.ReadLine
        TextFax.Text = sh.ReadLine
        Textmail.Text = sh.ReadLine
        Textadr2.Text = sh.ReadLine
        Textvil2.Text = sh.ReadLine
        TextCp2.Text = sh.ReadLine
        Textdigi2.Text = sh.ReadLine
        Textphone2.Text = sh.ReadLine
        Textfax2.Text = sh.ReadLine
        Textcomments.Text = sh.ReadLine

        sh.Close()

    End Sub


Alors quand j'ouvre le formulaire il m'affiche bien le premier contact mais je n'arrive pas a naviguer c'est a dire a aller a l'enregistrement suivant ou précédent je pense(mais c'est pas sur sinon j'aurais la solution lol) que je ne doit pas enregistrer ma structure correctement )!!!

Merci de votre aide!!!
3
blob73 Messages postés 55 Date d'inscription dimanche 15 août 2004 Statut Membre Dernière intervention 20 juin 2005
3 sept. 2004 à 17:13
Re alors j'ai suivi vos conseils!!! mais j'arrive pas a relire du coup !!!

je conserbve la meme structure qu'au dessus pui voici le code de l'ecriture dans le fichier

Public Sub ecrire()
        FileOpen(1, "c:\person.txt", OpenMode.Binary)

        With contact(nbrctc)
            .num = nbrctc
            .cat = Cbxcat.Text & nbrctc
            .nom = Textnom.Text & nbrctc
            .prenom = Textprénom.Text & nbrctc
            .adr = Textadr.Text & nbrctc
            .vil = TextVil.Text & nbrctc
            .cp = textcp.Text & nbrctc
            .digi = Textdig.Text & nbrctc
            .tel = TextPhone.Text & nbrctc
            .mob = TextMob.Text & nbrctc
            .fax = TextFax.Text & nbrctc
            .mail = Textmail.Text & nbrctc
            .adr2 = Textadr2.Text & nbrctc
            .vil2 = Textvil2.Text & nbrctc
            .cp2 = TextCp2.Text & nbrctc
            .digi2 = Textdigi2.Text & nbrctc
            .tel2 = Textphone2.Text & nbrctc
            .fax2 = Textfax2.Text & nbrctc
            .comm = Textcomments.Text & nbrctc
            FilePut(1, contact)

        End With
        FileClose(1)

    End Sub


voici la lecture

 Public Sub lire()
        FileOpen(1, "C:\person.txt", OpenMode.Binary)
        With contact(nbrctc)
            nbrctc = .num
            Cbxcat.Text = .cat
            Textnom.Text = .nom
            Textprénom.Text = .prenom
            Textadr.Text = .adr
            TextVil.Text = .vil
            textcp.Text = .cp
            Textdig.Text = .digi
            TextPhone.Text = .tel
            TextMob.Text = .mob
            TextFax.Text = .fax
            Textmail.Text = .mail
            Textadr2.Text = .adr2
            Textvil2.Text = .vil2
            TextCp2.Text = .cp2
            Textdigi2.Text = .digi2
            Textphone2.Text = .tel2
            Textfax2.Text = .fax2
            Textcomments.Text = .comm
            FileGet(1, contact)
        End With
        FileClose(1)

    End Sub


et bien rien ne s'affiche dans me champs texte !!!! Helppp
3
Rejoignez-nous