|
-
Nov 20th, 2007, 12:38 AM
#1
Thread Starter
New Member
creating a text file
Hi all,
I am trying to create a text file in VB, but getting an error ...
User -defned type not defined. suggest me ...
Code:
Private Sub Command1_Click()
Dim FS As New FileSystemObject
Dim Stream As TextStream
Set Stream = FS.CreateTextFile(App.Path & "\ashoks.txt", True)
Stream.Close
End Sub
Thanks....
-
Nov 20th, 2007, 12:47 AM
#2
Lively Member
Re: creating a text file
This is adding the time and date to it, so that it's a completely unique file. Hope it helps
vb Code:
Private Sub Command2_Click()
Dim frfile As Long
Dim filetimedate As String
frfile = FreeFile
filetimedate = Format(Now(), "(mm dd yyyy) (hh-mm-ss)")
Open App.Path & "\log" & filetimedate & ".txt" For Output As #frfile
Print #frfile, Text1.Text
Close #frfile
Text1.Text = ""
End Sub
-
Nov 20th, 2007, 01:06 AM
#3
Thread Starter
New Member
Re: creating a text file
yeah thats working, thanks.
but what is the difference b/w above and this process
how to implemet same with above functions.
Thanks...
-
Nov 20th, 2007, 04:17 AM
#4
Re: creating a text file
to use FSO you need to add a reference to microsoft scripting runtime
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 20th, 2007, 06:56 AM
#5
Re: creating a text file
 Originally Posted by westconn1
to use FSO you need to add a reference to microsoft scripting runtime
The lack of this reference is what cause your error.
-
Nov 21st, 2007, 02:17 AM
#6
Thread Starter
New Member
Re: creating a text file
From above replies I realise that I need to add FSO reference to my code, but i am not aware of the same. please update below code with FSO reference ....
Code:
Private Sub Command1_Click()
Dim FS As New FileSystemObject
Dim Stream As TextStream
Set Stream = FS.CreateTextFile(App.Path & "\ashoks.txt", True)
Stream.Close
End Sub
Compile erroe: User -defned type not defined
Thanks....
-
Nov 21st, 2007, 02:39 AM
#7
Frenzied Member
Re: creating a text file
To add Microsoft Scripting Runtime, click on Projects->References and set the ref to it
-
Nov 22nd, 2007, 01:41 AM
#8
Thread Starter
New Member
Re: creating a text file
Dear all,
I got the solution for above problem. here is solution
Code:
Private Sub Command1_Click()
Call myfile
End Sub
Public Sub myfile()
Set myFSO = CreateObject("Scripting.FileSystemObject")
'Dim ts As TextStream
Set ts = myFSO.CreateTextFile(App.Path & "\ashok.txt", True)
'ts.Close
'Set ts = myFSO.OpenTextFile(App.Path & "\ashok.txt", Forwriting, True)
ts.WriteLine "hi ashok"
ts.WriteLine "bye ashok"
ts.Close
End Sub
Thanks to all....
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
|