12-01-2020 03:19 AM
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.
Solved! Go to Solution.
12-02-2020 04:25 PM
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
12-03-2020 09:29 AM
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.