有没有办法取消变量的变暗? [英] Is there a way to UnDim Variable?

查看:75
本文介绍了有没有办法取消变量的变暗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否存在取消变量变暗的可能性.

I'm just wondering if there is a possibility to un-dim a variable.

想象一下这是我在ASP页面中使用的#include文件

Imagine this is my #include file that I'm using in ASP page

Dim MyVar
MyVar = "Hello World"
Response.write(MyVar)
'From now on I can not use Dim MyVar anymore as it throws an error
'I have tried
MyVar = Nothing
Set MyVar = Nothing
'But again, when you do
Dim MyVar
'It throws an error.

这样做的原因是,我不能在同一页面上多次使用同一#INCLUDE文件.是的,我确实喜欢使用Option Explicit,因为它可以帮助我保持代码更整洁.

The reason for this is that I cannot use the same #INCLUDE file more than once per page. And yes, I do like using Option Explicit as it helps me to keep my code cleaner.

*)我发现它不够清晰.

*) Edited: I see that it's not as clear as I wanted.

想象这是一个"include.asp"

Imagine this is a "include.asp"

<%
Dim A
A=1
Response.Cookie("beer")=A
%>

现在的asp页面:

<!--#include file="include.asp"-->
<%
'Now: I do not see whats in include above and I want to use variable A
Dim A
'And I get an error
'I also cannot use the same include again:
%>
<!--#include file="include.asp"-->

你明白我的意思吗?如果我能够在Include的末尾对A变量进行UNDIM,该问题将得到解决.

Do you see my point? If I would be able to UNDIM the A variable at the end of the Include, the problem would be solved.

推荐答案

没有办法取消"变量.幸运的是,您也不需要它.

No there is no way to "UnDim" a variable. Luckily you also don't need that.

每当您尝试在同一作用域中两次声明变量时,您就已经在犯错了.认为运行时不允许您这样做很有帮助.

Whenever you try to declare a variable twice in the same scope, you're already making a mistake. Consider it as helpful that the runtime does not let you.

解决方案:

  • 不使用全局变量.使用函数,在那里声明变量.
  • 不要多次包含同一个文件.

这篇关于有没有办法取消变量的变暗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆