Question:
Visual basic and radio buttons with case statement?
vicki
2012-04-14 09:55:56 UTC
I'm trying to create a program for school that, among many other requirments, requires me to use a select case statement. It MUST use case, and not an if statement.
My code gives back the wrong results. When 3 is checked, I get 4 When 4 is checked, I get 3. When 5 is checked, I get 3.
Thank you! My code is below.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim yearsLoan As Double
Dim loan As Double

Select Case loan
Case years3.Checked = True
yearsLoan = 3
Case years4.Checked = True
yearsLoan = 4
Case years5.Checked = True
yearsLoan = 5
End Select
TextBox1.Text = yearsLoan
End Sub
End Class
Three answers:
texasmaverick
2012-04-14 10:53:54 UTC
Try this version of your code.



The for has a button, a text box and 3 radiobuttons with the checked property set to false





Public Class Form1



Public Num1 As Integer



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



Dim yearsLoan As Double

Dim loan As Double



Select Case Num1

Case Is = 3

yearsLoan = 3

Case Is = 4

yearsLoan = 4

Case Is = 5

yearsLoan = 5

End Select

TextBox1.Text = yearsLoan

End Sub



Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

Num1 = 3

End Sub



Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged

Num1 = 4

End Sub



Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged

Num1 = 5

End Sub

End Class
malan
2016-12-18 20:04:13 UTC
Visual Basic Case Statement
macphee
2016-09-28 14:52:27 UTC
Vb.net Case Statement


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