Classic ASP Object Required Error

Microsoft VBScript runtime error '800a01a8'

Page 1 of 1

2 Replies - 4243 Views - Last Post: 24 June 2010 - 02:11 PM Rate Topic: -----

#1 codeladySRQ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-June 10

Classic ASP Object Required Error

Posted 17 June 2010 - 07:45 AM

I am a novice programmer. I have never learned Classic ASP (or any server-side programs). I am trying to open and read a text file and read the IP addresses in the file and allow only the IP addresses in the file access to the server and deny all else.

Line 42 is: If Contents.InStr(pIP) > 0 Then

pIP is in the text file along with the IP addresses.

I would rather do this via code than access lists on the router.

But I keep getting this error:

Microsoft VBScript runtime error '800a01a8'

Object required: 'Contents'

/Folder/ValidAddressList.asp, line 42



Here is my code:
FUNCTION ValidIPs(pIP)
Const Filename = "/Folder/ipaddress.txt" ' file of ip addresses to read
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

' create a filesystem object
Dim FSO
set FSO = server.CreateObject("Scripting.FileSystemObject")

' map the logical path to the physical system path
Dim Filepath
Filepath = Server.MapPath(Filename)


    IF FSO.FileExists(Filepath) Then
        Set TextStream = FSO.OpenTextFile(Filepath, ForReading, False, TristateUseDefault)
               
       ' read file in one hit, then close text file
       Dim Contents
              
       ' Dim position
       ' Position=instr(1, contents, pIP,comparemethod.text)
       
        'if isObject(Contents) then 
        '    set objectName = nothing 
        'end if 
        
        ' Set Contents = nothing
        ' Set Contents.InStr(pIP) = nothing

        Contents = TextStream.ReadAll
            If Contents.InStr(pIP) > 0 Then 
                ValidIPs = true
            Else
                ValidIPs = false   
            End If  
        TextStream.Close
        Set TextStream = nothing
                  
    ELSE 
        ' close file
        TextStream.Close
        
        Set FSO = nothing      

    END IF
    
END FUNCTION
  %>



Is This A Good Question/Topic? 0
  • +

Replies To: Classic ASP Object Required Error

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4405
  • View blog
  • Posts: 12,262
  • Joined: 18-April 07

Re: Classic ASP Object Required Error

Posted 17 June 2010 - 03:27 PM

In classic asp we are still back on functions, not objects. So InStr is a stand alone function, not a method of a string object. So you want to do...

If Instr(Contents, "IP Address to look for") > 0 then
    ' They were found in file, so do something.
Else
    ' Not found
End if



I see you had some of that there and it is commented out. But that is how you use Instr in classic ASP. :)


P.S. The reason it is erroring out is that contents is a string and in VBScript (classic ASP) strings are not objects. So when you try to call Instr() method on it, it is saying the string is not an object and so it doesn't contain methods like InStr().

This post has been edited by Martyr2: 17 June 2010 - 03:29 PM

Was This Post Helpful? 1
  • +
  • -

#3 codeladySRQ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-June 10

Re: Classic ASP Object Required Error

Posted 24 June 2010 - 02:11 PM

View PostMartyr2, on 17 June 2010 - 02:27 PM, said:

In classic asp we are still back on functions, not objects. So InStr is a stand alone function, not a method of a string object. So you want to do...

If Instr(Contents, "IP Address to look for") > 0 then
    ' They were found in file, so do something.
Else
    ' Not found
End if



I see you had some of that there and it is commented out. But that is how you use Instr in classic ASP. :)


P.S. The reason it is erroring out is that contents is a string and in VBScript (classic ASP) strings are not objects. So when you try to call Instr() method on it, it is saying the string is not an object and so it doesn't contain methods like InStr().



Reply from CodeLadySRQ: Thank you so much! I am familiar with object oriented programming so I was clueless.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1