|
-
Apr 6th, 2008, 05:03 AM
#1
Thread Starter
PowerPoster
[RESOLVED] How To Get Data From A TXT File?
I have made a simple text file user-defined at run-time. I have two Text Boxes called "Text1" and "Text2". I then need the filename, without the file extension to be placed in Text1. And in Text2, what is inside the simple text file.
-
Apr 6th, 2008, 05:09 AM
#2
Re: How To Get Data From A TXT File?
Code:
Dim sFileName As String
Dim s As String
sFileName = "C:\test.txt"
Text1.Text = Left$(sFileName, Len(sFileName) - 4) ' -4 for .txt
'OPen file and grab all contents
Open sFileName For Input As #1
s = Input(LOF(1), 1)
Close #1
Text2.Text = s
-
Apr 6th, 2008, 05:10 AM
#3
Junior Member
Re: How To Get Data From A TXT File?
Ok. If it's the same as what i am thinking then you would have to do "FSO" as that is the one way i can say will be easy for you
add this code to a new module
Code:
'Declare FileSystemObject Script Variables (FSOSV)
Public FSO As New FileSystemObject
Public F As File
Public fol As Folder
Then this code for opening
Code:
Text1.Text = FSO.OpenTextFile(App.Path & "\database\catalogue\pages.txt", ForReading).ReadAll
Edit the code, and add the refrences of microsoft scriptlet libery =]
Is your name George? 
-
Apr 6th, 2008, 11:59 AM
#4
Fanatic Member
Re: How To Get Data From A TXT File?
 Originally Posted by ThEiMp
I have made a simple text file user-defined at run-time. I have two Text Boxes called "Text1" and "Text2". I then need the filename, without the file extension to be placed in Text1. And in Text2, what is inside the simple text file.
Well i think lintz solved your problem except one little thing.
Your file name you are opening is sFileName = Text1.Text & ".txt" because you said you want to enter file path without extension. And if you enter C:\Test in your textbox you must later add ext. to open the file
-
Apr 6th, 2008, 06:44 PM
#5
Thread Starter
PowerPoster
Re: How To Get Data From A TXT File?
I am getting an error called, in the following lines of code...
Error: Text1.Text = Left$(sFileName, Len(sFileName) - 4)
The error called is error code '5'.
And yes, I have been able to fix up the file extension that was inside the code, I got from the last post I got. And that I don't think is the problem with this code. Because that code doesn't get executed until this line of code with the error in it, gets executed.
-
Apr 6th, 2008, 08:20 PM
#6
Re: How To Get Data From A TXT File?
What is value is 'sFileName'?
My example worked fine for me
-
Apr 6th, 2008, 08:22 PM
#7
Re: How To Get Data From A TXT File?
 Originally Posted by Dungeon Keeper
Your file name you are opening is sFileName = Text1.Text & ".txt" because you said you want to enter file path without extension.
I interpreted the initial question as he already knew the file name and wanted to display it in Text1 but without the extension...
-
Apr 6th, 2008, 08:29 PM
#8
Thread Starter
PowerPoster
Re: How To Get Data From A TXT File?
Bye the way... The value of sFileName is found inside "Form4.Text1.Text".
-
Apr 6th, 2008, 08:31 PM
#9
Thread Starter
PowerPoster
Re: How To Get Data From A TXT File?
Yes. I want to input the data into Text1. But get the program to add the extension of *.TXT onto it after you click OK, which is found in the Form.
-
Apr 6th, 2008, 08:48 PM
#10
Re: How To Get Data From A TXT File?
Oh OK. Try this.
Code:
Sub Command1_Click()
Dim sFileName As String
Dim s As String
sFileName = Text1.Text & ".txt"
'OPen file and grab all contents
Open sFileName For Input As #1
s = Input(LOF(1), 1)
Close #1
Text2.Text = s
End Sub
-
Jan 9th, 2009, 09:47 AM
#11
Hyperactive Member
Re: How To Get Data From A TXT File?
Hi, i have tried lintz' code and it works. But when i try to edit it and apply it in my program, i get an error :Run time error '62' Input past end of line. May i know what is the problem?
Code:
Private Sub Command1_Click()
Dim sFileName As String
Dim s As String
sFileName = "C:\Documents and Settings\All Users\Application Data\BVRP Software\mobile PhoneTools\document\recu0006.SMS"
Text1.Text = Left$(sFileName, Len(sFileName) - 4) ' -4 for .txt
'OPen file and grab all contents
Open sFileName For Input As #1
s = Input(LOF(1), 1)
Close #1
Text2.Text = s
End Sub
Basically, i just change the path. My file is .SMS extension but it can be opened by using notepad. Is this cause the problem?
I'm still on the path of learning.... 
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
|