我只是想知道是否有可能取消調暗變量。有沒有UnDim變量的方法?
想象一下,這是我的#include文件,我使用的ASP頁面
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,因爲它可以幫助我保持代碼清潔。
*)編輯:我看到它不是我想要的那麼清楚。
想象這是一個 「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"-->
你明白我的意思?如果我能夠在包含結尾處UNDIM A變量,問題就會解決。
我建議你不要試圖做到這一點,因爲它會在同一範圍內給出不同的含義MyVar的。爲什麼不將MyVar設置爲Nothing後重用?例如'MyVar =「Hello World2」'? – acarlon