Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft VBScript runtime error: Bad file mode

Microsoft VBScript runtime error: Bad file mode

Microsoft VBScript runtime error: Bad file mode

Trying to create the following script and keep getting a Bad File Mode error. Can someone help me. I'm not much of a programmer and I'm banging my head against the wall. The error is on the line that reads:
Do Until ipFileObj.AtEndOfStream = True

In order to run the script you have to create a file called IP_Addresses.csv. Thank you for any help!

' Defining constants
const READ = 1
const WRITE = 2
const APPEND = 8
const ASCII = 0

' Defining variables and initializing
dim fileName, ipAddrStr, newRoom, comp1_IP, comp2_IP, comp3_IP, comp4_IP
fileName = "IP_Addresses.csv"
ipAddrStr = ""
newRoom = "106"
comp1_IP = ""
comp2_IP = ""
comp3_IP = ""
comp4_IP = ""

' Creating ASCII text file and overwriting
Set fso = CreateObject("Scripting.FileSystemObject")
ipAddrStr = _
newRoom & ",1," & comp1_IP & vbCrLf & _
newRoom & ",2," & comp2_IP & vbCrLf & _
newRoom & ",3," & comp3_IP & vbCrLf & _
newRoom & ",4," & comp4_IP & vbCrLf

'Append New Room Information to File
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FileExists(fileName) Then
WScript.StdOut.WriteLine(Chr(7) & Chr(7)),0, False
WScript.StdOut.WriteLine("File Does Not Exit!!!" & vbCrlf & _
"You Must Create the File Before You can Read the File!!")
End If
Set ipFileObj = fso.OpenTextFile(fileName,APPEND,ASCII)

' Read and write IPs file
Set ipFileObj = fso.OpenTextFile(fileName,APPEND,ASCII)

' Read file one line at a time displaying room, computer, and IP
Do Until ipFileObj.AtEndOfStream = True

room = ipFileObj.Read(3)
computer = ipFileObj.Read(1)
ipAddress = ipFileObj.Read(13)
WScript.Echo "The IP Address in Room "& room &" for Computer " & computer& " is " &ipAddress


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close