I want to save the text in a text area as a file, but im having troubles.
here is the code
window = CreateWindow( "Test",0,0,640,480,0,11 )
CentreGadget(Window)
menu=WindowMenu (window)
file=CreateMenu("&File",0,menu)
CreateMenu "Open",1,file
CreateMenu "Save",1,file
UpdateWindowMenu window
txtbox = CreateTextArea (20,20,500,300,window)
Repeat
ID = WaitEvent(15)
If ID=$803 Then End
If ID=$1001 Then
EID=EventData()
Select EID
Case 1 Gosub open
Case 2 Gosub save
End Select
End If
Forever
.open
filz$=RequestFile$( "Pick a file!","txt, dat, qst" )
txt=ReadFile(filz$)
While Not Eof(txt)
r$=ReadLine(txt)
r$=r$+Chr$(13)
AddTextAreaText(txtbox,r)
Wend
CloseFile txt
Return
.save
txt= TextAreaText(txtbox,r)
While Not Eof(txt)
r$=ReadLine(txt)
r$=r$+Chr$(13)
WriteFile("quest.txt")
Wend
Return
Function CentreGadget(G, Group = -1)
If Group = -1 Then Group = Desktop()
CX = ClientWidth(Group) / 2 : CY = ClientHeight(Group) / 2
SetGadgetShape G, CX - (GadgetWidth(G)/2), CY - (GadgetHeight(G)/2), GadgetWidth(G), GadgetHeight(G)
End Function
here is the code
window = CreateWindow( "Test",0,0,640,480,0,11 )
CentreGadget(Window)
menu=WindowMenu (window)
file=CreateMenu("&File",0,menu)
CreateMenu "Open",1,file
CreateMenu "Save",1,file
UpdateWindowMenu window
txtbox = CreateTextArea (20,20,500,300,window)
Repeat
ID = WaitEvent(15)
If ID=$803 Then End
If ID=$1001 Then
EID=EventData()
Select EID
Case 1 Gosub open
Case 2 Gosub save
End Select
End If
Forever
.open
filz$=RequestFile$( "Pick a file!","txt, dat, qst" )
txt=ReadFile(filz$)
While Not Eof(txt)
r$=ReadLine(txt)
r$=r$+Chr$(13)
AddTextAreaText(txtbox,r)
Wend
CloseFile txt
Return
.save
txt= TextAreaText(txtbox,r)
While Not Eof(txt)
r$=ReadLine(txt)
r$=r$+Chr$(13)
WriteFile("quest.txt")
Wend
Return
Function CentreGadget(G, Group = -1)
If Group = -1 Then Group = Desktop()
CX = ClientWidth(Group) / 2 : CY = ClientHeight(Group) / 2
SetGadgetShape G, CX - (GadgetWidth(G)/2), CY - (GadgetHeight(G)/2), GadgetWidth(G), GadgetHeight(G)
End Function