0

I'm using this code to "convert" the status of a Radio Button to a integer in "boolean way"

If MyRadioButton.Checked Then
    cmdConnection.Parameters.AddWithValue("@paramMychoice", 1)
Else
    cmdConnection.Parameters.AddWithValue("@paramMychoice", 0)
End If

The code works fine

Reading the answer of Muhammad Nabeel Arif in this link Store boolean value in SQLite

he uses

int flag = (boolValue)? 1 : 0;

But if I try something like

Dim flag As Integer
flag = (MyRadioButton.Checked)? 1 : 0

I get "option strict on disallows implicit conversions from 'boolean' to 'integer'"

Right, I understand and Visual Studio suggest something like flag = CInt((ProtocoloAutorizadaNoRadioButton.Checked))? 1 : 0

But I also get the error "The ? character cannot be used here"

How can I use the solution of int flag = (boolValue)? 1 : 0 on VB.net?

Community
  • 1
  • 1
fedeteka
  • 943
  • 1
  • 14
  • 33

1 Answers1

2

Using If

Dim flag As Integer
flag = if(MyRadioButton.Checked,1, 0)

If Operator (Visual Basic)

Also set explicit and strict to on to your project. (I recommend to set those two default to on in Visual Studio)

shadow
  • 1,883
  • 1
  • 16
  • 24