【问题标题】:Classic ASP getPathName and getName Error经典 ASP getPathName 和 getName 错误
【发布时间】:2012-11-14 07:34:56
【问题描述】:

我通常使用 PHP 开发网站。但是现在我必须使用 ASP Classic,因为我的客户已经有一个网站,然后我必须维护该网站。我已经将所有网站移至我的新主机。但是这段代码有错误:

cPath=getPathName(Server.mappath(Request.ServerVariables("PATH_INFO")))

错误信息是:

Microsoft VBScript 运行时错误“800a000d”

类型不匹配:'getPathName'

调用getName代码时显示一些错误。

请帮助我该怎么做。

【问题讨论】:

  • 你能多加一点吗,比如你声明cPath的地方。 - 类型不匹配是当您尝试将一种类型的值填充到另一种类型的变量中时发生的一般错误。
  • @Robuust 类型不匹配的原因是 getPathName 是由 VBScript 自动创建的,但类型为 Empty。由于他试图将其用作函数,因此导致类型不匹配。脚本语言的奇迹!

标签: asp-classic


【解决方案1】:

据我所知,经典的 ASP 或 VBScript 没有与 PHP getPathName()getName() 等效的函数。

当给定一个字符串时,我无法理解getPathName() 的含义,实际上我认为它不存在,所以只需要:

cPath = Server.MapPath(Request.ServerVariables("PATH_INFO"))

并且该变量将包含当前正在执行的 ASP 文件的完整物理路径。

至于getName()你可以写自定义函数:

Function GetOnlyName(filePath)
    Dim slashIndex
    slashIndex = InStrRev(filePath, "\")
    If slashIndex<1 Then
        slashIndex = InStrRev(filePath, "/")
    End If
    If slashIndex>0 Then
        ExtractFileName = Mid(filePath, slashIndex + 1, Len(filePath) - slashIndex + 1)
    Else  
        ExtractFileName = filePath
    End If
End Function

然后像这样使用它:

cName = GetOnlyName(Server.MapPath(Request.ServerVariables("PATH_INFO")))

并且该变量将只包含 ASP 文件的名称。

作为记录,为了避免混淆类型不匹配错误,总是把它放在你的脚本之上:

Option Explicit

然后始终使用Dim 语句声明所有变量,就像上面的函数一样。有了这个,尝试使用getPathName 会给出更有意义的“变量未定义”错误。

【讨论】:

    猜你喜欢
    • 2012-02-11
    • 2016-10-06
    • 2010-11-04
    • 1970-01-01
    • 2011-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多