以自己的名字空间做一个项目吧,然后可以加到任何一个需要使用的解决方案里,方案中其他项目import你的名字空间,很酷的

解决方案 »

  1.   

    給你一個最簡單的例子:[第一步]
    SimpleCalculator.vb
    =======
    Imports SystemNameSpace Hammer
      Public Class SimpleCalculator
        Public Function Plus(iA As Integer, iB As Integer)
          Plus = iA + iB
        End Function
      End Class
    End NameSpace[第二步]
    C:\>vbc /t:library /r:System.dll SimpleCalculator.vb[第三步]
    test.aspx
    =========
    <%@ Page Language="vb" %>
    <%@ Import Namespace="Hammer" %>
    <script language="vb" runat="server">
      Dim objSC As New SimpleCalculator()
      Response.Write (objSC.Plus(1+1))
    </script>
    <html>
    </html>你應該會看到 "2"。
      

  2.   

    啊﹐我在写什么?
    应该是 Response.Write (objSC.Plus(1,1))还有,如果 vbc 没有错误的话,会有 SimpleCalculator.dll 产生,此时必将这个 dll 放到 /bin 里才可以用。比如说: C:\InetPub\wwwroot\bin。
      

  3.   

    请问在后台VB文件中如何应用这个DLL?你举的例子是在aspx文件中应用。
      

  4.   

    基本上用法是一样的例如:
    test.aspx
    =========
    <%@ page language="vb" inherits="Hammer.MyPage" src="test.aspx.vb" %>
    <html>
    <body>
    </body>
    </html>
    test.aspx.vb
    ============
    Imports System
    Imports HammerNamespace Hammer   Public Class MyPage
         Inherits System.Web.UI.Page      Public Label1 As New System.Web.UI.WebControls.Label()      Protected Sub Page_Load
            Label1.Text = "试试看"
            Controls.Add(Label1)        Response.Write("1 + 1 = " & objSC.Plus(1,1))
          End Sub
       End ClassEnd Namespace
      

  5.   

    DLL要用VB写吗,用C#可以吗?!