Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Datagrid question

Solved!
Go to solution

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!

Download All
0 Kudos
Message 1 of 8
(9,262 Views)
Solution
Accepted by topic author zenman88

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

T. Le
Vision Product Support Engineer
National Instruments
0 Kudos
Message 2 of 8
(9,221 Views)

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

 

0 Kudos
Message 3 of 8
(9,215 Views)

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! 

T. Le
Vision Product Support Engineer
National Instruments
0 Kudos
Message 4 of 8
(9,208 Views)

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.

Download All
0 Kudos
Message 5 of 8
(9,199 Views)

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

T. Le
Vision Product Support Engineer
National Instruments
0 Kudos
Message 6 of 8
(9,186 Views)

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

Download All
0 Kudos
Message 7 of 8
(9,176 Views)

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. 

 

T. Le
Vision Product Support Engineer
National Instruments
0 Kudos
Message 8 of 8
(9,169 Views)