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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Out of Range errror

Status
Not open for further replies.

glenmac

Technical User
Jul 3, 2002
947
CA
In this code I get subscript out of range for line 10 can anyone see my mistake?

Code:
Const ForReading = 1
Const ForWriting = 2
Const TristateFalse = 0

Dim line1    
Dim line3
Dim line5

Set theArgs = WScript.Arguments
file1=theArgs(0)

Set fs = CreateObject("Scripting.FileSystemObject")
' open file to read from
Set f = fs.GetFile ("c:\255\quiz1.txt")
Set ts = f.OpenAsTextStream (ForReading, TristateFalse)

line1= ts.Readline
ts.skipline
line3= ts.Readline
ts.skipline
line5= ts.Readline

writetext

Sub writetext
  Set fs = CreateObject("Scripting.FileSystemObject")
  ' open file to write to, create if not there, using ASCII
  afile ="c:\255\" & file1
  Set ts = fs.OpenTextFile(afile, ForWriting, True)

  ts.WriteLine line1
  ts.Writeline line3
  ts.Writeline line5 
 ts.Close 
End Sub
 
"subscript out of range" has to do with an array being accessed outside its bounds.

check what value you are getting for file1 and try a
ubound(theArgs) to see how many items in the array.

"did you just say Minkey?, yes that's what I said."

MrGreed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top