Reputation: 47
Hello all i have tried to convert c# code to vb but getting error in this line as "Expression Expected" what can be the error and what is the correct syntax. Error is in second line
Dim m As MenuItem = TryCast(sender, MenuItem)
audioDevice = (If(m.Index>0, filters.AudioInputDevices(m.Index-1), Nothing))
C# CODE
MenuItem m = sender as MenuItem;
audioDevice = ( m.Index>0 ? filters.AudioInputDevices[m.Index-1] : null );
Upvotes: 1
Views: 260
Reputation: 9460
Try this
Dim m As MenuItem = TryCast(sender, MenuItem)
audioDevice = (IIf(m.Index>0, filters.AudioInputDevices(m.Index-1), Nothing))
IIf Function MSDN Documentation
As IIf Function is deprecated use like this
If m.Index>0 Then
audioDevice = filters.AudioInputDevices(m.Index-1)
Else
audioDevice = Nothing
End If
Hope it helps
Upvotes: 1
Reputation: 64
Here is probably the best tool I have ever found! And having been a developer for over 10 years, when I found this (And with most examples online being in C, this was just GOLDEN!) .. Hope this helps you! (And anyone else that hasn't stumbled across this 'gem'... Finally VB coders have better access to online examples... NOTE* this isn't the only code converter, but it's by far the best one I have ever used.. Perhaps if you convert the code again using this, your troubles might be solved.......
http://converter.telerik.com/ (Does an amazing job on converting)
Upvotes: -1
Reputation: 10874
Are you running VB.Net 2008 or later? The If
operator is not supported in earlier versions.
Since the non-short-circuit Iif
function will cause the true-part of the expression to cause an index out of range, you should use an If Then Else
statement if you want a version prior to 2008 to be supported.
Upvotes: 4