08-22-2013 06:04 AM
Hello,
I have written a small program as below. My data portal is loaded with example file Example.tdm with the channels time,speed,revs and torque respectively. I would like to create a channel with the calculation as below but when I excute I am getting the error as
"an invalid text operand 0 is used within the index operation of the formula chd(1, 0)".
Pls help me to solve this issue.
The script written is as below.
Dim i
Globaldim ("diacalG")
Globaldim ("Read")
Globaldim ("WR")
Globaldim ("Length")
Length = chnlength("Revs")
Call chnalloc("diacalG",Length,1,datatypefloat64,,Targetgroupindex,5)
For i = 1 To Length
Read = chd(1,"channel2")
Write = 1.11824*exp(-5)*31*Read^2
chd(1,"diacalG") = Write
Next
08-22-2013 11:33 AM - edited 08-22-2013 11:38 AM
You have to specify the group when using the channel name of Chd, so "group1/diacalG" or "[1]/diacalG" Depends on what group your channel is in.
This would do what you want MUCH faster
Call Calculate("Ch(""[1]/diacalG"")= 1.11824*exp(-5)*31*Ch(""[1]/channel2"")^2")
Replace the 1 with the group number you are using.
The calculate function uses diadems built in calculator. To use calculate you have to send it a string , so Call Calculate(Your string). The Ch function just returns the channel. Since the ch function needs strings as well, you have to use 2 double quotes to put a single quote in a string. So, MsgBox("Hello World") will output Hello World, but if you used MsgBox("Hello ""The"" World"), you would get Hello "The" World. You could also use Ch(1) for the first channel in the index.
08-23-2013 12:26 AM
Thank you very much Mr.Russel
It is working.