简体   繁体   English

在经典ASP中是否可以两次定义相同的变量?

[英]Is it possible to define same variable twice in classic ASP?

Is it somehow possible to declare same variable in .asp file twice? 是否可以在.asp文件中两次声明相同的变量? Example below does not look very clever, but this is just an example and I have to sort it out. 下面的示例看起来并不很聪明,但这只是一个示例 ,我必须对其进行梳理。

Dim number : number = 1

Select Case number
    Case 1
        Dim a
    Case 2
        Dim a
End Select

Theoretically you can of course declare a variable twice, the problem is, asp will throw an error, if the variable is declared in the same scope. 从理论上讲,您当然可以声明两次变量,问题是,如果在同一范围内声明变量,asp将抛出错误。

whatever you want to achieve, keep in mind, you can (almost) always access the variables in parent scope, thus rendering a double declaration useless. 请记住,无论您要实现什么,您都可以(几乎)始终访问父作用域中的变量,从而使双声明无效。

Dim number : number = 1
Dim a
Select Case number
   Case 1:
      a = "whatever"
   Case 2:
      a = "something different"
End Select
response.write a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM