比如:我定义
     Public Function FormatStr(ByVal ob As Object) As String
        If ob.ToString().Trim() = "" Then
            FormatStr = ""
        Else
            FormatStr = ob.ToString().Trim().Substring(0, 2) + ":" + ob.ToString().Trim().Substring(2, 2)
        End If
    End Function
   
   Private Sub ma()
    ................
   End Sub 程序中所有页面都要调用这两个函数,我应该把他们放在什么地方,怎样读取调用?????

解决方案 »

  1.   

    建一个类,再调用类,或者建一个model模块,将函数放在模块中,但在模块中的函数应为public 的
      

  2.   

    1、在项目中新追加一个类文件,比如Common:
    Public Class Common
        Inherits System.Web.UI.Page    Public Function FormatStr(ByVal ob As Object) As String
            If ob.ToString().Trim() = "" Then
                FormatStr = ""
            Else
                FormatStr = ob.ToString().Trim().Substring(0, 2) + ":" + ob.ToString().Trim().Substring(2, 2)
            End If
        End Function    Private Sub ma()
            ''................
        End Sub
    End Class2、修改页面类的定义:Public Class WebForm1
        Inherits System.Web.UI.Page
    为:
    Public Class WebForm1
        Inherits Common
        
    祝你成功!!!
      

  3.   

    TO:swordragon(古道热肠) 
    ------------------------------------
    那页面怎么调用呢?????
      

  4.   

    对于public的方法,直接调用:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = FormatStr("1220")
    End Sub
      

  5.   

    1、在项目中新追加一个类文件,比如Common:
    Public Class Common
        Inherits System.Web.UI.Page    Public Function FormatStr(ByVal ob As Object) As String
            If ob.ToString().Trim() = "" Then
                FormatStr = ""
            Else
                FormatStr = ob.ToString().Trim().Substring(0, 2) + ":" + ob.ToString().Trim().Substring(2, 2)
            End If
        End Function    Private Sub ma()
            ''................
        End Sub
    End Class2、修改页面类的定义:Public Class WebForm1
        Inherits System.Web.UI.Page
    为:
    Public Class WebForm1
        Inherits Common
    {
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            TextBox1.Text = FormatStr("1220")
        End Sub
    }