DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

FileDlgNameList Loading Order

Solved!
Go to solution

Hello

 

I have have come across this issue for some time and I was wondering if this is normal or if it is in fact a bug.

 

Here is what I am doing

 

I make a function call and grab multiple files using "Call FileDlgShow" function and I allow the function to grab multiple files.

 

So for illustrative purposes I have three files which I selected below

 

file1

file2

file3

 

When I loop the FileDlgNameList it returns the files in the following order

 

file2

file3

file1

 

Basically it allows return the first file selected last.

 

Below is the code I am using

    Call FileDlgShow(DataReadPath, "DAT Data File, *.Dat", "Data selection", True)     'Calls a data browser's


     
      
     For Each sElement in  FileDlgNameList
    
      Call DataFileLoad(sElement, "H01-VFTS-01", "Load")
      
    Next 

 

Any ideas?

 

I am using DIAdem 2015 32 bit

Tim
0 Kudos
Message 1 of 5
(4,983 Views)

Hello Tim,

 

The "FileDlgShow" command is in the end a configured Windows standard dialog. The result order of the selected files has to do something with order of selecting, but does not exactly represent it. Unfortunately do we have no influence on it.

 

Greetings

Walter

0 Kudos
Message 2 of 5
(4,956 Views)

Thanks Walter.

 

I have used a work around in the past where the last item in the list is loaded first followed by all successive items.

 

Kind of weird it does this though.

Tim
0 Kudos
Message 3 of 5
(4,945 Views)

Hi Tim,

 

If your files happen to be named so that an alphabetical sorting is what is desired, then I often use the following simple bubble sort:

 

Dim i, DlgTitle, StartPath, FiltExts
FiltExts = "TDMS Files,*.tdms|TDM Files,*.tdm"
DlgTitle = "Select the Data Files to Process..."
StartPath = "C:\Users\Public\Documents\National Instruments\DIAdem 2012\Data" 'CurrentScriptPath
Call FileDlgShow(StartPath, FiltExts, DlgTitle, TRUE)
IF DlgState <> "IDCancel" THEN
  FilePaths = BubbleSort0(FileDlgNameList) ' sort the array of file names alphabetically
'  FOR i = 1 TO UBound(FilePaths)
'    Call DataFileLoad(FilePaths(i), "")
'  NEXT
  MsgBox OutputArray(FilePaths)
END IF ' file(s) selected


Function BubbleSort0(NamesToSort)
  Dim i, iMin, iMax, SwapName, Swapped
  IF NamesToSort(0) = "" THEN iMin = 1 ELSE iMin = 0
  iMax = UBound(NamesToSort)
  ReDim SortedNames(1-iMin+iMax)
  FOR i = 1 TO 1-iMin+iMax
    SortedNames(i) = NamesToSort(i-1+iMin)
  NEXT ' i
  Do ' Until bubble sort of NamesToSort() is finished
    Swapped = False
    FOR i = 0 TO UBound(SortedNames)-1
      IF StrComp(UCase(SortedNames(i)), UCase(SortedNames(i+1))) > 0 THEN
        SwapName  = SortedNames(i)
        SortedNames(i)   = SortedNames(i+1)
        SortedNames(i+1) = SwapName
        Swapped = True
      END IF ' Name(i) and Name(i+1) need to be swapped
    NEXT ' i
  Loop Until NOT (Swapped)
BubbleSort0 = SortedNames
End Function ' BubbleSort0()


Function OutputArray(ArrayVar)
  Dim i, HdrMsg, Msg
  HdrMsg = "   i  " & vbTAB & "ArrayValues(i)" & vbCRLF
  HdrMsg = HdrMsg & "-----" & vbTAB & String(60, "-")
  FOR i = 1 TO UBound(ArrayVar)
    Msg = Msg & "  " & i & "  " & vbTAB & ArrayVar(i) & vbCRLF
  NEXT ' i
OutputArray = Msg
End Function ' OutputArray()

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 4 of 5
(4,883 Views)
Solution
Accepted by topic author smoothdurban

Thanks Brad

 

Sorting them is helpful but I was more interested in loaded them as the are selected as opposed to loading the first selected file last.

 

My solution was simple

 

For i = 0 to Ubound(FileDlgNameList)  
    If i = 0 Then 
        Call DataFileLoad(FileDlgNameList(Ubound(FileDlgNameList)
    Else
        Call DataFileLoad(FileDlgNameList(i-1)
 
    End If

Next

3

 

Tim
0 Kudos
Message 5 of 5
(4,847 Views)