如何连续记录数据到excel文件vb中每秒4000个值的速率。 [英] How to log the data continuously to excel file the rate of 4000 values per second in vb.
问题描述
i从串口获取数据并使用文本框在屏幕上显示,我想以每秒4000个值的速率将这些数据记录到excel文件中。首次点击导出按钮数据记录应该开始并在第二次点击时记录每秒的数据它应该停止记录。如何实现它。
excel文件格式如下
Temp1 Temp2 C1 C2 C3 ............. C3999 C4000
例如:
For I = 3 To 4002
Application.DoEvents()
h4kworksheet.Cells(1,I)=C&我 - 2
h4kworksheet.Cells(2,1)= temp1_horizontal
h4kworksheet.Cells(2,2)= temp2_horizontal
h4kworksheet.Cells (2,I)= rf_data_horizontal
h4ksave.Value = I
下一页
这里的上面代码temp1_horizontal值应该放在1 coloumn,temp2_horizontal应该放在2 coloumn,rf_data_horizontal应该从c1到c4000
如果temp1_horizontal = 20
temp2_horizontal = 30
rf_data_horizontal = 2.5
值应放在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
我的尝试:
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
推荐答案
如果您需要对数据进行静态分析,请使用VB
程序从串口收集数据(将它们存储在内存中)。在这种数据收集过程结束时,使用数据创建工作表并享受Excel
的强大功能。
当然有一些警告。您的VB
应用程序必须能够跟上串行端口上的传输速率,并且它应该有足够的内存来临时存储所需的数据量。
If you need a statical analysis of the data then use yourVB
program to collect the data from the serial port (store them in memory). At the end of such 'data-collection' process create the sheet with the data and enjoy the power ofExcel
.
There are caveats, of course. YourVB
application must be able to keep up with the transmission rate on the serial port and it should have enough memory to temporarily store the wanted amount of data.
这篇关于如何连续记录数据到excel文件vb中每秒4000个值的速率。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!