ni.com is currently undergoing scheduled maintenance.
Some services may be unavailable at this time. Please contact us for help or try again later.
02-16-2012 10:48 AM
Hi,
I have multiple scripts that do certain jobs. In each of them, all I want to do is change some channel names. I can change each channel name individually by hitting Ctrl + F to bring up the Find and Replace dialog box and selecting Replace With - Replace All. Does anyone know if I can manually do the same functions as Ctrl + F function from the script editor?
Thanks
Solved! Go to Solution.
02-17-2012 02:57 PM
Hi Kevster,
I would have said that using <Ctrl-F> from the keyboard IS manual script editing. But it sounds like what you should be doing instead is using some channel name variables instead of channel name string constants. Then you would have one location in your script (usually at the top) where each channel name string is assigned to its channel name variable-- this one short spot in your script will be super easy to edit. The rest of your code will just use the channel name variables instead of string constants and will never need to be changed.
Brad Turpin
DIadem Product Support Engineer
National Instruments
02-20-2012 03:17 AM
Thats it, why didn't I think of that!
Thanks for the idea!
02-20-2012 05:55 AM
Hi Brad,
I am trying to use the variable as you suggested but I cant seem to get it, maybe you could help me. I am trying to use do a set of equations through this method. here is what I have at the minute:
sFormula = "Ch(""Instrumentation/Channel2"")=Ch(""Instrumentation/Channel2"")-x+y"
aSymbol(1) = "x"
aValues(1) = CHDx(1,CNo("Instrumentation/Channel2"))
aSymbol(2) = "y"
aValues(2) = CHDx(1,CNo("Instrumentation/Channel1"))
Call Calculate (sFormula, aSymbol, aValues, "ºC")
Using a variable channel name, I think it should be something like:
Dim x01, x02
x01="Desired Name 1"
x02="Desired Name 2"
sFormula = "Ch(""Instrumentation/"x02""")=Ch(""Instrumentation/"x02""")-x+y"
aSymbol(1) = "x"
aValues(1) = CHDx(1,CNo("Instrumentation/"x02""))
aSymbol(2) = "y"
aValues(2) = CHDx(1,CNo("Instrumentation/"x01""))
Call Calculate (sFormula, aSymbol, aValues, "ºC")
However, I get an error message saying "Expected end of statement" after colum 35 (which is between the first 'x' and the '02'). Do you perhaps know why this would be?
Regards
Kev
02-22-2012 09:03 AM
Hi Kev,
You were close, you just needed to use the "&" operator in VBScript to concatenate string constants and string variables, like this:
x01="Desired Name 1"
x02="Desired Name 2"
sFormula = "Ch(""Instrumentation/" & x02 & """)=Ch(""Instrumentation/" & x02 & """)-x+y"
MsgBox sFormula
Brad Turpin
DIAdem Product Support Engineer
National Instruments