DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems in Sub ReadStore(file)

hello everyone!
 
I wrote the sub ReadStore(file), but there are some things, i don't understand:
 
1. why i get errors, when i try to implement a message box with MsgBox("text") or with call MsgBoxDisp("text")
 
2. how can i create file-object? cause i want to test my sub in the diadem-editor. because it is a sub, i have to call it from somewhere, for this a need a fileobject.
 
3. i have txt-file with my datas, this file represents a tabelle with values. i want to order them by one column, so i have to diver the channelgroups. For this i check, if the raw has same value in this column  like the value of the next raw. if not, i check if the root has already a channelgroup with same name:
 
if root.channelgroups.exists("name")
 
if this is the case, i need something like
 
set channelgroup = root.channelgroups.item("name")
 
but there it crashes...
 
you have to know, that i have no experience with vbs and diadem. I hope somebody can help me...
 
thank you for your help....i'm sorry, that i cannot post the script...
 
mfg f-zoid...
0 Kudos
Message 1 of 4
(3,474 Views)

Hi f-zoid,

The first thing you need to realize is that the ReadStore() subroutine is used inside a DataPlugin and is called automatically every time DIAdem (or LabVIEW) attempts to load a data file with that DataPlugin.  I also edit and develop DataPlugins using the DIAdem-SCRIPT editor, but unlike "normal" DIAdem VBScripts, DataPlugin scripts can not be started with the DIAdem-SCRIPT "Run script" icon.  Instead, the DataPlugin's ReadStore() subroutine is called whenever you drag a data file of that type into the Data Portal or attempt to index one of those data files with the DataFinder.

Inside of a DataPlugin you get the "File" object for free.  The top-level subroutine of every VBScript DataPlugin looks like this:

Sub ReadStore(File)
  ' code happens here
End Sub

The "File" object is created for you and passed to you as the one parameter in the ReadStore() subroutine.  As noted above, it is DIAdem (or LabVIEW) which creates the File object and passes it to the ReadStore() subroutine when it invokes the DataPlugin.  Also note that the other parent object in the DataPlugin API, the "Root" object, is also created for you and is simply available as a global variable inside the DataPlugin.

For more information on DataPlugin programming, check out the following online-Help topic in DIAdem 10.x

"Programming Reference>>Object-Oriented Script Interfaces>>DataPlugin"

or download the DIAdem 9.1 DataPlugin API from the www.ni.com/dataplugins web site.

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 2 of 4
(3,441 Views)
hello...

first i have to thank you very much for your post!

now to the problem....

i read the documentation of diadem...they say, they have a method root.channelgroups.item(string) which returns the channelgroup-object...this don't work, i think, otherwise i don't now where my misstake is...

next problem is, that i understood the documentation right Smiley Very Happy, cause, if ReadStore(File) is called from diadem and the file object is not a normal file-object, than i cannot debug my script, cause i don't know how to create this special file-object and cannot call this method...

so how can i debug my script?

this are two strange points, i think...

thanks again,
michael
0 Kudos
Message 3 of 4
(3,442 Views)

Hi michael,

You are right.  DIAdem 10.0 and earlier versions contained a bug that would not allow you to index a particular Group from the Root object, either by number or by name.  This has been fixed in DIAdem 10.1.  Until you get DIAdem 10.1, you can work around this bug by assigning each Group that you create to a new variable, so that you don't have to use the Root object to get that Group when you need it later, like this:

Dim i, Groups
ReDim Groups(5)
FOR i = 1 TO Ubound(Groups)
  Set Groups(i) = Root.ChannelGroups.Add "Group " & i
NEXT ' i
'------ other code here ------
FOR i = 1 TO Ubound(Groups)
  Groups(i).Properties.Add "description", "This is Group number " & i
NEXT ' i

Interestingly, this same bug did not prevent you from indexing a particular Channel from its parent Group by name or number-- that has always worked.  If you need Group lookup by name, you can use a VBScript dictionary object.

The File object passed in the ReadStore(File) subroutine is not the same file object as you get with the standard VBScript FileSystemObject.  You can, however open as many new File objects as you want in the ReadStore() subroutine or in any other Subs or Functions the ReadStore() subroutine calls, using the following function from the DataPlugin API:

Set MyNewFileObject = OpenFile("c:\test.txt")

Debugging a DataPlugin is a ticklish business, but it can be done.  Prior to DIAdem 10, you could use the standard MsgBox command to output information to a MsgBox that would appear when you drag the data file into the Data Portal, or when you run a test VBScript like this:

Call DataDelAll
Call DataFileLoad(DataFilePath, DataPluginName)

Where the variable "DataFilePath" contains the full path to the data file you want to test with, and the variable "DataPluginName" contains the name of the DataPlugin (that you typed in) that you want to use when importing this data file.

But in DIAdem 10.x, because of indexing headaches the MsgBox command causes for the DataFinder, the MsgBox command is no longer allowed in a DataPlugin.  You can instead use a similar method of outputting information to a Root or Group or Channel property instead of to a MsgBox dialog.  Or you can use the standard FileSystemObject variable in VBS to output information to an external ASCII file.  I hear that it is also possible to use a just-in-time VBScript debugger for DataPlugins, but I have not personally ever done that.

Hope all this helps,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 4 of 4
(3,420 Views)