Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read Last Created Text File to InputBox

Status
Not open for further replies.

Nu2Java

Technical User
Jun 5, 2012
166
US
Hello,

I am trying to understand how to read a text line to an inputbox. I have this code that will create the text file from the inputbox, but then I want to read that same line when I run the script again. I keep getting an error that says "Input past end of file". I am sure I have something out of order.... any help would be great!

Code:
Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNeeded = true
set fso = CreateObject("Scripting.FileSystemObject")
set file = fso.OpenTextFile("output.txt", ForWriting, CreateIfNeeded)
dim fname


Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\\temp\\output.txt",1)
strText = objFileToRead.ReadAll()

fname = inputbox("Enter some text", strText)
Set objFileToRead = Nothing


file.write fname
objFileToRead.Close
file.close
 
Hello Geates,

I am trying to learn how to create and read text files. What I want this script to do is open with the inputbox, ask for input and then save that input to a text file. When I run the script again, I want the inputbox to read in the line of text that was last stored in that text file as the default text.

I hope I am making sense.
 
Code:
[blue]Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNeeded = True

Set fso = CreateObject("Scripting.FileSystemObject")

With fso.OpenTextFile("C:\temp\output.txt", ForReading, CreateIfNeeded)
    If Not .AtEndOfStream Then strText = .ReadAll()
End With

fname = InputBox("Enter some text", , strText)
If fname <> "" Then fso.OpenTextFile("c:\temp\output.txt", ForWriting).write fname[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top