Click here to Skip to main content
15,887,939 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,
i want to log the data continuously to the text file.
On a first click of button the data logging should start and log the data to txt file
on a second click it should stop the data logging.
how to achieve this
Thanks in advance

What I have tried:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Application.DoEvents()
bt_count3 = bt_count3 + 1
If bt_count3 <= 1 Then
v4klog.FileName = DateTime.Now.ToString("ddMMyyyy") & "_" & DateTime.Now.ToString("HHmmss") & "v4k.xls"
If v4klog.ShowDialog() = Windows.Forms.DialogResult.OK Then
v4klogfile_name = v4klog.FileName
nc1 = 0
nr1 = 2
V4kworkbook = xlapp2.Workbooks.Add(1)
V4kworksheet = V4kworkbook.Sheets("sheet1")
V4kworksheet.Cells(1, 1) = "TR1"
V4kworksheet.Cells(1, 2) = "TR2"

file2_count = 0
Button3.Text = "STOP"
Button3.ForeColor = Color.Red
enable_v4k = True
End If
End If
If bt_count3 >= 2 Then
Button3.Enabled = False
Button3.Text = "START"
Button3.ForeColor = Color.Green
bt_count3 = 0
If enable_v4k = True Then
enable_v4k = False
v4ksave.Visible = True
lbv4ksave_status.Visible = True
For k = 3 To 4002
Application.DoEvents()
V4kworksheet.Cells(1, k) = "C" & k - 2
v4ksave.Value = k
Next
v4ksave.Visible = False
For j = 1 To 10

lbv4ksave.Visible = True
delay1(100)
lbv4ksave.Visible = False
delay1(100)
Next
lbv4ksave_status.Visible = False
Button3.Enabled = True
V4kworksheet.Range("A1:EWX1").HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter
V4kworkbook.SaveAs(v4klogfile_name)
V4kworkbook.Close()
xlapp2.Quit()
End If
End If
End Sub
Posted
Updated 27-Jan-17 6:59am

1 solution

Well your code has nothing to do with logging data to a text file.
However,
The concept you are looking for is "multithreading" and here are some excellent articles here on CodeProject to get you started:
Beginners Guide to Threading in .NET: Part 1 of n[^]
Beginners Guide to Threading in .NET: Part 2 of n - the other articles are referenced from these.

The articles are in C# but look fairly simple to convert to VB.NET. Alternatively do your own search on the multithreading topic now that you know what to research.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900