ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Check if a channel object variable exists

Solved!
Go to solution

Hi,

 

How do I check if a channel object variable was successfully set?

 

Early in my code I use the following to determine if a channel exists and, if so, to set a channel object variable to represent it:

If Data.Root.ChannelGroups(1).Channels.Exists("Yaw Rate Gain") Then
  Set YRateG = Data.GetChannel("Yaw Rate Gain")
End If

Later in my code I'd like to check if YRateG is valid but I can't find a way of checking without tripping an error if it isn't.

 

I've tried using IsNull on YRateG.Name and I've tried Data.Root.ChannelGroups(1).Channels.Exists(YRateG.Name), but neither worked.

 

Thanks, Simon.

0 Kudos
Message 1 of 3
(1,809 Views)
Solution
Accepted by topic author Simon_Aldworth

Hi Simon,

 

I'd recommend you use the IsObject(YRateG) comparison.  As long as you don't initialize the variable to Nothing or re-use it between the Set assignment and when you compare, this should work.

 

Brad Turpin

Principal Technical Support Engineer

National Instruments

0 Kudos
Message 2 of 3
(1,769 Views)
dim YRateG : Set YRateG = nothing
If Data.Root.ChannelGroups(1).Channels.Exists("Yaw Rate Gain") Then
  Set YRateG = Data.GetChannel("Yaw Rate Gain")
End If

if not YRateG is nothing then
end if

could be an alternative.

Be aware that isobject will also return true for nothing.

0 Kudos
Message 3 of 3
(1,751 Views)