DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

If condition over strings

Hello

 

I would like to create an IF condition for a string at the beginning of the description.

For ex.

If the "N.A." string exist at the beginning of channel Description (Description for ex. "N.A. Lap Belt L.C. LHS")  then to delete the channel.

I tried the following without success:

 

Option Explicit 'Forces the explicit declaration of all the variables in a script.
Dim i, j, oMyChn, oMyUnit
For i = 1 to GroupCount
For j = 1 to GroupChnCount(i)
if(Data.Root.ChannelGroups(i).Channels(j).Properties("description").Value="N.A.") THEN
Call Data.Root.ChannelGroups(i).Channels.Remove(j)
end if
Next
Next

 

I will appriciate your assistance solving this issue.

 

Oded

0 Kudos
Message 1 of 4
(2,512 Views)

Hi odedmi,

The description is not identical with "N.A." but is only a part of it.

Instead of:

if(Data.Root.ChannelGroups(i).Channels(j).Properties("description").Value="N.A.") THEN

you should use:

If InStr(1, Data.Root.ChannelGroups(i).Channels(j).Properties("description").Value,"N.A.",VBTextCompare) = 1 Then

 

Please have a look in the help: http://zone.ni.com/reference/en-XX/help/370858N-01/vbs/methods/vbs_method_instr_globalobj/

 

Winfried

0 Kudos
Message 2 of 4
(2,504 Views)

Hello Odedmi,

if you are looking for a more compact solution and you are using a recent version of DIAdem, take a look at data.getchannels

If you use this function in conjunction with data.remove you can do something like:

 

Dim oList
Set oList = Data.GetChannels("N.A.*")
If ( 0 < oList.Count ) Then Call Data.Remove(oList)

 

If you are 100% sure the channels exist (at least one) you can go as compact as

Call Data.Remove(Data.GetChannels("N.A.*"))

but that would give you an error message in case no channel name starting with "N.A." exists

0 Kudos
Message 3 of 4
(2,484 Views)

Hi All,

 

Please note that Data.GetChannels(CompareString) only operates on the name of the Channel and the name of the Group that Channel is in.  This would not be the right approach to use if the CompareString in question is stored in a Channel or Group property other than the name, such as the "Description" property.

 

Cheers,

Brad Turpin

DIAdem Product Support Engineer

National Instruments

 

0 Kudos
Message 4 of 4
(2,428 Views)