martes, 21 de febrero de 2017

Clase Visual Basic .NET para grabar / mostrar un archivo de texto (log)

Imports System.IO

Public Class clsLog
    Dim m_filename As String = ""
    Private m_sw As StreamWriter = Nothing
    Private m_bAppend As Boolean

    Public Sub New(ByVal strPathLogFile As String, Optional ByVal bAppend As Boolean = True)
        m_filename = strPathLogFile
        m_bAppend = bAppend
        Try
            m_sw = New StreamWriter(m_filename, bAppend)
            m_sw.Close()
        Catch ex As Exception
            Debug.WriteLine(ex.Message)
        End Try
    End Sub

    Protected Overrides Sub Finalize()
        Dispose()
        MyBase.Finalize()
    End Sub

    Private Sub Dispose()
        Try
            m_sw = Nothing
        Catch ex As Exception
            Debug.WriteLine(ex.Message)
        End Try
    End Sub

    Public Sub Log(strValue As String)
        Try
            m_sw = New StreamWriter(m_filename, m_bAppend)
            m_sw.WriteLine(strValue)
            m_sw.Flush()
            m_sw.Close()
        Catch ex As Exception
            Debug.WriteLine(ex.Message)
        End Try
    End Sub

    Public Sub ShowLog()
        If System.IO.File.Exists(m_filename) Then
            Process.Start(m_filename)
        End If
    End Sub

End Class

No hay comentarios:

Publicar un comentario

VBA Access. Redondeo de números decimales con el método medio redondeo. Alternativa a la función Round (bankers round)

 Private Function Redondeo(ByVal Numero As Variant, ByVal Decimales As Integer) As Double     'Aplica método medio redondeo (half round ...