Avatar of On-a-steep-curve
On-a-steep-curve
 asked on

vbscript error Name redefined 'ForReading'

I got a script that checks files in a directory but I keep on getting this error

vbscript error Name redefined 'ForReading'

how do I fix it


Dim objFile, maxspeed, auditneeded
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolder: Set objFolder=objFSO.GetFolder("C:\Documents and Settings\All Users\Documents\out2\")
 
For Each File in objFolder.Files
  If lCase(objFSO.GetExtensionName(file.name))="ini" Then
 
    Const ForReading = 1
 
    Set objFile = objFSO.OpenTextFile(file.path, ForReading)
 
    Dim arrFileLines()
    i = 0
    Do Until objFile.AtEndOfStream  
    Redim Preserve arrFileLines(i)
    arrFileLines(i) = objFile.ReadLine
    i = i + 1
    Loop
 
    For Each strLine in arrFileLines
 
      dim myspeedaudit
      myspeedaudit=InStr(1, strLine, "Max_Speed=", 1) 
 
      if myspeedaudit = 1 Then
        maxspeed = Split(strLine, "=", -1, 1)
        if maxspeed(1) > 96 Then
          auditneeded="y"
          Wscript.Echo "Max speed = " & maxspeed(1) & " auditneeded = " & auditneeded
        End If
      End if
     
    Next
            
    objFile.Close
    Set objFile=Nothing        
  End If
 
Next

Open in new window

ASPVisual Basic ClassicVB Script

Avatar of undefined
Last Comment
Dimitris

8/22/2022 - Mon
Dimitris

Change the ForReading in line 10 with 1
Set objFile = objFSO.OpenTextFile(file.path, 1)

The problem is that the enumerations are not working in ASP
Dimitris

Or you can do this

Dim ForReading=1
Dim ForWriting = 2
Dim ForAppending =8

If you declare them then you can use the alias for read,write and append
On-a-steep-curve

ASKER
Tried both neither work

solution 1 Produces a Type mismatch for Dim arrFileLines()
solution 2 produces and expected end of statement error after the reading (char 15)
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
yehudaha

move line 8 to the start of the script
yehudaha

move line 8 to the begining of the script
ASKER CERTIFIED SOLUTION
Dimitris

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.