|
-
May 11th, 2005, 08:11 AM
#1
Thread Starter
Junior Member
saving a text box as text with todays date
Does anybody have any idea on how to automatically save a text box as text with the file name as todays date.
thanks
Last edited by bparker; May 11th, 2005 at 03:57 PM.
Reason: Solved
-
May 11th, 2005, 08:18 AM
#2
Re: saving a text box as text with todays date
Well automatically depends on when you want to do this. But here's the code, to call it simply pass the TextBox you want to be saved as an argument. This will save the text in the same folder as the application and the name of the file will be in this format yyyymmdd.txt.
VB Code:
Public Function SaveText(txtBox As TextBox) As Boolean
Dim hFile As Integer
Dim sFileName As String
On Error Resume Next
hFile = FreeFile
sFileName = App.Path & "\" & Format(Now, "yyyymmdd") & ".txt"
Open sFileName For Output As #hFile
Print #hFile, txtBox.Text
Close #hFile
SaveText = (Err.Number = 0)
End Function
-
May 11th, 2005, 08:22 AM
#3
Thread Starter
Junior Member
Re: saving a text box as text with todays date
I want to save it by clicking a button
-
May 11th, 2005, 08:30 AM
#4
Fanatic Member
Re: saving a text box as text with todays date
Private Sub Command1_Click
Call SaveText
end sub
sir loin
-
May 11th, 2005, 08:32 AM
#5
Re: saving a text box as text with todays date
Well it would then be:
VB Code:
Private Sub Command1_Click()
Call SaveText(Text1)
End Sub
If the text box is named Text1 that is.
-
May 11th, 2005, 08:52 AM
#6
Thread Starter
Junior Member
Re: saving a text box as text with todays date
its not working
this is what I have
VB Code:
Public Function SaveText(txtBox As TextBox) As Boolean
Dim hFile As Integer
Dim sFileName As String
On Error Resume Next
hFile = FreeFile
sFileName = App.Path & "C:\My Documents\" & Format(Now, "yyyymmdd") & ".txt"
Open sFileName For Output As #hFile
Print #hFile, Text1.Text
Close #hFile
End Function
Private Sub Command1_Click()
Call SaveText(Text1)
End Sub
Private Sub Text1_Change()
End Sub
-
May 11th, 2005, 09:41 AM
#7
Thread Starter
Junior Member
Re: saving a text box as text with todays date
-
May 11th, 2005, 01:10 PM
#8
Re: saving a text box as text with todays date
The problem is the line where you set the path:
VB Code:
sFileName = App.Path & "C:\My Documents\" & Format(Now, "yyyymmdd") & ".txt"
App.Path returns the path to where you're application is installed or where your project file is stored if you're running from inside the VB IDE. So let's say you have your program in "C:\MyVBProject" that means that you're trying to create a file in C:\MyVBProjectC:\My Documents\20050511.txt and that will of course not work. If you want to use c:\My Documents\ then remove App.Path.
-
May 11th, 2005, 03:57 PM
#9
Thread Starter
Junior Member
Re: saving a text box as text with todays date
Thanks a lot for the help
I works perfect now
-
May 11th, 2005, 04:13 PM
#10
Re: saving a text box as text with todays date
Just want to point out that the code has been mosdified from its original intent. That is, to pass a TextBox (any) to the function and have that data saved out.
Currently, the line in error is:
and should be:
VB Code:
Print #hFile, [b]txtBox[/b].Text
In the current function, the "Public Function SaveText(txtBox As TextBox) As Boolean"
is being passed the Object, but not being used in the function the way it was intended.
Bruce.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|