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.
Printable View
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.
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
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
Then this code for openingCode:'Declare FileSystemObject Script Variables (FSOSV)
Public FSO As New FileSystemObject
Public F As File
Public fol As Folder
Edit the code, and add the refrences of microsoft scriptlet libery =]Code:Text1.Text = FSO.OpenTextFile(App.Path & "\database\catalogue\pages.txt", ForReading).ReadAll
Well i think lintz solved your problem except one little thing.Quote:
Originally Posted by ThEiMp
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 :D
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.
What is value is 'sFileName'?
My example worked fine for me :D
I interpreted the initial question as he already knew the file name and wanted to display it in Text1 but without the extension...Quote:
Originally Posted by Dungeon Keeper
Bye the way... The value of sFileName is found inside "Form4.Text1.Text".
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.
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
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?
Basically, i just change the path. My file is .SMS extension but it can be opened by using notepad. Is this cause 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