Bonjour.
J'ai repris un code donné sur un ancien post.
Comment le modifier pour que l'utilisateur puise choisir lui meme le chemin ou se trouve le fichier et puise charger un fichier ayant n'importe quel nom ?. ( *.txt )
Dans l'exemple on charge toujour du repertoire c:\fichier.txt
===================
Procedure.s FileToString(FileName.s)
Protected file.l, string.s
file = ReadFile(#PB_Any, FileName)
If file
string = Space(Lof(file))
ReadData(file, @string, Lof(file))
CloseFile(file)
EndIf
ProcedureReturn string
EndProcedure
If OpenWindow(0, 0, 0, 960, 600, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
EditorGadget(0, 8, 8, 380, 540)
EndIf
SetGadgetText(0, FileToString("c:\fichier.txt"))
Repeat
EventID = WindowEvent()
Select EventID
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
EndIf
==================
Bonne journée à tous
Charger un Fichier *.txt
- Progi1984
- Messages : 2659
- Inscription : mar. 14/déc./2004 13:56
- Localisation : France > Rennes
- Contact :
Regarde du coté de OpenFileRequester !
Librairies & Applications : https://www.purebasic.fr/french/viewtop ... f=8&t=6220
Site Web : https://rootslabs.net
Site Web : https://rootslabs.net
Voilà le code!
Salut, voilà ton code modifier pour charger nimporte quel fichier *.txt.
Voilà @+++.
Code : Tout sélectionner
Procedure.s FileToString(FileName.s)
Protected file.l, string.s
file = ReadFile(#PB_Any, FileName)
If file
string = Space(Lof(file))
ReadData(file, @string, Lof(file))
CloseFile(file)
EndIf
ProcedureReturn string
EndProcedure
If OpenWindow(0, 0, 0, 960, 600, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
EditorGadget(0, 8, 8, 380, 540)
EndIf
If CreateMenu(0,WindowID(0))
MenuItem(0,"&Charger un fichier")
EndIf
Repeat
EventID = WindowEvent()
Select EventID
Case #PB_Event_Menu
Select EventMenu()
Case 0
SetGadgetString(1, FileToString(OpenFileRequester("Sellectionner le fichier à charger.", "", "*.txt|*.txt", 0))
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
EndIf
Le minimun quand on donne un code c'est de le tester avant ...
En voici un qui fonctionn ene version 4 !
En voici un qui fonctionn ene version 4 !
Code : Tout sélectionner
Enumeration
#Win0
#BP0
#Editor_0
EndEnumeration
Procedure.s FileToSting(File.s)
OpenFile(1,File)
Txt.s=""
Rc.s = Chr(13)+Chr(10)
While Not Eof(1)
Txt.s+ReadString(1)+ Rc
Wend
CloseFile(1)
ProcedureReturn Txt
EndProcedure
Procedure Open_Win0()
If OpenWindow(#Win0, 404, 62, 1011, 771, "Editeur Simple", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#Win0))
ButtonGadget(#BP0, 30, 10, 80, 30, "Ouvrir Fichier")
EditorGadget(#Editor_0, 30, 50, 960, 690)
EndIf
EndIf
EndProcedure
Open_Win0()
Repeat
Event = WaitWindowEvent()
GadgetID = EventGadget()
If Event = #PB_Event_Gadget
If GadgetID = #BP0
File.s=OpenFileRequester("Selection du fichier à éditer","*.*","*.txt",1)
SetGadgetText(#Editor_0,FileToSting(File))
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
End
Denis
Bonne Jounée à tous
Bonne Jounée à tous