Charger un Fichier *.txt
Publié : jeu. 09/nov./2006 15:02
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
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