使用VB將ASP代碼封裝到DLL文件
更新時(shí)間:2007年01月10日 00:00:00 作者:
很久以前的文檔,整理出來(lái),回味一下
使用VB封裝ASP,建立SayHello測(cè)試程序
1、打開VB6,新建ActiveX DLL
2、在工程引用中加入Microsoft Active Server Pages Object Library選擇
3、填加代碼如下:
'Code Start
'聲明部分
Private MyScriptingContext As ScriptingContext
Private MyApplication As Application
Private MyRequest As Request
Private MyResponse As Response
Private MyServer As Server
Private MySession As Session
'下面定義公用函數(shù)(在VB中訪問(wèn)ASP對(duì)象,即在VB中可以用MyApplication等同于ASP中的Application、MyRequest等同于ASP中的Request、 MyResponse等同于ASP中的Response、 MyServer等同于ASP中的Server、 MySession等同于ASP中的Session 使用)
Public Sub OnStartPage(PassedScriptingContext As ScriptingContext)
Set MyScriptingContext = PassedScriptingContext
Set MyApplication = MyScriptingContext.Application
Set MyRequest = MyScriptingContext.Request
Set MyResponse = MyScriptingContext.Response
Set MyServer = MyScriptingContext.Server
Set MySession = MyScriptingContext.Session
End Sub
Public Sub OnEndPage()
Set MyScriptingContext = Nothing
Set MyApplication = Nothing
Set MyRequest = Nothing
Set MyResponse = Nothing
Set MyServer = Nothing
Set MySession = Nothing
End Sub
'建立自定義函數(shù)SayHello
Public Sub SayHello()
MyResponse.Write ("Hello World")
End Sub
'Code End
4、將類名改為:HelloWorld 將工程名改為:TestVBCode
5、生成TestVBCode.DLL文件,并使用Windows運(yùn)行注冊(cè)組件命令Regsvr32 路徑\TestVBCode.DLL注冊(cè)后即可使用。(卸載組件命令為Regsvr32 /u 路徑\TestVBCode.DLL)
6、建立Test.asp文件,代碼如下
<%
'VB自建函數(shù)調(diào)用格式
'Set 對(duì)象名=Server.CreateObject("工程名.類名")
'對(duì)象名.自建函數(shù)名
Set MyTestObj = Server.CreateObject("TestVBCode.HelloWorld")
MyTestObj .SayHello
%>
7、運(yùn)行Test.asp文件結(jié)果顯示如下:
Hello World
以上實(shí)例將開啟你的VB編程世界之門
一起來(lái)吧,呵呵!
使用VB封裝ASP,建立SayHello測(cè)試程序
1、打開VB6,新建ActiveX DLL
2、在工程引用中加入Microsoft Active Server Pages Object Library選擇
3、填加代碼如下:
'Code Start
'聲明部分
Private MyScriptingContext As ScriptingContext
Private MyApplication As Application
Private MyRequest As Request
Private MyResponse As Response
Private MyServer As Server
Private MySession As Session
'下面定義公用函數(shù)(在VB中訪問(wèn)ASP對(duì)象,即在VB中可以用MyApplication等同于ASP中的Application、MyRequest等同于ASP中的Request、 MyResponse等同于ASP中的Response、 MyServer等同于ASP中的Server、 MySession等同于ASP中的Session 使用)
Public Sub OnStartPage(PassedScriptingContext As ScriptingContext)
Set MyScriptingContext = PassedScriptingContext
Set MyApplication = MyScriptingContext.Application
Set MyRequest = MyScriptingContext.Request
Set MyResponse = MyScriptingContext.Response
Set MyServer = MyScriptingContext.Server
Set MySession = MyScriptingContext.Session
End Sub
Public Sub OnEndPage()
Set MyScriptingContext = Nothing
Set MyApplication = Nothing
Set MyRequest = Nothing
Set MyResponse = Nothing
Set MyServer = Nothing
Set MySession = Nothing
End Sub
'建立自定義函數(shù)SayHello
Public Sub SayHello()
MyResponse.Write ("Hello World")
End Sub
'Code End
4、將類名改為:HelloWorld 將工程名改為:TestVBCode
5、生成TestVBCode.DLL文件,并使用Windows運(yùn)行注冊(cè)組件命令Regsvr32 路徑\TestVBCode.DLL注冊(cè)后即可使用。(卸載組件命令為Regsvr32 /u 路徑\TestVBCode.DLL)
6、建立Test.asp文件,代碼如下
<%
'VB自建函數(shù)調(diào)用格式
'Set 對(duì)象名=Server.CreateObject("工程名.類名")
'對(duì)象名.自建函數(shù)名
Set MyTestObj = Server.CreateObject("TestVBCode.HelloWorld")
MyTestObj .SayHello
%>
7、運(yùn)行Test.asp文件結(jié)果顯示如下:
Hello World
以上實(shí)例將開啟你的VB編程世界之門
一起來(lái)吧,呵呵!
相關(guān)文章
使用ASP實(shí)現(xiàn)網(wǎng)站的“目錄樹”管理的代碼
使用ASP實(shí)現(xiàn)網(wǎng)站的“目錄樹”管理的代碼...2007-09-09asp中將字符串轉(zhuǎn)數(shù)字的函數(shù)小結(jié)
這篇文章主要介紹了asp中將字符串轉(zhuǎn)數(shù)字的函數(shù)小結(jié),需要的朋友可以參考下2020-09-09JScript中遍歷Request表單參數(shù)集合的方法
這篇文章主要介紹了JScript中遍歷Request表單參數(shù)集合的方法,本文以遍歷Request.QueryString集合為例給出了實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-03-03asp OpenTextFile文本讀取與寫入實(shí)例代碼
打開指定的文件并返回一個(gè) TextStream 對(duì)象,可以讀取、寫入此對(duì)象或?qū)⑵渥芳拥轿募?2008-08-08asp實(shí)現(xiàn)excel中的數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫(kù)
本文給大家匯總介紹了使用asp實(shí)現(xiàn)將Excel中數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(kù)中的方法,需要的朋友可以參考一下2015-09-09轉(zhuǎn)換中文為unicode 轉(zhuǎn)換unicode到正常文本
轉(zhuǎn)換中文為unicode 轉(zhuǎn)換unicode到正常文本...2006-10-10Asp中Server.ScriptTimeOut屬性需要注意的一點(diǎn)分析
Server.ScriptTimeout 這個(gè)屬性給定Asp腳本執(zhí)行的最大時(shí)間,如果asp程序的運(yùn)行時(shí)間超過(guò)了這個(gè)屬性規(guī)定的值,Asp就會(huì)報(bào)錯(cuò)。2011-06-06