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.
12-18-2012 09:37 AM
Hello,
I have Diadem 2011 and I am facing a problem when I try to automatically rename a list of channel (loaded in my data portal). My list of channel and their corresponding new names are written in a text file with the following syntax :
initial name1, new name1
initial name2, new name2
..................
initial name n, new name n
My first idea was to import this .txt file in order to create 2 channels called for example "old channel" and "new channel" and to use the following renaming command in a loop like this:
For i=1 to length (old channel)
Data.Root.ChannelGroups(1).Channels(old channel (i)).Name = new channel(i)
next
This command works correctly when I replace old channel(i) and new channel(i) by a string like for example "channel1" and "channel2". In my opinion, there is a problem with the data type, but I don't manage to solve it.
I also tried the data type conversion but without success.
Thank you by advance for your help
Jeremy
Solved! Go to Solution.
12-19-2012 03:06 PM
Hi Jeremy,
I'd recommend you read the name lookup file into memory instead of channels in the Data Portal. The below code uses 2 parallel string arrays, but the Dictionary object is another good way to go.
NameArrayFilePath = CurrentScriptPath & "Name Arrays.csv" Call ReadNameArrays(OldChanNames, NewChanNames, NameArrayFilePath) Set Group = Data.Root.ActiveChannelGroup jMax = Group.Channels.Count FOR j = 1 TO jMax IF Group.Channels.Exists(OldChanNames(j)) THEN Set Channel = Group.Channels(OldChanNames(j)) Channel.Name = NewChanNames(j) END IF NEXT ' j Sub ReadNameArrays(OldChanNames, NewChanNames, NameArrayFilePath) Dim j, f, fso, Cols Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(NameArrayFilePath, 1) ReDim OldChanNames(0) ReDim NewChanNames(0) Do While NOT f.AtEndOfStream Cols = Split("," & f.ReadLine, ",") IF UBound(Cols) > 1 THEN j = j + 1 ReDim Preserve OldChanNames(j) ReDim Preserve NewChanNames(j) OldChanNames(j) = Trim(Cols(1)) NewChanNames(j) = Trim(Cols(2)) END IF Loop ' Unitl EOF f.Close End Sub ' ReadNameArrays()
Brad Turpin
DIAdem Product Support Engineer
National Instruments
01-03-2013 06:40 AM
Thank you very much!