12-09-2016 03:36 AM
Dear all,
I just began designing a temperature measuring system with a NI USB TC-01 device. The code is based on the example located at "c:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DotNET4.0\Analog In\Measure Voltage\AcqMultVoltageSamples_SWTimed\VB\MainForm.vb".
However, the Datagrid in VB.net only show 1 line of data (the lastest). Is it possible to display all measured data in the Datagrid?
thanks a lot!
Solved! Go to Solution.
12-12-2016 12:51 PM
Hi,
If you want to display all measured data in the Datagrid, you will need to modify the code in the dataToDataTable function.
Right now, your currentDataIndex is always 0 so you will need to increment it every time the dataToDataTable function is called.
As an example, you can add these lines of code in the for loop in the dataToDataTable function:
Dim rowArr As Object() = New Object(currentChannelIndex) {}
dataTable.Rows.Add(rowArr)
currentDataIndex = currentDataIndex + 1
12-13-2016 12:15 AM
thanks a lot! thuyanhl
Just tested with my usb device, the DataGrid updates only the first row with the latest temperature. The data is saved on c:\file.txt.
Could you be so kind to give me some tips on showing all data and save them all on harddisk? my code is attached.
with my best regards
12-13-2016 03:38 PM
Hi,
The reason your DataGrid is only showing the first row is because your currentChannelIndex is always reinitialized when you call the dataToDataTable. You will need to declare "currentDataIndex" at the beginning of your class in order to be able to increment it in your dataToDataTable function. I hope this helps!
12-15-2016 02:30 AM - edited 12-15-2016 02:31 AM
Dear thuyanhl,
Thanks for your help.
I have declared currentDataIndex and set it to be increased by 1, but still only the first line is updated with the latest temperature. (attached files) >-<
Could you be so kind to take a look at this problem? I am sorry to bother you again.
with my best regards.
12-15-2016 02:58 PM
Hi,
I think you are incrementing your currentChannelIndex before creating the row.
This is the structure you would want:
For currentChannelIndex = 0 To (channelCount - 1)
dataTable.Rows(currentDataIndex)(currentChannelIndex) = sourceArray.GetValue(currentChannelIndex)
Dim rowArr As Object() = New Object(currentChannelIndex) {}
dataTable.Rows.Add(rowArr)
currentDataIndex = currentDataIndex + 1
Next
12-16-2016 12:06 AM
Dear thuyanhl,
Thanks a lot!
I have tried with the modified code and found that still, only the first row is updated (attached pic and code). Am I missing sth?
thanks again.
with my best regards
zen
12-16-2016 09:17 AM
Hi,
As I said before, you need to declare your currentDataIndex outside of your function, as a class variable in order for you to be able to increment it. Else, if your variable is declared inside of the function it is going to be reset to 0 every time you call the dataToDataTable.