Asp classic 重用同一变量

Asp classic 重用同一变量,asp-classic,vbscript,Asp Classic,Vbscript,是否有方法设置dim变量以在相同的fs fo和x中重复使用。还是每次在页面上运行代码时都必须创建一个唯一的变量 <% itemnum = 1 dim fs,fo,x fs=Server.CreateObject("Scripting.FileSystemObject") set fo=fs.GetFolder(Server.MapPath("/images")) ... %> 下一节 <% itemnum = 1 dim fs,fo,x fs=Server.Crea

是否有方法设置dim变量以在相同的fs fox中重复使用。还是每次在页面上运行代码时都必须创建一个唯一的变量

<%
itemnum = 1
dim fs,fo,x

fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder(Server.MapPath("/images"))

...
%>

下一节

<%
itemnum = 1
dim fs,fo,x

fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder(Server.MapPath("/videos"))

...
%>

您只需在页面顶部调暗一次,然后就可以随意重复使用它(无需重新调暗/重新创建fso对象,只要您的代码在同一范围内(页面/包含集))——即使您进出asp块

示例(全部在一个asp文件中):


呜呜呜呜

这不是ASP.NET,而是经典的ASP.NET。将其包装在函数中并使用局部变量。@您能提供一个如何执行此操作的示例吗?我不是一个asp程序员,我只是调整一些现有的代码。
<%
'#### Declare objects and initialise FSO (only has to be done once per request)
dim fs,fo,x 
set fs = Server.CreateObject("Scripting.FileSystemObject") 
%>
bla bla bla
<%
set fo=fs.GetFolder(Server.MapPath("/images")) 
'Do something with the images folder
%>
bla bla bla
<%
set fo=fs.GetFolder(Server.MapPath("/videos")) 
'Do something with the videos folder
%>
bla bla bla
<%
'#### Cleanup
set fo = Nothing
set fs = Nothing
%>