From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
11-15-2019 09:48 AM
DIAdem 19.0.0f7460 (64-bit); DataFinder 19.0.0f7456
The file property "Test~Module" is an integer value and the data type is DataTypeInt16.
Unable to assign DataTypeInt16 or DataTypeInt32 as the column type for this property.
Only DataTypeFloat64 and DataTypeUnknown will be accepted without triggering an error.
Run the script below to see the error.
Call LogFileDel
'Optimize specific properties on My DataFinder
Dim oPropertiestoOptimizeDic, sFolder
sFolder = NameSplit(sFilePathDIAdemExample("TR_M17_QT_32-1.tdm"),"P")
Set oPropertiestoOptimizeDic = CreateObject("Scripting.Dictionary")
Call oPropertiestoOptimizeDic.Add("UUT", Array(eSearchFile,DataTypeString))
Call oPropertiestoOptimizeDic.Add("Test~Module", Array(eSearchFile,DataTypeInt32))
'Call oPropertiestoOptimizeDic.Add("Test~Module", Array(eSearchFile,DataTypeFloat64))
Call oPropertiestoOptimizeDic.Add("Test~Name", Array(eSearchFile,DataTypeString))
Call oPropertiestoOptimizeDic.Add("Test~Operator", Array(eSearchFile,DataTypeString))
Call oPropertiestoOptimizeDic.Add("Test~Procedure", Array(eSearchFile,DataTypeString))
Call oPropertiestoOptimizeDic.Add("Test~ProductionDate", Array(eSearchFile,DataTypeDate))
If Not bOptimizeDataFinderProperties("My DataFinder", oPropertiestoOptimizeDic) Then Call Err.Raise(65535,,"ERROR - bOptimizeDataFinderProperties()")
'Re-index the folder that contains the example files "TR_M17_QT*.tdm*"
If Not bResetMyDataFinderSearchFolder(sFolder, True) Then Call Err.Raise(65535,,"ERROR - bResetMyDataFinderSearchFolder()")
Call Navigator.Display.CurrDataFinder.QueryForm.Clear
Navigator.Display.CurrDataFinder.QueryForm.ReturnType = eSearchFile
Call Navigator.Display.CurrDataFinder.QueryForm.Conditions.RemoveAll
Call Navigator.Display.CurrDataFinder.QueryForm.Conditions.Add(eSearchFile,"Filename","=","TR_M17_QT*.tdm*")
Call Navigator.Display.CurrDataFinder.QueryForm.Conditions.Add(eSearchFile,"Folder","=",sFolder)
Navigator.Display.CurrDataFinder.QueryForm.ResultsMode = eResultsModeProperties 'column-oriented / properties search
Call Navigator.Display.CurrDataFinder.ResultsList.Columns.RemoveAll
Call Navigator.Display.CurrDataFinder.ResultsList.Columns.Add(eSearchFile, "filename", DataTypeString)
Call Navigator.Display.CurrDataFinder.ResultsList.Columns.Add(eSearchFile, "UUT", DataTypeString)
Call Navigator.Display.CurrDataFinder.ResultsList.Columns.Add(eSearchFile, "Test~ProductionDate", DataTypeDate)
'The uncommented statements below results in the error: "The value of the argument DataType of the method Add is not valid."
'If you inspect the data type for this file property by looking at the search results, it will be DataTypeInt16.
'The only data type that doesn't cause an error is DataTypeFloat64 and DataTypeUnknown
'Call Navigator.Display.CurrDataFinder.ResultsList.Columns.Add(eSearchFile, "Test~Module", DataTypeInt16)
Call Navigator.Display.CurrDataFinder.ResultsList.Columns.Add(eSearchFile, "Test~Module", DataTypeInt32)
Function sFilePathDIAdemExample(ByVal sFilename)
'Returns the full absolute file/path for the location of the DIAdem
'example (TDM/TDMS) file sFilename. Looks in the usual places.
'Returns "" if the file cannot be found.
'v20191023
sFilePathDIAdemExample = ""
Dim arrFilePaths, sFilePath, sFolder: ReDim arrFolders(1): arrFolders(0) = ProgramDrv: arrFolders(1) = CommonDocumentsPath
For Each sFolder In arrFolders
arrFilePaths = DirListGet(sFolder,sFilename,"Date/Time","FullFilenamesRecursive")
If IsArray(arrFilePaths) Then
For Each sFilePath In arrFilePaths
If InStr(1,sFilePath,"Libr",vbTextCompare) = 0 Then sFilePathDIAdemExample = sFilePath: Exit For
Next
End If
If Len(sFilePathDIAdemExample) > 0 Then Exit For
Next
If IsArray(arrFilePaths) Then Call Erase(arrFilePaths)
If IsArray(arrFolders) Then Call Erase(arrFolders)
End Function 'sFilePathDIAdemExample()
Function bOptimizeDataFinderProperties(ByVal sDataFinderName, ByVal oPropertiesDic)
'Optimize the properties specified in oPropertiesDic
'(key = property name, 'value = Array(Type, OptimizedDataType)
' Type: eSearchFile, eSearchChannelGroup, eSearchChannel
' OptimizedDataType: DataTypeString, DataTypeInt32, DataTypeFloat64, DataTypeDate
bOptimizeDataFinderProperties = False
Call MsgLineDisp("Optimizing " & oPropertiesDic.Count & " custom properties for files on My DataFinder..")
Dim oDataFinder, oSettings, sProperty, lErr, sErr, arrValue
Set oDataFinder = Navigator.ConnectDataFinder(sDataFinderName)
If oDataFinder Is Nothing Then Exit Function
Set oSettings = oDataFinder.GetSettings()
bOptimizeDataFinderProperties = True
For Each sProperty In oPropertiesDic
'Call LogFileWrite("Optimizing property '" & sProperty & "' of type " & oPropertiesDic(sProperty) & " on " & oDataFinder.Name)
arrValue = oPropertiesDic(sProperty)
If Not IsArray(arrValue) Then
Call LogFileWrite("ERROR - value of oPropertiesDic passed to bOptimizeDataFinderProperties() is not an array")
Exit Function
End If
On Error Resume Next
'OptimizeCustomProperty(Type, PropertyName, [OptimizedDataType])
'Type: eSearchFile, eSearchChannelGroup, eSearchChannel
'OptimizedDataType: DataTypeString, DataTypeInt32, DataTypeFloat64, DataTypeDate
Call oSettings.OptimizeCustomProperty(arrValue(0), sProperty, arrValue(1))
lErr = Err.number: sErr = Err.Description: On Error Goto 0
If lErr = 269 Then
Call LogFileWrite("The property has not been indexed yet on" & sDataFinderName)
bOptimizeDataFinderProperties = False 'The property has not been indexed yet on sDataFinderName
ElseIf lErr <> 0 Then
Call LogFileWrite(sProperty & " ERROR " & lErr & vbTab & sErr)
Call LogFileWrite(sProperty & " Type: " & arrValue(0))
Call LogFileWrite(sProperty & " OptimizedDataType: " & sDataTypeForProperty(arrValue(1)))
bOptimizeDataFinderProperties = False
End If
Next
Call MsgLineDisp(vbTab)
Set oSettings = Nothing: Set oDataFinder = Nothing
End Function 'bOptimizeDataFinderProperties()
Function bResetMyDataFinderSearchFolder(ByVal sFolder, ByVal bShowMsgBox)
bResetMyDataFinderSearchFolder = False
Dim oDF, oIndexer, iLastDisp, sMsg
Const iTimeoutSec = 180, iTimer = 12
iLastDisp = 0
If Not FolderExist(sFolder) Then
Call LogFileWrite("ERROR - folder does not exist " & sFolder & " bResetMyDataFinderSearchFolder()")
Exit Function
End If
Call StopWatchReset(iTimer)
If bShowMsgBox Then
sMsg = "Reseting My DataFinder index for folder " & sFolder & ".."
Call MsgBoxDisp(sMsg,"MB_NOBUTTON", "MsgTypeNote", MsgStdButton, MsgTimeOut, True)
End If
Set oDF = Navigator.ConnectDataFinder("My DataFinder")
'oDF.Refresh & oDF.Reset don't resolve index problem (unless indexing specific files failed)
Set oIndexer = oDF.Indexer
'Call oIndexer.IndexFolder() will resolve refresh the index so that a query
'using custom properties executes without an error.
Call oIndexer.IndexFolder(sFolder, True, True)
'Call oIndexer.UpdateSearchArea() will NOT refresh the index so that a
'query using custom properties executes without an error.
'*** NOTE: The parameter passed to oIndexer.UpdateSearchArea() is the
'search area Path without a trailing "\".
'Call oIndexer.UpdateSearchArea(Mid(sFolder,1,Len(sFolder)-1))
Call StopWatchPause(iTimer)
If bShowMsgBox Then
Call LogFileWrite(Str(StopWatch(iTimer),"d.d") & " sec required to reset My DataFinder search folder '" & sFolder & "'")
Else
If Int(StopWatch(iTimer)) > 2 Then Call LogFileWrite(Str(StopWatch(iTimer),"d.d") & " sec required to reset My DataFinder search folder '" & sFolder & "'")
End If
If bShowMsgBox Then Call MsgBoxCancel
Set oDF = Nothing: Set oIndexer = Nothing
bResetMyDataFinderSearchFolder = True
End Function ' bResetMyDataFinderSearchFolder()
11-18-2019 04:36 PM
Hi Mark,
When I run your posted code, I get a type mismatch error on line 86. As far as I can tell, the variable "sDataTypeForProperty" appears nowhere else in the code. Do you have that declared as a global variable? It would have to be an array to index it like is happening in line 86. Also it would have to be an array with 0..23 index values at least, because you're requesting sDataTypeForProperty(23) in that line, since arrValue(1)=23 at that moment (at least on my computer).
So far I'm not convinced it's a data type problem.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
11-19-2019 06:51 AM
Sorry about the missing function sDataTypeForProperty(). If you remove it and just print out the integer value, it should have been the integer value for DataTypeInt32. HOWEVER - I no longer experience the error, and I cannot explain why. I spent a lot of time debugging this problem, and now it has gone away. I suspect it may have been duplicates of the same files in multiple My DataFinder search folders. After I reported that error, I removed some of those search folders.
Bottom line: No problem exists with optimized integer file property for a Navigator result column.
I am posting below a revised script, should someone wish to run the test.
'Optimize the file properties for the DIAdem example files "TR_M17_QT_32*" and then
'build a Navigator query to show those properties.
Call LogFileDel
'Optimize specific properties on My DataFinder
Dim oPropertiestoOptimizeDic, sFolder
sFolder = NameSplit(sFilePathDIAdemExample("TR_M17_QT_32-1.tdm"),"P")
If Len(sFolder) = 0 Then Call Err.Raise(65535,,"ERROR - DIAdem example file not found")
Set oPropertiestoOptimizeDic = CreateObject("Scripting.Dictionary")
Call oPropertiestoOptimizeDic.Add("UUT", Array(eSearchFile,DataTypeString))
Call oPropertiestoOptimizeDic.Add("Test~Module", Array(eSearchFile,DataTypeInt32))
Call oPropertiestoOptimizeDic.Add("Test~Name", Array(eSearchFile,DataTypeString))
Call oPropertiestoOptimizeDic.Add("Test~Operator", Array(eSearchFile,DataTypeString))
Call oPropertiestoOptimizeDic.Add("Test~Procedure", Array(eSearchFile,DataTypeString))
Call oPropertiestoOptimizeDic.Add("Test~ProductionDate", Array(eSearchFile,DataTypeDate))
If Not bOptimizeDataFinderProperties("My DataFinder", oPropertiestoOptimizeDic) Then Call Err.Raise(65535,,"ERROR - bOptimizeDataFinderProperties()")
'Re-index the folder that contains the example files "TR_M17_QT*.tdm*"
If Not bResetMyDataFinderSearchFolder(sFolder, True) Then Call Err.Raise(65535,,"ERROR - bResetMyDataFinderSearchFolder()")
Call Navigator.Display.CurrDataFinder.QueryForm.Clear
Navigator.Display.CurrDataFinder.QueryForm.ReturnType = eSearchFile
Call Navigator.Display.CurrDataFinder.QueryForm.Conditions.RemoveAll
Call Navigator.Display.CurrDataFinder.QueryForm.Conditions.Add(eSearchFile,"Filename","=","TR_M17_QT*.tdm*")
Call Navigator.Display.CurrDataFinder.QueryForm.Conditions.Add(eSearchFile,"Folder","=",sFolder)
Navigator.Display.CurrDataFinder.QueryForm.ResultsMode = eResultsModeProperties 'column-oriented / properties search
Call Navigator.Display.CurrDataFinder.ResultsList.Columns.RemoveAll
Call Navigator.Display.CurrDataFinder.ResultsList.Columns.Add(eSearchFile, "filename", DataTypeString)
Call Navigator.Display.CurrDataFinder.ResultsList.Columns.Add(eSearchFile, "UUT", DataTypeString)
Call Navigator.Display.CurrDataFinder.ResultsList.Columns.Add(eSearchFile, "Test~ProductionDate", DataTypeDate)
Call Navigator.Display.CurrDataFinder.ResultsList.Columns.Add(eSearchFile, "Test~Module", DataTypeInt32)
Call WndShow("NAVIGATOR")
Function sFilePathDIAdemExample(ByVal sFilename)
'Returns the full absolute file/path for the location of the DIAdem
'example (TDM/TDMS) file sFilename. Looks in the usual places.
'Returns "" if the file cannot be found.
'v20191119
sFilePathDIAdemExample = ""
Dim arrFilePaths, sFilePath, sFolder: ReDim arrFolders(2): arrFolders(0) = ProgramDrv: arrFolders(1) = CommonDocumentsPath: arrFolders(2) = GetEnv("PUBLIC")
For Each sFolder In arrFolders
arrFilePaths = DirListGet(sFolder,sFilename,"Date/Time","FullFilenamesRecursive")
If IsArray(arrFilePaths) Then
For Each sFilePath In arrFilePaths
If InStr(1,sFilePath,"Libr",vbTextCompare) = 0 Then sFilePathDIAdemExample = sFilePath: Exit For
Next
End If
If Len(sFilePathDIAdemExample) > 0 Then Exit For
Next
If IsArray(arrFilePaths) Then Call Erase(arrFilePaths)
If IsArray(arrFolders) Then Call Erase(arrFolders)
End Function 'sFilePathDIAdemExample()
Function bOptimizeDataFinderProperties(ByVal sDataFinderName, ByVal oPropertiesDic)
'Optimize the properties specified in oPropertiesDic
'(key = property name, 'value = Array(Type, OptimizedDataType)
' Type: eSearchFile, eSearchChannelGroup, eSearchChannel
' OptimizedDataType: DataTypeString, DataTypeInt32, DataTypeFloat64, DataTypeDate
bOptimizeDataFinderProperties = False
Call MsgLineDisp("Optimizing " & oPropertiesDic.Count & " custom properties for files on My DataFinder..")
Dim oDataFinder, oSettings, sProperty, lErr, sErr, arrValue
Set oDataFinder = Navigator.ConnectDataFinder(sDataFinderName)
If oDataFinder Is Nothing Then Exit Function
Set oSettings = oDataFinder.GetSettings()
bOptimizeDataFinderProperties = True
For Each sProperty In oPropertiesDic
'Call LogFileWrite("Optimizing property '" & sProperty & "' of type " & oPropertiesDic(sProperty) & " on " & oDataFinder.Name)
arrValue = oPropertiesDic(sProperty)
If Not IsArray(arrValue) Then
Call LogFileWrite("ERROR - value of oPropertiesDic passed to bOptimizeDataFinderProperties() is not an array")
Exit Function
End If
On Error Resume Next
'OptimizeCustomProperty(Type, PropertyName, [OptimizedDataType])
'Type: eSearchFile, eSearchChannelGroup, eSearchChannel
'OptimizedDataType: DataTypeString, DataTypeInt32, DataTypeFloat64, DataTypeDate
Call oSettings.OptimizeCustomProperty(arrValue(0), sProperty, arrValue(1))
lErr = Err.number: sErr = Err.Description: On Error Goto 0
If lErr = 269 Then
Call LogFileWrite("The property has not been indexed yet on" & sDataFinderName)
bOptimizeDataFinderProperties = False 'The property has not been indexed yet on sDataFinderName
ElseIf lErr <> 0 Then
Call LogFileWrite(sProperty & " ERROR " & lErr & vbTab & sErr)
Call LogFileWrite(sProperty & " Type: " & arrValue(0))
Call LogFileWrite(sProperty & " OptimizedDataType: " & sDataTypeForProperty(arrValue(1)))
bOptimizeDataFinderProperties = False
End If
Next
Call MsgLineDisp(vbTab)
Set oSettings = Nothing: Set oDataFinder = Nothing
End Function 'bOptimizeDataFinderProperties()
Function bResetMyDataFinderSearchFolder(ByVal sFolder, ByVal bShowMsgBox)
bResetMyDataFinderSearchFolder = False
Dim oDF, oIndexer, iLastDisp, sMsg
Const iTimeoutSec = 180, iTimer = 12
iLastDisp = 0
If Not FolderExist(sFolder) Then
Call LogFileWrite("ERROR - folder does not exist " & sFolder & " bResetMyDataFinderSearchFolder()")
Exit Function
End If
Call StopWatchReset(iTimer)
If bShowMsgBox Then
sMsg = "Reseting My DataFinder index for folder " & sFolder & ".."
Call MsgBoxDisp(sMsg,"MB_NOBUTTON", "MsgTypeNote", MsgStdButton, MsgTimeOut, True)
End If
Set oDF = Navigator.ConnectDataFinder("My DataFinder")
'oDF.Refresh & oDF.Reset don't resolve index problem (unless indexing specific files failed)
Set oIndexer = oDF.Indexer
'Call oIndexer.IndexFolder() will resolve refresh the index so that a query
'using custom properties executes without an error.
Call oIndexer.IndexFolder(sFolder, True, True)
'Call oIndexer.UpdateSearchArea() will NOT refresh the index so that a
'query using custom properties executes without an error.
'*** NOTE: The parameter passed to oIndexer.UpdateSearchArea() is the
'search area Path without a trailing "\".
'Call oIndexer.UpdateSearchArea(Mid(sFolder,1,Len(sFolder)-1))
Call StopWatchPause(iTimer)
If bShowMsgBox Then
Call LogFileWrite(Str(StopWatch(iTimer),"d.d") & " sec required to reset My DataFinder search folder '" & sFolder & "'")
Else
If Int(StopWatch(iTimer)) > 2 Then Call LogFileWrite(Str(StopWatch(iTimer),"d.d") & " sec required to reset My DataFinder search folder '" & sFolder & "'")
End If
If bShowMsgBox Then Call MsgBoxCancel
Set oDF = Nothing: Set oIndexer = Nothing
bResetMyDataFinderSearchFolder = True
End Function ' bResetMyDataFinderSearchFolder()
Function sDataTypeForProperty(ByVal iDataType)
'Returns a string name for the DataType corresponding
'to the DataStore property DataType as an integer (enumeration).
'See Function oGetFilePropsOfNonIndexedTdmsOrTdmFileAsDic() for an example that uses this function.
Select Case iDataType
Case 0
sDataTypeForProperty = "DataTypeUnknown"
Case 1
sDataTypeForProperty = "DataTypeInt8" '8-bit integer values
Case 2
sDataTypeForProperty = "DataTypeInt16"
Case 3
sDataTypeForProperty = "DataTypeInt32"
Case 4
sDataTypeForProperty = "DataTypeInt64" '64-bit integer values
Case 5
sDataTypeForProperty = "DataTypeUInt8" 'Unsigned 8-bit integer values
Case 6
sDataTypeForProperty = "DataTypeUInt16" 'Unsigned 16-bit integer values
Case 7
sDataTypeForProperty = "DataTypeUInt32"
Case 8
sDataTypeForProperty = "DataTypeUInt64"
Case 9
sDataTypeForProperty = "DataTypeFloat32" '32-bit real values
Case 10
sDataTypeForProperty = "DataTypeFloat64"
Case 23
sDataTypeForProperty = "DataTypeString"
Case 24
sDataTypeForProperty = "DataTypeEnum" 'Enumeration
Case 30
sDataTypeForProperty = "DataTypeDate" 'Time
End Select 'iDataType
End Function 'sDataTypeForProperty()