10-11-2010 11:28 PM
Newbie to both DIAdem, VBS and pretty much everything. I've got the basic stuff I need done in DIAdem scripted and working well but a hangup on the syntax of this super-simple channel logic operation is killing me! Please help!
I'll make this very simple. I'm working with "path variable" file reference and the "option explicit" enabled in this script.
I've got four channels within a group called "Untitled": "TimeGenerated", "Untitled 1" and "DiffY" (derivative of "Untitled 1" W.R.T the time channel...) and "DiffX" (which I don't care about). They are all equilength.
I simply want to set values of "Untitled 1" = 0 (or null) wherever the matching row of DifferentiatedY is > 0.25.
I have tried all sorts of horrible mixes of (what I think is...) VBS and AUT syntax, such as:
TRY 1:
Option Explicit 'Forces the explicit declaration of all the variables in a script.
If ("Untitled/DiffY")>0.25 Then
["Untitled/Untitled 1"=null]
End If
which gives the error:
"Error in <If_loop.VBS> (Line: 8, Column: 1):
Type mismatch: '[string: "Untitled/DiffY"]'
TRY 2:
Option Explicit 'Forces the explicit declaration of all the variables in a script.
If Ch("Untitled/DiffY")>0.25 Then
Ch("Untitled/Untitled 1")=0
End If
which gives the error:
"Error in <If_loop.VBS> (Line: 8, Column: 1):
Variable uses an Automation type not supported in VBScript"
TRY 3:
Option Explicit 'Forces the explicit declaration of all the variables in a script.
If ch("Untitled"/"DiffY")>0.25 Then
ch("Untitled"/"Untitled 1")=null
End If
which gives the error:
"Error in <If_loop.VBS> (Line: 8, Column: 1):
Type mismatch: '[string: "Untitled"]' "
I have tried many other entries as well. I have spent way too much time searching through the DIAdem manual, searching the web about VBS syntax in general, all to no avail.
Can someone point out my incredibly simple error?
THANK YOU IN ADVANCE!
-Dan
10-12-2010 08:58 AM
Hi Dan,
Each channel contains a number of different values. If you want to apply an expression to all the values in a channel, you need to use the Channel Calculator. Here is an example of the two things you discussed (setting to NoValue or setting to 0) based on the value of a condition. You should pick one of the FormulaCalc lines and not run both.
L1
L2
Call
Call
= CNo("Untitled/Untitled 1") = CNo("Untitled/DiffY") FormulaCalc("Ch(L1):= Ch(L1) + NoValue*(Ch(L2)>0.25)") FormulaCalc("Ch(L1):= Ch(L1)*(Ch(L2)<=0.25)")
Brad Turpin
DIAdem Product Support Engineer
National Instruments
10-12-2010 08:58 AM
And here it is in readable form.
L1 = CNo("Untitled/Untitled 1")
L2 = CNo("Untitled/DiffY")
Call FormulaCalc("Ch(L1):= Ch(L1) + NoValue*(Ch(L2)>0.25)")
Call FormulaCalc("Ch(L1):= Ch(L1)*(Ch(L2)<=0.25)")
10-12-2010 09:39 AM
Brad -
Thank you. Funny, I had just previously used the channel calculator to take the absolute value of the differentiated signal!
I also hadn't thought of working with variables this way. I'll use this more!
Thanks again,
-Dan
10-12-2010 03:29 PM
Brad or whomever else may be able to help;
Another very simple question....
Could you recommend a resource for explaining how to repeat my commands for different channels using a simple counter loop? I believe the problem revolves around the fact that my raw data has mixed text string/number channel names (such as "Untitled 1"... through "Untitled 72"). I have the DIAdem Basics manual but it does not adequately explain how to define a channel as a variable in such cases - for use in a counter loop. I want to repeat my channel commands which I have gotten working for a single channel "Untitled 1" for 70 other channels - exactly the same way. I am trying to use a straightforward counter loop (for... to)
Right now I have name-oriented channel references set to "Group name/Channel name"
I know I need to specify the channel "numbers", by variable (i.e, I), all starting with the string of my channel name, "Untitled" as a variable. I have tried to get the VBS syntax correct, ad nauseum...
I have tried specifying the variable in ways like:
Dim I
Dim "Untitled_: I"
Dim "Untitled:I"
...and invoking the variable within the look in ways like:
For I = 1 to 71
Call ChnDifferentiate("Untitled/TimeGenerated","Untitled/Untitled"(I),"Untitled/DifferentiatedX","Untitled/DifferentiatedY") '... XW,Y,E,E
(more lines...)
Next
and...
Dim I
For I = 1 to 71
Call ChnDifferentiate("Untitled/TimeGenerated","Untitled/Untitled_"(I),"Untitled/DifferentiatedX","Untitled/DifferentiatedY") '... XW,Y,E,E
(more lines...)
Next
and...
Dim I
For I = 1 to 71
Call ChnDifferentiate("Untitled/TimeGenerated","Untitled/Untitled"(I),"Untitled/DifferentiatedX","Untitled/DifferentiatedY") '... XW,Y,E,E
(more lines...)
Next
...and many more.
The error of course comes in that first line below the "for" comment.
Can you possibly point me towards the DIAdem help on this topic of mixed string/number channels? Or I might just try renaming all the channels to a number only, such that DIAdem / VBS can recognize them as a non-mixed variable.
Thanks in advance for any advice! I know this is really as simple as a missed quotation, underscore, parenthesis, etc.... ugh.
-Dan
10-12-2010 04:03 PM
Hi Dan,
You keep treating a string constant like it's an array variable, and that just doesn't work. Here's what I'd recommend, assuming you want to process all the channels of the first group except the first one, which you take as the communal time channel for all the data channels in the group:
GroupIdx = 1
jMax = GroupChnCount(GroupIdx)
TimeCh = CNoXGet(GroupIdx, 1)
NewGroupName = "Derivatives"
IF GroupIndexGet(NewGroupName) > 0 THEN Call GroupDel(GroupIndexGet(NewGroupName))
Call GroupCreate(NewGroupName)
Call GroupDefaultSet(GroupCount)
FOR j = 2 to jMax
DataCh = CNoXGet(GroupIdx, j)
DataName = ChnName(DataCh)
Call ChnDifferentiate(TimeCh, DataCh, "DiffX_" & DataName, "DiffY_" & DataName)
NEXT ' j
Brad Turpin
DIAdem Product Support Engineer
National Instruments