Arrays and radio buttons

bobos051

Member
Joined
May 14, 2009
Messages
6
Programming Experience
Beginner
Hey, am having 3 radio buttons and a button
The codes should be added to the button_click event, when ever the radio button is selected and the button is click then,
The codes should determine which button is selected and assign it to a variable. Create a two parallel 1-dim arrays and populate it with the data below:
Accommodation standard=(5 Star, 4 Star, Budget)
Cost=(200,100,60)

Dim AccStandard() As String = {"5 Star", "4 Star", "Budget"}
Dim cost() As Integer = {200, 100, 60}
 
Last edited:
Not exactly what your looking for

Off the top of my head this would work fine.

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
RadioButton2.Checked = False
RadioButton3.Checked = False
Button1_Click(sender, e)
End If
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
RadioButton1.Checked = False
RadioButton3.Checked = False
Button1_Click(sender, e)
End If
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
If RadioButton3.Checked = True Then
RadioButton1.Checked = False
RadioButton2.Checked = False
Button1_Click(sender, e)
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strValue As String
Dim strcost As String
If RadioButton1.Checked = True Then
strValue = RadioButton1.Text
strcost = "200"
ElseIf RadioButton2.Checked = True Then
strValue = RadioButton2.Text
strcost = "100"
Else
strValue = RadioButton3.Text
strcost = "50"
End If
End Sub
 
Since in a group of RadioButtons only one can be checked, it doesn't make much sense to "uncheck" the others - because they are unchecked already.

A single handler would also look a bit nicer

And if the tabstops are set accordingly, the whole stuff more or less reduces to:

If CType(sender, RadioButton).Checked then SelIndex = CType(sender, RadioButton).TabIndex - TabIndexOfTheFirstRadioButton

SelIndex would be a member var that can be used in _Click to simply select the correct array index
 
pls can you make it a little easier
TyB's code should probably do the job. If you have not much experience you'd probably better use his, instead of trying to understand what I suggested.
Time might come when you understand it easily and/or can teach me something better ;)
 
The homework says ...

If RadioButton1.Checked = True Then
strValue = category(0)
strcost = price(0)
ElseIf RadioButton2.Checked = True Then
strValue = category(1)
strcost = price(1)
Else
strValue = category(2)
strcost = price(2)
End If

now you have used an array.
 
Array and Radio Buttons.

Hi everyone, I need help with this please.
Add codes to the click() event procedure to a button as follows:
Create a variable for accommodation. Determine which accommodation radio button the user selected and assign it to this variable.
Modify the call statement to function CalculateAccommodationCost()

FUNCTION CalculateAccommodationCost()
Create two parallel 1-dim arrays at procedure level and populate it with the data below:
Accommodation Standard= {5 Star, 4 Star, Budget}
Cost Per Twin Share = {200,100,60}

There are 3 radio buttons: 5 Star, 4 Star, and Budget
 
Back
Top