1

I'm taking a scripting class and im having some issues with my script. According to the lab assignment all my syntax is correct. However i keep getting a input past end of file error on line 60,1. I've starred at the program forever and checked all lines letter for letter for quite some time with no luck. Any help would be greatly appreciated. Here is the script.

 dim ipAddress(5,3)
 ipAddress(0,0)="192.168.10.11"
 ipAddress(0,1)="192.168.10.12"
 ipAddress(0,2)="192.168.10.13"
 ipAddress(0,3)="192.168.10.14"
 ipAddress(1,0)="192.168.10.19"
 ipAddress(1,1)="192.168.10.20"
 ipAddress(1,2)="192.168.10.21"
 ipAddress(1,3)="192.168.10.22"
 ipAddress(2,0)="192.168.10.27"
 ipAddress(2,1)="192.168.10.28"
 ipAddress(2,2)="192.168.10.29"
 ipAddress(2,3)="192.168.10.30"
 ipAddress(3,0)="192.168.10.35"
 ipAddress(3,1)="192.168.10.36"
 ipAddress(3,2)="192.168.10.37"
 ipAddress(3,3)="192.168.10.38"
 ipAddress(4,0)="192.168.10.43"
 ipAddress(4,1)="192.168.10.44"
 ipAddress(4,2)="192.168.10.45"
 ipAddress(4,3)="192.168.10.46"
 ipAddress(5,0)="192.168.10.51"
 ipAddress(5,1)="192.168.10.52"
 ipAddress(5,2)="192.168.10.53"
 ipAddress(5,3)="192.168.10.54" 

const READ = 1
const WRITE = 2
const APPEND = 8
const ASCII = 0

dim fileName
fileName = "IP_Addresses.csv"
dim ipAddrStr
ipAddrStr = ""
dim fso
Set fso = Wscript.CreateObject("Scripting.FileSystemObject") 
Set ipFileObj = fso.CreateTextFile(fileName,True,ASCII)

For room = 0 to 5
  For computer = 0 to 3
    ipAddrSr = CStr(room+100) & "," & CStr(computer+1) & "," ipAddress(room,computer)
     & vbCrlf
    ipFileObj.write(ipAddrStr)
  Next
Next

ipFileObj.close

Set ipFileObj = fso.OpenTextFile(fileName,READ,ASCII)
WScript.Echo ipFileObj.ReadAll **' this is line 60**
ipFileObj.Close
David
  • 15,894
  • 22
  • 55
  • 66
Robert Bell
  • 11
  • 1
  • 2
  • You could have found the error where Ekkehard.Horner is pointing to by opening the `IP_Addresses.csv` file. You would have seen that that file was empty and caused the `input past end of file` error, because there was no content. This would lead you to the root cause: the data was never written because the string that would be written is empty. – AutomatedChaos Oct 14 '13 at 09:25

2 Answers2

4

As you don't use "Option Explicit", you get what you deserve: You (try to) concatenate the lines into ipAddrSr but write ipAddrStr to the file. So nothing gets written to the file.

Fix the syntax error and the bad name to:

ipAddrStr = CStr(room+100) & "," & CStr(computer+1) & "," & ipAddress(room,computer) & vbCrlf
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • As I said in the post I am still learning VB script. We have yet to learn Option Explicit. However it seems the spelling error you found and I totally missed, so thank you for the response. – Robert Bell Oct 13 '13 at 16:46
  • And you get the upvote that you deserve. `Option Explicit` should be introduced as soon as variables and declaration are introduced. No excuses. – AutomatedChaos Oct 14 '13 at 09:19
1

Assuming that the file isn't empty, perhaps you need to specify the directory the file is in? I think this can be done either in your script:

fileName = "c:\your_directory\IP_Addresses.csv"

Or if you run it in the command line via cscript...

cscript.exe your.vbs "c:\your_directory\IP_Addresses.csv"

You can check the file size before executing your Echo if you like...

if fileName.size > 0 then 
    Set ipFileObj = fso.OpenTextFile(fileName,READ,ASCII)
    WScript.Echo ipFileObj.ReadAll **' this is line 60**
    ipFileObj.Close
else 
    WScript.Echo = "File was empty" 
end if 

See details of passing an argument to your script here.

Community
  • 1
  • 1
Scott Solmer
  • 3,871
  • 6
  • 44
  • 72