Hi,
i am acquiring data from serial port and displaying it on a screen using text boxes,i want to log these data to excel file at a rate of 4000 values per second.On first click of a export button data logging should start and log the data for every second on the second click it should stop logging.how to achieve it.
the excel file format is as below
Temp1 Temp2 C1 C2 C3.............C3999 C4000
for ex:
For I = 3 To 4002
Application.DoEvents()
h4kworksheet.Cells(1, I) = "C" & I - 2
h4kworksheet.Cells(2, 1) = temp1_horizontal
h4kworksheet.Cells(2, 2) = temp2_horizontal
h4kworksheet.Cells(2, I) = rf_data_horizontal
h4ksave.Value = I
Next
here in the above code temp1_horizontal value should be placed at 1 coloumn,temp2_horizontal should be placed at 2 coloumn and rf_data_horizontal should be placed from c1 to c4000
if temp1_horizontal=20
temp2_horizontal=30
rf_data_horizontal=2.5
the values should be placed as follows in excel
Temp1 Temp2 C1 C2 C3.............C3999 C4000
20 30 2.5 2.5 2.5 2.5 2.5
20 30 2.5 2.5 2.5 2.5 2.5
What I have tried:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Application.DoEvents()
bt_count2 = bt_count2 + 1
If bt_count2 <= 1 Then
h4klog.FileName = DateTime.Now.ToString("ddMMyyyy") & "_" & DateTime.Now.ToString("HHmmss") & "h4k.xls"
If h4klog.ShowDialog() = Windows.Forms.DialogResult.OK Then
h4klogfile_name = h4klog.FileName
nc = 0
nr = 2
h4kworkbook = xlapp1.Workbooks.Add(1)
h4kworksheet = h4kworkbook.Sheets("sheet1")
h4kworksheet.Cells(1, 1) = "TR1"
h4kworksheet.Cells(1, 2) = "TR2"
file1_count = 0
Button2.Text = "STOP"
Button2.ForeColor = Color.Red
enable_h4k = True
End If
End If
If bt_count2 >= 2 Then
Button2.Enabled = False
Button2.Text = "START"
Button2.ForeColor = Color.Green
bt_count2 = 0
If enable_h4k = True Then
enable_h4k = False
h4ksave.Visible = True
lbh4ksave_status.Visible = True
For I = 3 To 4002
Application.DoEvents()
h4kworksheet.Cells(1, I) = "C" & I - 2
h4kworksheet.Cells(2, 1) = temp1_horizontal
h4kworksheet.Cells(2, 2) = temp2_horizontal
h4kworksheet.Cells(2, I) = rf_data_horizontal
h4ksave.Value = I
Next
h4ksave.Visible = False
For t = 1 To 10
lbh4ksave.Visible = True
delay1(1)
lbh4ksave.Visible = False
delay1(1)
Next
lbh4ksave_status.Visible = False
Button2.Enabled = True
h4kworksheet.Range("A1:EWX1").HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter
h4kworkbook.SaveAs(h4klogfile_name)
h4kworkbook.Close()
xlapp1.Quit()
End If
MsgBox("Done")
End If