locked
Question on how use 1 set of code in the my project/web site RRS feed

  • Question

  • User-1188570427 posted

    I want to use the below code throughout my whole program.website for every aspx file. This code sends the errors messages to a text file for me, so I can keep track of all my issues. I want to place the code below in one file and call it every time for each web page in the catch statement. Any ideas how to do this and how I would call it etc?


    1   Private Sub errors(ByVal errors As String)
    2            Try
    3                Dim
    writetofile As IO.StreamWriter
    4                Dim path As String
    5                Session("errorlog") = errors
    6                path = Session("errorsconnection") + "trackindexworking.txt"
    8                writetofile = New IO.StreamWriter(path, True)
    9                writetofile.WriteLine(Now.ToString() + "----> " + errors + ControlChars.NewLine + ControlChars.NewLine)
    10               writetofile.Close()
    11           Catch ex As Exception
    12             
    13           End Try
    14       End Sub

     

        Private Sub errorexample()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>        Try<o:p></o:p>            <o:p></o:p>        Catch ex As Exception<o:p></o:p>            errors(ex.ToString)<o:p></o:p>            Response.Redirect("~/test/Error.aspx")<o:p></o:p>        End Try<o:p></o:p>

        End Sub

     

    Friday, October 31, 2008 8:41 PM

Answers

  • User-158764254 posted

    like this:

    Dim classInstance As New Class2
    Dim result As Boolean 
    result = classInstance.sendtoerrorfile("something","something")

    Note: If you make the function Shared, then you do not need to create an instance of the class to call that method.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 2, 2008 3:01 PM

All replies

  • User-990694832 posted

    A person could put the function in the global.asax file

    or a person could create a utility class and create a new instance for each page

    Hope this helps

    DK 

     

    Friday, October 31, 2008 11:38 PM
  • User-1188570427 posted

    Okay say I do make a class. How do I use it from my aspx file?

    Imports Microsoft.VisualBasic

    Public Class Class2

    Public Function sendtoerrorfile(ByVal errors As String, ByVal path As String) As Boolean

    MsgBox("testing class file")

    End Function

    End Class

    Saturday, November 1, 2008 5:53 AM
  • User-158764254 posted

    like this:

    Dim classInstance As New Class2
    Dim result As Boolean 
    result = classInstance.sendtoerrorfile("something","something")

    Note: If you make the function Shared, then you do not need to create an instance of the class to call that method.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 2, 2008 3:01 PM
  • User-1630302068 posted

     or:

    Imports Microsoft.VisualBasic
    Public Class Class2

    Public Shared Function sendtoerrorfile(ByVal errors As String, ByVal path As String) As Boolean
        MsgBox("testing class file")

    End Function

    End Class

    then to call:

    Class2.senderrortofile(...)

    Wednesday, November 5, 2008 11:17 AM