enregistrer dans un fichier (utilisation des pointers ???)

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
SpaceMan
Messages : 290
Inscription : mar. 26/oct./2004 19:35
Contact :

enregistrer dans un fichier (utilisation des pointers ???)

Message par SpaceMan »

je veux faire une application qui enregistre le nom prenom et numero de phone dans un fichier.
La fenetre est composée de 3 boites de saisies et des boutons "enregistrer"
et "afficher dernier enregistrement".
:( j'ai lu les tutos sur les pointeurs mais je ne suis toujours pas
capable de faire grande chose avec.
Merci d'avance à vous :)
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

des pointeurs ? pour enregistrer dans un fichier ?

moi, je fais dans ce style la :

c'est simple et efficace. et largement suffisant pour ce style d'application
tu charges la liste au début du prog
tu fais tes modif dessus
et tu l'enregistres

Code : Tout sélectionner

Structure InfoListe
  Nom.s
  Prenom.s
  Tel.l
EndStructure
NewList Liste.InfoListe()


Procedure Charger()
  OpenPreferences("Test.txt")
  n = 0
  Repeat
    n + 1
    Nom.s = ReadPreferenceString(Str(n) + "-Nom", "")
    If Nom
      AddElement(Liste())
      Liste()\Nom = Nom
      Liste()\Prenom = ReadPreferenceString(Str(n) + "-Prenom", "")
      Liste()\Tel = ReadPreferenceLong(Str(n) + "-Tel", 0)
    EndIf
  Until Nom = ""
  ClosePreferences()
EndProcedure

Procedure Sauver()
  If CreatePreferences("Test.txt")
    n = 0
    ForEach Liste()
      n + 1
      WritePreferenceString(Str(n) + "-Nom", Liste()\Nom)
      WritePreferenceString(Str(n) + "-Prenom", Liste()\Prenom)
      WritePreferenceLong(Str(n) + "-Tel", Liste()\Tel)
    Next
    ClosePreferences()
  EndIf
EndProcedure

Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
SpaceMan
Messages : 290
Inscription : mar. 26/oct./2004 19:35
Contact :

y a pas plus simple

Message par SpaceMan »

:D je crois qu'on ne pas pas rever mieux c'est cool de ta part :D
bernard13
Messages : 1221
Inscription : mer. 05/janv./2005 21:30

Message par bernard13 »

spaceman
je peux 'taider
j'ai faus aussi un programme de genre où tu peux modifier la liste en cours ..
SpaceMan
Messages : 290
Inscription : mar. 26/oct./2004 19:35
Contact :

Message par SpaceMan »

ok Bernard13 tu es le bienvenu je prends tout ce qui peut m'aider
Merci
Un défaut qui empêche les hommes d’agir, c’est de ne pas sentir de quoi ils sont capables.
Jacques Bénigne Bossuet
bernard13
Messages : 1221
Inscription : mer. 05/janv./2005 21:30

Message par bernard13 »

salut spaceman

voici un bout de code non fini
tu peux crée une liste et la modifier ensuite
les fonction charger et sauver n'ont pas ete ecrite
car ce que faire c'est un juste un bout de code pour modifier une liste
ce programme me sert d'exemple
j'ai appris a crée des bout de code d'exemple pour avoir ensuite a piocher dedans .





Code : Tout sélectionner

;Repertoire telephonie 
; par Jbernard13 écris le 01/01/2005

; contanste des fenetres 

Enumeration
  #main_0
  #fenetre_1
  #fenetre_2 
EndEnumeration

;constante des gadgets
Enumeration
   #liste
  #frame_0
  #text_nom
  #string_nom
  #text_prenom
  #string_prenom
  #text_telephone
  #string_telephone 
  #button_ajoute
  #button_annule
  #button_modifie
EndEnumeration

; barre du menu 
Enumeration
 
  #barre_New
  #barre_Charger
  #barre_Sauver
  #barre_efface
  #barre_info
  EndEnumeration





; Chargement des fonts
Global FontID1
FontID1 =LoadFont(1,"arial",11,#PB_Font_Bold)
Global fontId2
fontId2 =LoadFont(2,"arial",12,#PB_Font_Bold)
Global fontID3
fontID3=LoadFont(3,"arial",11)

; creation d'un élément 

Structure carnet
  Nom.s
  Prenom.s
  Telephone.s
EndStructure
NewList items.carnet()

Procedure.b item_clear()
  ClearList(items ())
EndProcedure
Procedure.b item_add()
  If  AddElement(items())
    items()\Nom=GetGadgetText(#string_nom)
    items()\Prenom=GetGadgetText(#string_prenom)
    items()\Telephone=GetGadgetText(#string_telephone)
    AddGadgetItem(#liste,-1,items()\Nom+Chr(10)+items()\Prenom+Chr(10)+items()\Telephone)
  EndIf
  ProcedureReturn 1
EndProcedure
;Modification d'un element de la liste  
Procedure item_modifie(index,Nom.s,Prenom.s,Telephone.s)
  indexcourant=ListIndex(items())
  SelectElement(items(),index)
  items()\Nom=Nom
  items()\Prenom=Prenom
  items()\Telephone=Telephone
  SelectElement(items(),indexcourant)
EndProcedure




; effacement d'un element de la liste 
Procedure remove()
  effacer=0
  If GetGadgetItemState(#liste,effacer)&#PB_ListIcon_Checked 
    MessageRequester("Merlin vous informe que ", "L'élément sera supprimer ", #MB_OK|#MB_ICONINFORMATION)
    RemoveGadgetItem(#liste,effacer)
  EndIf
EndProcedure





;procdeure des fenetres 

Procedure main()
  If OpenWindow(#main_0,0,0,800,600,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered,"Carnet de telephone")
    If CreateToolBar(0, WindowID()) 
       ToolBarStandardButton(#barre_New,#PB_ToolBarIcon_New)
       ToolBarStandardButton(#barre_Charger,#PB_ToolBarIcon_Open )
       ToolBarStandardButton(#barre_Sauver,#PB_ToolBarIcon_Save)
       ToolBarStandardButton(#barre_efface,#PB_ToolBarIcon_Delete)
       ToolBarStandardButton(#barre_info,#PB_ToolBarIcon_Properties)
       ToolBarToolTip(#barre_New,"Creation d'une nouveau élément pour la liste en cours")
       ToolBarToolTip(#barre_Charger,"Charge une liste")
       ToolBarToolTip(#barre_Sauver ,"Sauve une liste")
       ToolBarToolTip(#barre_efface ," Efface un élément de la liste en le cochant ")
       ToolBarToolTip(#barre_info,"Information")
      
   
    EndIf
    If CreateGadgetList(WindowID())
       ListIconGadget(#liste,10,54,780,535,"Nom :",250, #PB_ListIcon_CheckBoxes| #PB_ListIcon_GridLines   )
      AddGadgetColumn(#liste,1,"Prenom :",250)
      AddGadgetColumn(#liste,2,"Téléphone :",276)
      SetGadgetFont(#liste,FontID1)
    
    
    EndIf
    
  EndIf
EndProcedure
Procedure ajouter()
  If OpenWindow(#fenetre_1,0,0,400,300,#PB_Window_ScreenCentered,"Crée une nouvelle entrée dans la liste")
    
    If CreateGadgetList(WindowID())
      Frame3DGadget(#frame_0,10,5,380,280,"")
      TextGadget(#text_nom,130,30,140,30,"Nom : ",#PB_Text_Center)
      SetGadgetFont(#text_nom,fontId2)
      StringGadget(#string_nom,80,55,250,25,"")
      SetGadgetFont(#string_nom,fontID3)    
      TextGadget(#text_prenom,130,90,140,30,"Prénom : ",#PB_Text_Center)
      SetGadgetFont(#text_prenom,fontId2)
      StringGadget(#string_prenom,80,115,250,25,"")
      SetGadgetFont(#string_prenom,fontID3)
      TextGadget(#text_telephone,130,155,140,30,"Téléphone: ",#PB_Text_Center)
      SetGadgetFont(#text_telephone,fontId2)
      StringGadget(#string_telephone,80,180,250,25,"",#PB_String_Numeric)
      SetGadgetFont(#string_telephone,fontID3)
      ButtonGadget(#button_ajoute,50,240,100,30,"Ajouter")
      SetGadgetFont(#button_ajoute,fontId2)
      ButtonGadget(#button_annule,250,240,100,30,"Annuler")
      SetGadgetFont(#button_annule,fontId2)
      
      
      Repeat
        event=WaitWindowEvent()
        Select event
          Case #PB_EventGadget
            Select EventGadgetID()
              Case#button_ajoute:item_add()
                fermer_window_1=1
                
              Case #button_annule: fermer_window_1=1
            EndSelect
        EndSelect
      Until  fermer_window_1=1
      CloseWindow(#fenetre_1)
      While WindowEvent():Wend
      
      
      
      
    EndIf
    
  EndIf
  
EndProcedure
;fenetre de modification 
Procedure modifier(index)
  If OpenWindow(#fenetre_2,0,0,400,300,#PB_Window_ScreenCentered,"modification")
    
    If CreateGadgetList(WindowID())
      Frame3DGadget(#frame_0,10,5,380,280,"")
      TextGadget(#text_nom,130,30,140,30,"Nom : ",#PB_Text_Center)
      SetGadgetFont(#text_nom,fontId2)
      StringGadget(#string_nom,80,55,250,25,"")
      SetGadgetFont(#string_nom,fontID3)
      TextGadget(#text_prenom,130,90,140,30,"Prénom : ",#PB_Text_Center)
      SetGadgetFont(#text_prenom,fontId2)
      StringGadget(#string_prenom,80,115,250,25,"")
      SetGadgetFont(#string_prenom,fontID3)
      TextGadget(#text_telephone,130,155,140,30,"Téléphone: ",#PB_Text_Center)
      SetGadgetFont(#text_telephone,fontId2)
      StringGadget(#string_telephone,80,180,250,25,"",#PB_String_Numeric)
      SetGadgetFont(#string_telephone,fontID3)
      ButtonGadget(#button_modifie,50,240,100,30,"Modifier")
      SetGadgetFont(#button_modifie,fontId2)
      ButtonGadget(#button_annule,250,240,100,30,"Annuler")
      SetGadgetFont(#button_annule,fontId2)
      SelectElement(items(),index)
      SetGadgetText(#string_nom,items()\Nom)
      SetGadgetText(#string_prenom,items()\Prenom)
      SetGadgetText(#string_telephone,items()\Telephone)
      Repeat
        event=WaitWindowEvent()
        Select event
          Case #PB_EventGadget
            Select EventGadgetID()
              Case #button_modifie
                a.s = GetGadgetText(#string_nom) 
                b.s = GetGadgetText(#string_prenom) 
                c.s = GetGadgetText(#string_telephone) 
                If a <> "" And b <> "" And c <> "" 
                  SetGadgetItemText(#liste, index, a, 0) 
                  SetGadgetItemText(#liste, index, b, 1) 
                  SetGadgetItemText(#liste, index, c, 2) 
                  item_modifie(index, a.s, b.s, c.s) 
                  EndIf
                fermer_window_2=1
                
              Case #button_annule: fermer_window_2=1
            EndSelect
        EndSelect
      Until  fermer_window_2=1
      CloseWindow(#fenetre_2)
      While WindowEvent():Wend
      
      
      
      
    EndIf
    
  EndIf
  
EndProcedure

; boucle du programme 

main()



Repeat
  event=WaitWindowEvent()
  Select event
    Case#PB_EventMenu
      Select EventMenuID()
        Case#barre_New:ajouter()
        Case #barre_efface:remove()
        Case #barre_info:MessageRequester("Information ", "Carnet telephone  version 01 " + Chr(10) + "écris par Jean-Bernard Copyright 2005 ", #MB_OK|#MB_ICONINFORMATION)
          
          EndSelect
    
    
    Case #PB_EventGadget
      Select EventGadgetID()
        
        Case #liste
          Select EventType ()
            
            Case #PB_EventType_LeftDoubleClick
              element=GetGadgetState(#liste)
              If element>-1
                modifier(element)
                
              EndIf
          EndSelect
          
          
          
      EndSelect
      
      
      
      
      
    Case #PB_EventCloseWindow
      fermer_window_0=1
  EndSelect
Until  fermer_window_0=1
End

  
SpaceMan
Messages : 290
Inscription : mar. 26/oct./2004 19:35
Contact :

thank

Message par SpaceMan »

j'ai parcouru ton code et je pense vraiment qu'avec le tien et celui de Soldat inconnu je dois pouvoir m'ensorti. je prendrai le temps de bien l'étudier apres mon examen (je passe un dps) le 31/05/05

:D que serait le forum s'il n'ya avait pas des gens comme vous
bernard13
Messages : 1221
Inscription : mer. 05/janv./2005 21:30

Message par bernard13 »

bonn chance spaceman
si tu as un probleme pour ton code
n'hesiste pas a m'ecrire en mp
SpaceMan
Messages : 290
Inscription : mar. 26/oct./2004 19:35
Contact :

de retour

Message par SpaceMan »

En effet bernard13 mon examen s'est bien passé et me voici de retour
j'ai pu crée un bout de code grace au tien et celui de Soldat inconnu le seul probleme que j'ai c'est que je n'arrive pas à charger mes enregistrement
:oops: j'essaie de resoudre un probleme que me pose linux
je vais mettre le code en ligne.
Répondre