DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete Channels Using ChnNoMax?

Solved!
Go to solution

Hello,

 

I have a large TDMS files I need to pull specific channels out from and move to another file. Each file has from 3-20 groups with 5-20 channels each (there is no specific number and depends on how the testing was done). The only thing that does not change is the channel names that I need to recover and move to a smaller file.

 

My attempted script is attached below. I receive an error at the line "oMyChn.Remove" as this is obviously not a real command.

Spoiler

Dim oMyChn, oGroups 'Channel Vars
Dim LoopOver, ChInt, LoopInt 'Loop Vars
dim StrCompar, StrCompar2 'String Compare Vars
dim InputVal 'User File Save Name
dim Woah, WoahCt 'Too many loops turn off

LoopInt = 0
Woah = 200
WoahCt = 0

do while LoopInt < ChnNoMax
    Set oMyChn = Data.GetChannel(ChnNoMax - LoopInt)
'--- Compare channel name strings
    StrCompar = InStr(oMyChn.Name, "Power")
    StrCompar2 = InStr(oMyChn.Name, "Time")
'--- Remove channels that do not contain strings
    if (StrCompar = 1 or StrCompar2 = 1) then
       LoopInt = LoopInt +1 'Change loop variable
    else
       oMyChn.Remove '<<<<<<< THIS??? >>>>>>>>>>
    end if
'--
    WoahCt = WoahCt+1
    If WoahCt > Woah Then
       Exit Do
     End If
Loop

InputVal= InputBox("File Save Name","DIAdem","Test")
'Call DataFileSave("C:\" & InputVal & ".tdms","TDM")

I'm not sure if my method is the best way to go about this. Any help is appreciated.

 

Edit:

 I’ve considered using the following but don’t know the correct commands.

 1. get total number of groups

 2. for X = 1 to no. groups

3. get total channels per group

4. for y = 1 to no. channels in group x

5. delete appropriate channels

 6. end loop y

 7. end loop x

0 Kudos
Message 1 of 3
(2,188 Views)
Solution
Accepted by topic author Bryverine

 

Option Explicit  'Forces the explicit declaration of all the variables in a script.


Dim channelsToKeep
channelsToKeep = Array("Power", "Time", "Frequency")

Call Data.Root.ChannelGroups.Add("Saved Data", 1)

Dim i, j, channelCount

For channelCount = 0 To UBound(channelsToKeep, 1) Step 1
  For i = 2 To Data.Root.ChannelGroups.Count Step 1
    For j = 1 To Data.Root.ChannelGroups(i).Channels.Count Step 1
      If Data.Root.ChannelGroups(i).Channels(j).Name = channelsToKeep(channelCount) Then
        Call Data.Move(Data.Root.ChannelGroups(i).Channels(j),Data.Root.ChannelGroups(1).Channels)
      End If
    Next
  Next
Next

' Delete all the other channel groups
For i = 2 To Data.Root.ChannelGroups.Count Step 1
  Call Data.Root.ChannelGroups.Remove(2)
Next

 

Message 2 of 3
(2,142 Views)

Hello,

Sorry it took so long to try this. I ran the code today and it gives me an error that I can't seem to understand.

 

I was getting a missing index error.

 

I threw in a "On Error Resume Next" before the "If Data.Root.ChannelGroups(i).Channels(j).Name..." line and it seems to correct it thought I'm not sure why its trying to find an index that isn't there?

 

 

Thank you for the help!

0 Kudos
Message 3 of 3
(2,047 Views)