Writing a .txt file...
Blitz3D Forums/Blitz3D Beginners Area/Writing a .txt file...
| ||
| Hey, i'm making a code generator for my project, so some of my idiot friends can help me :)... basicly, the friends read and click buttons ect to make the code, then they press save, and it writes the real code to a .txt file, that they give me, and i put in the code. VIA copy and paste. using the awsome Winb3d for basic windows GUI, i need to know the process of creating and editing .txt files... i know it has somthing to do with WriteFile() ect ect, the process is unknown to me though :o any ideas |
| ||
| Look up WriteFile in the Command Ref, it'll help. I promise. |
| ||
| interesting, also WriteLine begins a new line and types into it, i think this may be it. i'll look into it and test it. |
| ||
Also if you go:
WriteFile("filename.bb")
it will make a blitzbasic file |
| ||
| so far so good. but a problem with adding to it, it won't.. it seems like it pasting over it.. creation process is fine. Creation function: [WORKS]
Function WriteCode()
code=WriteFile(WB3D_GetGadgetText(pickedfilename)+".txt")
WriteLine(code,WB3D_GetGadgetText(handl)+".list = New list")
WriteLine(code,WB3D_GetGadgetText(handl)+"\name="+Chr(34)+WB3D_GetGadgetText(name)+Chr(34))
WriteLine(code,"")
WriteLine(code,"")
CloseFile(code)
End Function
and the add process... [Broken :(]
Function AddToCode()
If FileType(WB3D_GetGadgetText(pickedfile)+".txt")=1
code2=OpenFile(WB3D_GetGadgetText(pickedfile)+".txt")
WriteLine(code2,WB3D_GetGadgetText(handl)+".list = New list")
WriteLine(code2,WB3D_GetGadgetText(handl)+"\name="+Chr(34)+WB3D_GetGadgetText(name)+Chr(34))
WriteLine(code2,"")
WriteLine(code2,"")
CloseFile(code2)
doesnotex=0
Else
doesnotex=1
End If
End Function
somthing i'm missing? the Wb3d_GetGadgetText(handle) functions are from WinBlitz3d, it gets what a user typed in, tested that these arent the problem.. any idea? |
| ||
| you need to SeekFile() to the end of the file before writing more data. kev |
| ||
| Hmm, how does that work? in the docs it shows how to navigate ints... not strings... how do i get to the end of the file (ie start adding more) |
| ||
in = OpenFile("test.txt")
If in > 0 Then
While Not Eof(in)
pos$ = ReadLine(in)
file_offset = file_offset + Len(pos$)+2
Wend
SeekFile in,file_offset
WriteLine in,"new line"
CloseFile in
EndIf
not sure if this would be the correct way but it does work, create a .txt file add some text to it. kev |
| ||
| Thanks, it looks like its working |