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.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

automatic channel renaming

Solved!
Go to solution

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

 

 

 

0 Kudos
Message 1 of 3
(5,601 Views)
Solution
Accepted by topic author Jeremy_TCL

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

Message 2 of 3
(5,576 Views)

Thank you very much!

0 Kudos
Message 3 of 3
(5,522 Views)