03-13-2012 07:08 PM
Hello,
I am using a script to load 4 files in th Data portal and later graph some selected channels. The problem is that when I choose the files through a dialog box, the order gets mixed up in the data portal. I would like the files to be sorted according to the source filename. Here is the loading script:
Dim i, intLoop, Group,b Call Data.Root.Clear() If FileDlgShow(DataReadPath,"TDMS Files,*.tdms","DataSelection",True) = "IDOk" Then For i = 0 to UBound(FileDlgNameList) Call DataFileLoad(FileDlgNameList(i),"TDMS","Load") DataFilename,FileImportFilter,ImportAction Next End If
Is there any way I can do that?
Thank you!
Solved! Go to Solution.
03-14-2012 06:03 AM
Hi Saloutios,
You can sort the FileDlgNameList Array for example using the BubbleSort algorithm:
Sub BubbleSort(arr) Dim value, numEls Dim index Dim firstItem Dim indexLimit, lastSwap ' account for optional arguments numEls = UBound(arr) firstItem = LBound(arr) lastSwap = numEls Do indexLimit = lastSwap - 1 lastSwap = 0 For index = firstItem To indexLimit value = arr(index) If (value > arr(index + 1)) Then ' if the items are not in order, swap them arr(index) = arr(index + 1) arr(index + 1) = value lastSwap = index End If Next Loop While lastSwap End Sub
The input array is sorted after you called that procedure.
Hope this helps
Winfried
03-16-2012 11:27 AM
@winner wrote:
Hi Saloutios,
You can sort the FileDlgNameList Array for example using the BubbleSort algorithm:
Sub BubbleSort(arr) Dim value, numEls Dim index Dim firstItem Dim indexLimit, lastSwap ' account for optional arguments numEls = UBound(arr) firstItem = LBound(arr) lastSwap = numEls Do indexLimit = lastSwap - 1 lastSwap = 0 For index = firstItem To indexLimit value = arr(index) If (value > arr(index + 1)) Then ' if the items are not in order, swap them arr(index) = arr(index + 1) arr(index + 1) = value lastSwap = index End If Next Loop While lastSwap End SubThe input array is sorted after you called that procedure.
Hope this helps
Winfried
Hi Winfried,
Thank you very much for the reply. That worked just fine for me!
Cheers!