开发者

ASP equivalent of PHP print_r

开发者 https://www.devze.com 2023-01-10 15:41 出处:网络
Plain old ASP, not .NET I\'ve got a really large and complicated class for making an upload progress bar and I\'m trying to find out the uploaded file name. I think easiest way to accomplish that wou

Plain old ASP, not .NET

I've got a really large and complicated class for making an upload progress bar and I'm trying to find out the uploaded file name. I think easiest way to accomplish that would be dumping the variable structure but, even if it isn't (and I appreciate if someone can 开发者_运维知识库point me), I've ended up wondering about it and the question here is still just that.

ASP doesn't have an equivalent as far as I know, so I'm looking here for a complete home made solution (unlike this one), which can dump the whole object structure.

Thanks in advance for all the trouble of finding or even making this, if you will. :)


I looked at loads of ways of trying to this as well but couldn't do anything with classes because vbscript doesn't support introspection. However in case it helps anyone trying to do a more simple print_r with classic ASP. I did manage to get a good way along just not with classes.

function print_r(data, dumpRef)
    dim dumpData
    if isArray(data) or cbool(instr(TypeName(data),"Dictionary")) or TypeName(data) = "ISessionObject" or TypeName(data) = "IForm" or TypeName(data) = "Field" then
        dumpData = dump(data, 0)
    else
        select case TypeName(data)
            case "Recordset"
                dumpData = dumpQuery(data, "html")
            case "IXMLDOMElement"
                dumpData = pre(htmlencode(data.xml))
                
            case else
                on error resume next
                dumpData = TypeName(data) & ": " & data
                if err.number <> 0 then
                    dumpData = "Unable to output data for data type " & TypeName(data)
                    err.clear
                end if
                on error goto 0
        end select
    end if 
    dumpData = "----------- DUMP CALLED " & dumpRef &" -------------" & vbcrlf & dumpData
    globalDumpData = globalDumpData & vbcrlf & dumpData
    if left(dumpRef,5) = "[pre:" then
        response.write "<pre>"&dumpData&"</pre>"
        if dumpRef = "[pre:stop]" then
            response.end
        end if
    end if
    print_r = dumpData
end function

function print_r_go(data)
    print_r data, "[pre:]"
end function

function print_r_stop(data)
    print_r data, "[pre:stop]"
end function

function dumpQuery(recordset, format)
    dim col, header, data, wrapper, q, colCount
    colCount = 1
    if format = "html" then
        wrapper = "<table border=""1"">" & vbnewline
    end if
    set q = recordset
    if q.recordcount > 0 then
        q.movefirst
    end if
    if q.absoluteposition = 1 then
        if format = "html" then
            header = "  <tr>" & vbnewline
        end if
        for each col in q.fields
            if format = "html" then
                header = header & "    <th align=""left"" valign=""top"">"&col.name&"</th>" & vbnewline
            else
                if colCount <> 1 then
                    header = header & ","
                end if
                header = header & cleanCSVValue(col.name)
            end if
            colCount = colCount + 1             
        next
        if format = "html" then
            header = header & "  </tr>" & vbnewline
        else
            header = header & vbnewline
        end if
        q.movefirst
    end if
    
    if q.recordcount > 0 then
        if format = "html" then
            data =  q.GetString(2, q.recordcount+1, "</td>" & vbnewline & "    <td valign=""top"">", "[#]", "")
            data = left(data, len(data) - 3)
            data = replace(data, "[#]", "</td>" & vbnewline & "  </tr>" & vbnewline & "  <tr>" & vbnewline & "    <td valign=""top"">")
            data = "  <tr>" & vbnewline & "    <td valign=""top"">" & data & "</td>" & vbnewline & "  </tr>"
        else
            data = q.GetString(2, q.recordcount+1, """,""", "[#]", "")
            data = replace(data, "[#]", """" & vbnewline & """")
            data = """" & data & """"
        end if
    end if
    
    wrapper = wrapper & header & data
    if format = "html" then
        wrapper = wrapper & vbnewline & "</table>"
    end if
    if q.recordcount > 0 then
        q.movefirst
    end if
        
    dumpQuery = wrapper
end function

function dump(data, depth)
    dim output, x, y, localData
    if isArray(data) then
        on error resume next
        dim secondDim : secondDim = ubound(data, 2)
        if err.number <> 0 then
            secondDim = -1
            err.clear
        end if
        on error goto 0
        output = ""
        if secondDim => 0 then
            output = "Two Dimensional "
        end if
        output = output & "Array <br />"
        output = output & Tab(depth) & "(<br />"
        if secondDim => 0 then
            for x=0 to uBound(data)
                for y = 0 to secondDim
                    output = output & Tab(depth+1) & "["&x&","&y&"] => "
                    output = output & dump(data(x,y), depth+2) 
                    output = output & "<br />"
                next
            next
        else 
            for x=0 to uBound(data)
                output = output & Tab(depth+1) & "["&x&"] => "
                output = output & dump(data(x), depth+2) 
                output = output & "<br />"
            next
        end if
        output = output & Tab(depth) & ")"
    elseif cbool(instr(TypeName(data),"Dictionary")) then
        output = TypeName(data) & " <br />"
        output = output & Tab(depth) & "(<br />"
        for each x in data
            output = output & Tab(depth+1) & "["&x&"] => "
            output = output & dump(data(x), depth+2) 
            output = output & "<br />"
        next
        output = output & Tab(depth) & ")"
    elseif TypeName(data) = "ISessionObject" then
        output = TypeName(data) & "<br />(<br/>"& Tab(depth+1) & "Contents<br />"
        output = output & Tab(depth+1) & "(<br />"
        for each x in data.contents
            output = output & Tab(depth+2) & "["&x&"] => "
            output = output & dump(data(x), depth+2) 
            output = output & "<br />"
        next
        output = output & Tab(depth+1) & ")<br/><br/>"
        output = output & Tab(depth+1) & "StaticObjects<br />"
        output = output & Tab(depth+1) & "(<br />"
        for each x in data.StaticObjects
            output = output & Tab(depth+2) & "["&x&"] => "
            output = output & dump(data(x), depth+2) 
            output = output & "<br />"
        next
        output = output & Tab(depth+1) & ")<br/>"
        output = output & Tab(depth) & ")"
    elseif TypeName(data) = "Recordset" then
        output = output & dumpQuery(data)
        output = output & "<br />"
    elseif TypeName(data) = "IForm" then
        for each x in data
            output = output & "["&x.name&"] => "
            output = output & dump(x, depth+2) 
            output = output & "<br />"
        next
    elseif TypeName(data) = "Field" then
        output = output & "["&data.name&"] => "
        output = output & dump(data.value, depth+2) 
        output = output & "<br />"
    else
        on error resume next
        output = output & data
        if err.number <> 0 then
            output = output & "Unable to dump data for data type " & TypeName(data)
            err.clear
        end if
        on error goto 0
    end if
    dump = output
end function

public function Tab(spaces)
    dim val, x
    val = ""
    for x=1 to spaces
        val = val & "    "
    next
    Tab = val
end function


There's no such tool that I know of, but you can debug classic ASP with Visual Studio, set breakpoints and hover over objects to inspect them like in .NET. I have done so for recordsets and simple value types, but I imagine it would also work for nested objects. You'll have to have VS installed on the machine you develop the site on, and enable debugging in IIS for this to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消