Question:
Visual Basic: If Then statement problem..?
2009-02-03 17:16:30 UTC
pretty much I'm a novice at program... and I've tried looking up various solution, but I haven't been able to find one yet... but pretty much my code appears below followed by that error message.


Dim s As Integer
Dim radiobutton1 As RadioButton
Dim radiobutton2 As RadioButton

If radiobutton1.Checked Then
s = 0
ElseIf radiobutton2.Checked Then
s = 2
End If

I am told by express:

Error 1 'Public Event Checked(sender As Object, e As System.Windows.RoutedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Five answers:
2009-02-03 17:21:03 UTC
Your conditionals are incomplete. You need to check whether Checked is true. And if your if then is outside of a function/event, that's probably illegal.
just_me ♦
2009-02-03 17:36:59 UTC
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton1.Click

Dim s As Integer





If RadioButton1.Checked Then

s = 0

Else

s = 2

End If
iqbal
2009-02-03 21:12:00 UTC
Hi,

In VB, Radio Button is called Option1. Its value is true or false.

The Option has not "Checked" property.



In ur prog u need not declare variable for Option.



If u have 2 options then simply write



If Option1.Value Then

s = 0

ElseIf Option2.Value Then

s = 2

End If
Paul B
2009-02-03 17:27:08 UTC
I think because checked is a boolean, you can use syntax like yours.



However, I'm pretty sure you need to write the lot in a method of some sort. -

"Private sub dostuff()

[mah code]

End sub"



And use the visual editor to create the radio buttons and their code; I think they need to be global, and because they're objects you need to create them with the "new" function (something like "private rb1 as RadioButton = new Radiobutton()"), but seriously, let the editor figure that stuff out. Its just easier.
?
2016-10-05 10:36:23 UTC
thank you on your question. you probably did an outstanding job of telling us the concern and displaying us your code and the blunders. Others might do nicely to be conscious your occasion. the blunders is a casting exception. Your variable is of sort 'unmarried' and additionally you're attempting to assign to it the cost "5 / 9(sngtemp - 32)" That value is a String on the grounds which you have placed costs around it, and additionally you will't solid a String to a unmarried (until it incredibly is a numeric string, yet it incredibly is beside the element). attempt removing the charges from around the cost on that line. solid success!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...