asp-classic - 经典 ASP、IIS 8.5、CINT CLNG 不工作

标签 asp-classic windows-8.1 iis-8

用 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),所以我认为这与区域设置和逗号被列为十进制字符有关。但现在我得到了不同的结果,这让我陷入困境..如果可以的话请帮忙。塔

最佳答案

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

关于asp-classic - 经典 ASP、IIS 8.5、CINT CLNG 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20395745/

相关文章:

javascript - 使用 jQuery 更新经典 ASP DIV 而无需重新加载网页

Android ADB 无法在 Windows 8.1 上将 APK 安装到 Nexus 5

c# - 访问 HubSection 内的数据

c# - 如何在 RichTextBlock 中显示字符串 - Windows Store Apps

asp.net - 什么是相当于 `aspnet_regiis -ir` 的 Windows Server 2012 命令行?

google-chrome - 找不到服务器 DNS 地址 - iis

asp-classic - jQuery-文件上传经典-ASP

javascript - Onclick传递两个变量时的语法问题,经典asp

session - 在经典 asp 中,我可以在 Session 对象中存储数据库连接吗?

iis - 自定义错误 400(错误请求)避免 IIS-8 拦截它