fedeteka fedeteka - 5 months ago 20
Vb.net Question

Using a integer flag to save radio button status like a boolean

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)
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?


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)