DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Sort MyDataFinder.Results by date

I need to sort the result from MyDataFinder.Results by date created.  Is there a function for this? 

I am using 10.2.....

I perform a search and the search returns files to me. (MyDataFinder.Results)
I extract several data points from each file and save them.
I graph the data points in X bar and R charts for rolling stat calculations every week.

I need this data to be sorted by date created so I can say "x" weeks ago I was out of tolerence. 

Below is the code I am using for the search.

sub RUNquery
    Set AdvancedQuery=Navigator.CreateQuery(eAdvancedQuery)
    Call AdvancedQuery.Conditions.Add(eSearchFile,"SiriusID","=",SIDtoSearch_)
    Call AdvancedQuery.Conditions.Add(eSearchFile,"SigGenCOFDM","=",GenToSearch_)
    AdvancedQuery.ReturnType=eSearchFile
    Call Navigator.Display.CurrDataProvider.QueryForm.SetCurrQuery(AdvancedQuery)
end sub

Sub InfoOnTheResultsOfTheQuery
    dim iMaxNumberOfReturndElements
    Set MyDataFinder = Navigator.ConnectDataFinder("My DataFinder")
    Call MyDataFinder.Search(AdvancedQuery)
    set MyResults  = MyDataFinder.Results
    AdvancedQuery.ReturnType=eSearchFile
    MyDataFinder.Results.MaxCount = iMaxNumberOfReturndElements
    Set MyResults  = MyDataFinder.Results
   
    'NEED TO SORT MyResults  by date created.


If MyResults.IsIncomplete Then
      msgbox "The first " & str(MyResults.Count) & " files found (incomplete search)"
    Else
      if str(MyResults.Count) = 0 then
        msgbox "There are no files that match this SID/generator configuration."&vbCr&vbCr&"Did you recently change generators or SPC Samples?"&vbCr&vbCr&"Please contact Brian Banacki."
      else
        msgbox str(MyResults.Count) & "  files found"
      end if
    End If
end Sub

BBANACKI
0 Kudos
Message 1 of 9
(5,129 Views)

Hi bbanacki,

The ResultsList (type = Elements) has a Sort() menthod.  You have to specify which property "column" to sort by and whether to sort descending (TRUE) or ascending (FALSE).  Try this in DIAdem 10.1 or later:

PropName = MyDataFinder.Results.Columns(1).GetPath(MyResults.Elements(1).Type),
MyResults.Sort(PropName,TRUE)

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 2 of 9
(5,119 Views)

I got an error when using the code provided
     "Object doesn't support this property or method: 'MyDataFinder.Results.Columns'"
 
I used the help to get the following code which is close to what you gave me:

Dim oMyResultsList
Set oMyResultsList = Navigator.Display.CurrDataProvider.ResultsList
Call oMyResultsList.Elements.Sort(oMyResultsList.Columns(3).GetPath(oMyResultsList.Elements(1).Type),FALSE)

This code executes fine although I am unfamiliar with how to use what it returns (oMyResultsList) and it doesnt sort MyDataFinder.Results. 


I use MyDataFinder.Results to open each individual file to extract the data I need.  What is returned after this sort method?  It doesnt seem to sort the MyDataFinder.Results. I used the help to find an example and pasted it below.



BBANACKI
0 Kudos
Message 3 of 9
(5,116 Views)
Hey bbanacki,

I've been playing around with the example code too (a combination of what you provided [after some modifications to get it to run on my machine] and the example from the help document).  The code seems to work fine for me so I must be close.  I attached my simplified code to this post. 

Note that you have to change the boolean input to the Sort method to adjust ascending and descending order.

In which column (#) is your File.Creation Date?  Make sure you adjust the index of the Columns collection to correspond to your appropriate File.Creation Date column.

I hope this helps!
Derrick S.
Product Manager
NI DIAdem
National Instruments
0 Kudos
Message 4 of 9
(5,107 Views)
DRock and Brad,

First of all, thank you for your help. 

I have the code sorting by the column specified (I sorted column 3).  Although after I perform the sort I need to load the files in the "new" sorted order, but the way I am loading the files they are still in the "old" unsorted order.  Below is the command I am using to load the files.  Is there a command I have missed to change the order of the MyResults????

DataFileToLoad = str(MyResults(iLoop).Properties("fullpath").Value)



Attached is the full script I am using.

BBANACKI
0 Kudos
Message 5 of 9
(5,084 Views)

Hi BBANACKI,

Try this code that loads the starndard TR_* data files that DIAdem installs-- change the FALSE to TRUE to see the load order invert:

Brad Turpin
DIAdem Product Support Engineer
National Instruments

Set MyDataFinder = Navigator.ConnectDataFinder("My DataFinder")
Set AdvancedQuery = Navigator.CreateQuery(eAdvancedQuery)
AdvancedQuery.ReturnType = eSearchFile
Call AdvancedQuery.Conditions.Add(eSearchFile,"FileName","=","TR_*")
Call MyDataFinder.Search(AdvancedQuery)
Set Elements = MyDataFinder.Results
iMax = Elements.Count
IF iMax > 4 THEN iMax = 4
Call DataDelAll
Call Elements.Sort("FileName", FALSE)
FOR i = 1 TO iMax
  LastGroup = GroupCount
  Call Navigator.LoadData(Elements(i), "Register")
  FOR j = LastGroup+1 TO GroupCount
    GroupName(j) = GroupName(j) & " - " & Elements(i).Name
  NEXT ' j
NEXT ' i

0 Kudos
Message 6 of 9
(5,070 Views)
Brad

This code works great for sorting by the FileName, Unfortunately we didn't use a file naming convention that would be that easy (lucky me). 
I need to sort by date created.  I tried simply changing FileName to DateCreated and found that its not that easy.  I cannot find to much information in the Help on this sort issue. 

Call Elements.Sort("FileName", true)
BBANACKI
0 Kudos
Message 7 of 9
(5,064 Views)

Hi BBANACKI,

What is the exact name of the property you want to search on, as it appears in the property table below the tree view or search results list in the NAVIGATOR?  Is this the Windows file creation date, the "Storage datetime" that is standard for DataPlugins, or is this a custom date/time property you have created?

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 8 of 9
(5,052 Views)

Thanks for your help,

I found out the final piece of the puzzle.... My sort function now sorts by file modify date!!!! sweet.

To sort by modify date I needed to use "modifyTime" in my script..



Modify date — Specifies when the data set was last modified in the operating system.

Script name modifyTime
Data type DataTypeDate
DataFinder Search possible
BBANACKI
0 Kudos
Message 9 of 9
(4,967 Views)