Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: OuTLawZGoSu on January 13, 2004, 06:43 PM

Title: Why wont this work?
Post by: OuTLawZGoSu on January 13, 2004, 06:43 PM
I need to save a text file with this format in the name:
"  [<current time>] Saved Chat.txt   "

When I hit Save, the file doesent save.
What am I doing wrong?


Private Sub Save_Click()
Form1.rtb.SaveFile (App.Path & "[ " & Format(Time, "hh:mm:ss") & " ] " & "SavedChat.txt")
End Sub

Private Sub Load_Click()
Form8.cd1.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
Form8.cd1.ShowOpen
Form8.rtbload.LoadFile Form8.cd1.FileTitle
End Sub
Title: Re:Why wont this work?
Post by: K on January 13, 2004, 06:47 PM
One problem I see right of the bat is that you can't have colons in a file name. (or backslashes either, in case you're saving the date as well).  Try replacing them with dashes, commas, or periods.
Title: Re:Why wont this work?
Post by: OuTLawZGoSu on January 13, 2004, 07:13 PM
Form1.rtb.SaveFile App.Path & ("\[ " & Format(Time, "hh-mm-ss") & " ] " & "SavedChat.txt")

thx
Title: Re:Why wont this work?
Post by: CrAzY on January 14, 2004, 07:41 AM
Eh, your doing it all wrong.  You need to open a txt file there should be a code for that.  I forget it off the top of my head.
Title: Re:Why wont this work?
Post by: K on January 14, 2004, 10:41 AM
Quote from: CrAzY on January 14, 2004, 07:41 AM
Eh, your doing it all wrong.  You need to open a txt file there should be a code for that.  I forget it off the top of my head.

Actually, the Richtextbox control has a save method which will save its contents to a file.  Why do things the long way when you can do it like he's doing it?
Title: Re:Why wont this work?
Post by: Newby on January 15, 2004, 07:45 PM
Dim YOURFILENAME as String
YOURFILENAME = "ChannelLog.txt"

Open App.Path & YOURFILENAME for Append as #1
Print #1, TEXTTOPRINT
Close #1


There you go.
Title: Re:Why wont this work?
Post by: Stealth on January 15, 2004, 10:42 PM
Better to make YOURFILENAME a Const unless you'll be modifying it at runtime. Also, you named it like a constant -- all-uppercase name.
Title: Re:Why wont this work?
Post by: Newby on January 15, 2004, 11:24 PM
Well, I just put that there so he could copy/paste that and change the channel log name. :P

Unless you want me to o_O


Dim YOURFILENAME as String
becomes

Private Const YOURFILENAME = "ChannelLog.txt"
Title: Re:Why wont this work?
Post by: Ersan on January 16, 2004, 08:24 AM
You need to include a backslash before your filename, after App.Path

Dim YOURFILENAME as String
YOURFILENAME = "\ChannelLog.txt"
Open App.Path & YOURFILENAME for Append as #1
Print #1, TEXTTOPRINT
Close #1