Things You'll Need:
- Computer
- Windows(98 or newer)
-
Step 1
Create a Text File
Create a text file with the following name at the following location.
C:\Temp\TextToRead.txt
Within the text file, add the following lines.
If you get this message,
you have successfully
completed this
programming task. -
Step 2
Open Notepad
Go to Start - All Programs - Accessories - Notepad
Save your file as C:\Temp\ReadTextFile.vbs -
Step 3
Copy Code
Copy and Paste the following code into Notepad.
'*****************************************************************
Option Explicit
Const conForReading = 1
'Declare variables
Dim objFSO, objReadFile, contents
'Set Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReadFile = objFSO.OpenTextFile("C:\Temp\TextToRead.txt", 1, False)
'Read file contents
contents = objReadFile.ReadAll
'Close file
objReadFile.close
'Display results
wscript.echo contents
'Cleanup objects
Set objFSO = Nothing
Set objReadFile = Nothing
'Quit script
WScript.Quit()
'******************************************************************
Save your file and exit Notepad -
Step 4
Success!Run Script
Double click on your ReadTextFile.vbs VBScript file.
You should get the window shown.
Select "OK"
Congratulations! You've written a VBScript capable of reading a text file.













