Hack Forums
[.NET] On button click, add current time and date to txt file in web - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] On button click, add current time and date to txt file in web (/showthread.php?tid=5946058)



On button click, add current time and date to txt file in web - Formula 1 - Feb 28, 2019

like the title say

when the button is clicked i want it to send the current date and time to txt file (log file)
also userTextBox.Text, so i can see it in this format

username: HackForumsUser
Date: 28/02/2019
Time: 20:58

And then when i click the button again, i want it to add the new one after the old one for example:


username: HackForumsUser
Date: 28/02/2019
Time: 20:58

username: HackForumsUser2
Date: 29/02/2019
Time: 22:58

username: HackForumsUser3
Date: 22/03/2019
Time: 21:58


RE: On button click, add current time and date to txt file in web - Who Soup - Feb 28, 2019

I gotchu, posting to update later.

EDIT:

Things Needed:
  • 2 Textboxes

  • 2 Buttons

  • Imports system.IO

  • Publicly declare: Dim los As New List(Of String)



[Image: 00787c273e5b94fc8f230f1f1388a87d.png]

Add Button:
Code
Dim packet As String = "Username: " & TextBox2.Text & vbNewLine & "Date: " & Date.Now & vbNewLine & "Time:" & TimeOfDay
       TextBox1.Text = TextBox1.Text & vbNewLine & packet
       los.Add(packet)

Save Button:
Code
File.WriteAllLines(Environment.CurrentDirectory & "Saved.txt", los)

Full Code:
Code
Imports System.IO

Public Class Form1

   Dim los As New List(Of String)
   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Dim packet As String = "Username: " & TextBox2.Text & vbNewLine & "Date: " & Date.Now & vbNewLine & "Time:" & TimeOfDay
       TextBox1.Text = TextBox1.Text & vbNewLine & packet
       los.Add(packet)

   End Sub

   Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
       File.WriteAllLines(Environment.CurrentDirectory & "Saved.txt", los)
   End Sub
End Class



RE: On button click, add current time and date to txt file in web - Formula 1 - Feb 28, 2019

(Feb 28, 2019 02:00 PM)Who Soup Wrote:  I gotchu, posting to update later.

EDIT:

Things Needed:
  • 2 Textboxes

  • 2 Buttons

  • Imports system.IO

  • Publicly declare: Dim los As New List(Of String)



[Image: 00787c273e5b94fc8f230f1f1388a87d.png]

Add Button:
Code
Dim packet As String = "Username: " & TextBox2.Text & vbNewLine & "Date: " & Date.Now & vbNewLine & "Time:" & TimeOfDay
       TextBox1.Text = TextBox1.Text & vbNewLine & packet
       los.Add(packet)

Save Button:
Code
File.WriteAllLines(Environment.CurrentDirectory & "Saved.txt", los)

Full Code:
Code
Imports System.IO

Public Class Form1

   Dim los As New List(Of String)
   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Dim packet As String = "Username: " & TextBox2.Text & vbNewLine & "Date: " & Date.Now & vbNewLine & "Time:" & TimeOfDay
       TextBox1.Text = TextBox1.Text & vbNewLine & packet
       los.Add(packet)

   End Sub

   Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
       File.WriteAllLines(Environment.CurrentDirectory & "Saved.txt", los)
   End Sub
End Class

Awesome bro, Thank you!