【问题标题】:Classic ASP, IIS 8.5, CINT CLNG not working经典 ASP、IIS 8.5、CINT CLNG 不工作
【发布时间】:2013-12-05 09:10:17
【问题描述】:

用 win 8.1 重新安装了我的开发机器 启用 ASP,安装我必须维护的旧网站,将网站安装为 IIS 中的应用程序,启用父路径,将错误发送到浏览器,在错误页面中设置完整的详细信息。一切都很好,除了我使用数字时

我在一个系统中工作,该系统捕获用户输入的财务数据,所以通常一个数字是:100.0 或 100.000 或 100 或 100,00

所以我有一个功能(我过去曾在大量网站上使用过)将不规则性标准化为恒定格式,例如 100.00(即:正确的小数,始终使用点等)

此行现在在 win 8.1 IIS 8.5 上失败:If Cdbl(myString) = Cdbl(0) Then

Function ProperDecimal(s_String)
    Dim CharPlace, DotChar, iLoop, strCurrentChar, myString
    myString = TRIM(s_String)
    If ISNULL(myString) OR myString = "" Then myString = 0
    myString = REPLACE(myString,",",".")

    'Find where the comma or dot is, ie: 100.00 is in position 3 (from the right)
    CharPlace = 1
    DotChar = 0
    For iLoop = Len(Replace(myString, " ", "")) to 1 Step -1
        strCurrentChar = mid(Replace(myString, " ", ""), iLoop, 1)
        If strCurrentChar = "." OR strCurrentChar = "," Then
            DotChar = CharPlace
            Exit For
        End If
    CharPlace = CharPlace + 1
    Next

    'If string is zero, leave it at zero, we dont need 0.00
    If Cdbl(myString) = Cdbl(0) Then
        'ignore it, no decimal places needed
        ProperDecimal = myString
    Else
        'Where is the DOT
        Select Case DotChar
            Case 0 'eg: 100 will be converted to 100.00
                ProperDecimal = (myString & ".00")
            Case 1 'eg: 100. will be converted to 100.00
                ProperDecimal = (myString & "00")
            Case 2 'eg: 100.0 will be converted to 100.00
                ProperDecimal = (myString & "0")
            Case 3 'eg: 100.00 will remain
                ProperDecimal = (myString)
            Case Else '(4, 5, 6, 7, 8, etc) 'eg: 100.001
                ProperDecimal = ProperDecimal(Round(myString,2))
        End Select
    End If
End Function

Call ProperDecimal("112.05")

这导致我尝试CDbl以外的其他方法

Response.write(isNumeric(s_String)) 'works, returns false because this is a string
Response.write(CINT(myString))
Response.write(CLNG(myString))
Response.write(CDBL(myString))

返回这个:

Microsoft VBScript 运行时错误“800a000d” 类型不匹配:'CINT'

Microsoft VBScript 运行时错误“800a000d” 类型不匹配:'CLNG'

Microsoft VBScript 运行时错误“800a000d” 类型不匹配:'CDBL'

Microsoft VBScript 运行时错误“800a000d” 类型不匹配:'CINT'

如果我然后更改 If 语句以将 0 转换为字符串,它可以工作:

If myString = CSTR(0) Then

但我真的不想将字符串与字符串进行比较,尤其是数字

这是现在正在进行的第二个项目。上一个项目我不得不将十进制逗号更改为句号(112,05 必须是 112.05),所以我认为这与区域设置和逗号被列为十进制字符有关。但是现在我得到了不同的结果,它把我逼到了墙边……如果可以的话,请帮忙。塔

【问题讨论】:

  • 向我们展示您的 isNumber() 函数的代码。那不是 vbscript 函数吗?
  • 据我所知,它的标准经典 asp/VB w3schools.com/vbscript/func_isnumeric.asp
  • IsNumeric != IsNumber
  • 好的,IsNumeric 返回 false,那是因为它是一个字符串.. 字符串不是问题,数字是问题,我认为我的 ASP 坏了,内置方法似乎不起作用,不是所有这些,只是其中的一些——也许 MS 没有通过 ASP 正确地移植到 iis 8 或者我不知道的东西
  • @Mark 好的,谢谢。对不起,我在我的 win 8.1 机器上试过了,一切正常。你肯定有另一个问题然后是 os/iis 版本

标签: asp-classic windows-8.1 iis-8


【解决方案1】:

服务器上的 CInt 工作正常(2008 R2),在客户端电脑(Windows Xp 和 Windows 7)上,但在我的 Windows 8 机器上,这是一个问题。

我创建了我自己的两个函数,现在我使用它们来代替 CInt 和 CDbl。如果需要,您可以制作更多。非常简单且经过测试,

编辑:

将函数名称更改为更短的版本。更容易更换和使用。如果您进行搜索,也不会与 Javascripts parseInt 冲突

Function pInt(Str)
    Dim val : val = 0

    '==Test Comma=='
    On Error Resume Next
        val = CInt(Replace(Str, ".", ","))

    '==Test Period=='
    On Error Resume Next
        val = CInt(Replace(Str, ",", "."))

    On Error Goto 0
    pInt = val
End Function

Function pDbl(Str)
    Dim val : val = 0

    '==Test Comma=='
    On Error Resume Next
        val = CDbl(Replace(Str, ".", ","))

    '==Test Period=='
    On Error Resume Next
        val = CDbl(Replace(Str, ",", "."))

    On Error Goto 0
    pDbl = val
End Function

我不是 ClassicASP/VBScript 方面的专家,但这很有效。我喜欢我的 C# ASP.net

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-27
    • 1970-01-01
    • 2011-07-14
    相关资源
    最近更新 更多