0

I want to show the error occured, date, error description in a text file.
Following is vb code. Can any one tell me how to write it in vb.net????

Open App.Path & "\ErrorLog" & Replace(Date, "/", "_") & ".txt" For Append As #1
Write #1, "Error in News update Exe:- Form Load Function ---" & Err.Description & "---" & Time
Write #1, "--------------------------------"
Close #1


:'(

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by waynespangler
0

Learn how to:-

-Open a file for writing
-Write to a file
-Use string.replace to replace "/" with "_"
-Close the file

0

It appears that you want to use vb6 code in a Try:Catch block. You do need to learn the things stated above but try this:

Imports System.IO

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x, y As Integer
        y = 0
        Try
            x = 25 / y
        Catch ex As Exception
            Dim filename As String = My.Application.Info.DirectoryPath & "\ErrorLog" & Now.ToShortDateString.Replace("/", "_") & ".txt"
            Dim sw As StreamWriter = New StreamWriter(filename, True)
            sw.WriteLine("Error in News update Exe:- Form Load Function ---" & Err.Description & "---" & Now.ToLocalTime)
            sw.WriteLine("--------------------------------")
            sw.Flush()
            sw.Close()
            MessageBox.Show(filename)

        End Try

    End Sub
End Class
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.