DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

FileNameGet function load order

I am using the function FileNameGet to load selected files into DIAdem.  However, the files are loaded in a different sequence from what I selected and more importantly the order windows displays them. 
 
For example, when the FileNameGet function is called I select the following files in the following order
 
Mod1-7-25-07.dat
Mod1-7-27-07.dat
Mod1-8-06-07.dat
and they are also sequentially shown in the same order in the windows dialog box when selecting the files.  However, when I look at the list file and the order they are loaded into diadem, they are not loaded in the same order.  They are loaded as shown below:
 
Mod1-8-06-07.dat
Mod1-7-25-07.dat
Mod1-7-27-07.dat
 
Is there some way to load the files in the order I select them from as each dataset is based on a day and I would like them to be placed in the report from earliest date to most recent?
 
0 Kudos
Message 1 of 10
(4,385 Views)
Hello Jim,
The LST file is created due to the order in which you mark the files in the dialog. The file you highlight latest will be loaded first. It seems there is some kind of FirstIn - LastOut buffer working in the background.
Now, DIAdem does not include a Script function to sort the content of a textfile but maybe you cand find some algorithm for that in one of the VBS forums online.
Getting the LST into numerical / alphabetical order will solve your issue, I assume.
Alternatively, mark the files in the correct order - starting with the newest and finnishing with the oldest file.
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 2 of 10
(4,366 Views)

Ingo

Thanks for the reply and if that is actually how the function worked then I would be satisfied.  However, it does not load the file (or even save them to the .lst file) in the same order as I select them from the dialog box.

In the attachement I show the dialog box that is opened when the FileNameGet function is used and I select the files sequentially in order Mod1-08-01-07.dat, Mod1-08-02-07.dat, and finally Mod1-08-03-07.dat.  However, the files are loaded as  Mod1-08-03-07.dat, Mod1-08-01-07.dat, Mod1-08-02-07.dat (also the .lst file is attached which shows the same thing although I changed the extension to .txt so it could be attached).

Like I stated above, if it did load the files as I selected them all would be great and that is how I expected it to work.  I would hate to have to write a bunch of code to somehow sort the filenames to overcome the odd behavior of this function so any help anyone has would be appreciated.

 

 

 

Download All
0 Kudos
Message 3 of 10
(4,359 Views)
Hello Jim!
 
From my experience the result list order is unpredictable. I don't know the internal implementation, but I expect that the list is just the result of the Windows file dialog box call. Unfortunately there is no build in sort function in DIAdem! The only solution I see is to implement such a function in script. Just google to 'vbscript array sort' to get some example code.
 
Matthias
Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 4 of 10
(4,348 Views)
Hello JimNoel,
sorry, I guess you missunderstood my explanation.
Please have a close look at the bottom of the dialog screenshot, at the combobox that shows which files you selected. Here you can see, that they are in the order 08-03-07, 08-01-07, 08-02-07. I assume that you first clicked on 03, then on 01, then on 03.
Actually, the LST file represents exactly this order of the files.  That means, the LST file does not resemble the alphabetical order in the upper dialog window, but the inverse order in which you are clicking on the individual files.
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 5 of 10
(4,348 Views)
I guess I will have to correct myself and aggree with Matthias, Watching how rh combobox is populated I found out that my assumption was not correct. It seems like in some cases, the filenames are reordered when additional files are selected.

Hang on, I'll do some more tests
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 6 of 10
(4,345 Views)
I created a workaround for you. This function is reordering the content of the LST file alphabetically:

Option Explicit  'Forces the explicit declaration of all the variables in a script.
 
  '-------------------------------------------------------------------------------
  '  Sorts a listfile alphabetically
  '-------------------------------------------------------------------------------
function sort(Listfile)
  dim line, file, files()
  '   Read LST file into files() variable, remove header comments
  dim buffer
  line = 0
  file = TextFileOpen(Listfile,tfRead)
  Do While Not TextFileEOF(file)
    buffer = TextFileReadLn(file)
    if left(buffer,1) <> "{" then
      line=line+1
      redim preserve files(line)
      files(line) = buffer
    end if
  Loop
  textfileclose file

  '   Bubblesort
  dim done, tmp, i, j

  For i = 1 To ubound(files)
  do
   done = True
   For j = 1 To 6
    If files(i) < files(j) Then
     done = False
     tmp = files(i)
     files(i) = files(j)
     files(j) = tmp
    End If 
   Next
   loop until done
  Next

  '  Rewrite LST file
  file = TextFileOpen(Listfile,tfCreate OR tfWrite OR tfANSI)
  For line = 1 to ubound(files)
    TextfileWriteLn file, files(line)
  Next
  textfileclose file
end function
 
  
  '-------------------------------------------------------------------------------
  ' MAIN
  '-------------------------------------------------------------------------------

sort autoactpath&"list.lst"

Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 7 of 10
(4,337 Views)

Hi Guys,

This is an old problem in DIAdem.  Here is the solution that I always use, which simply alphabetizes the selection by file name, which is usually what the user is intending.  Note that I am patently ignoring the LST file and relying on the "FileDlgFileName" variable, which is filled by the FileNameGet() function in most modern DIAdem versions.  If you happen to have an older DIAdem version, I can send you my previous function, which actually reads in the LST file contents in order to re-order the file names alphabetically.

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 8 of 10
(4,327 Views)

Brad / Ingo

Thanks to both of you for your help.  Rather than using the filesystem object as Ingo suggested, I actually used a bubble sort routine obtained from a coworker (actually looks identical to yours Brad)after selecting the filenames and this takes cares of what I was trying to accomplish.  Thanks again!

0 Kudos
Message 9 of 10
(4,326 Views)

Hello,

 

                Why you are taking more efforts to get the file in order? There are two simple ways available without doing the script.

 

1. Arrange the filename by name

 

2. When selecting the file, notice below the filenames in the filename box. It Looks first in lastout register.

 

Thank you

0 Kudos
Message 10 of 10
(4,125 Views)