很久以前的文檔,整理出來,回味一下
使用VB封裝ASP,建立SayHello測試程序
1、打開VB6,新建ActiveXDLL
2、在工程引用中加入MicrosoftActiveServerPagesObjectLibrary選擇
3、填加代碼如下:
'CodeStart
'聲明部分
PrivateMyScriptingContextAsScriptingContext
PrivateMyApplicationAsApplication
PrivateMyRequestAsRequest
PrivateMyResponseAsResponse
PrivateMyServerAsServer
PrivateMySessionAsSession
'下面定義公用函數(在VB中訪問ASP對象,即在VB中可以用MyApplication等同於ASP中的Application、MyRequest等同於ASP中的Request、MyResponse等同於ASP中的Response、MyServer等同於ASP中的Server、MySession等同於ASP中的Session使用)
PublicSubOnStartPage(PassedScriptingContextAsScriptingContext)
SetMyScriptingContext=PassedScriptingContext
SetMyApplication=MyScriptingContext.Application
SetMyRequest=MyScriptingContext.Request
SetMyResponse=MyScriptingContext.Response
SetMyServer=MyScriptingContext.Server
SetMySession=MyScriptingContext.Session
EndSub
PublicSubOnEndPage()
SetMyScriptingContext=Nothing
SetMyApplication=Nothing
SetMyRequest=Nothing
SetMyResponse=Nothing
SetMyServer=Nothing
SetMySession=Nothing
EndSub
'建立自定義函數SayHello
PublicSubSayHello()
MyResponse.Write("HelloWorld")
EndSub
'CodeEnd
4、將類名改為:HelloWorld將工程名改為:TestVBCode
5、生成TestVBCode.DLL文件,並使用Windows運行註冊組件命令Regsvr32路徑/TestVBCode.DLL註冊後即可使用。 (卸載組件命令為Regsvr32/u路徑/TestVBCode.DLL)
6、建立Test.asp文件,代碼如下
<%
'VB自建函數調用格式
'Set對象名=Server.CreateObject("工程名.類名")
'對象名.自建函數名
SetMyTestObj=Server.CreateObject("TestVBCode.HelloWorld")
MyTestObj.SayHello
%>
7、運行Test.asp文件結果顯示如下:
HelloWorld
以上實例將開啟你的VB編程世界之門
一起來吧,呵呵!