Question store Radio Button value

elianeasmar

Well-known member
Joined
Oct 3, 2013
Messages
76
Programming Experience
Beginner
Hello. I need your help please.
i have a form that contains "Sex" as a radio button.and i have a structure:

Public Structure _schoolinfo
Public Code As String
Public Name As String
Public PhoneNumber As String
Public Address As String
Public Sex As String
End Structure

And i am not using database to store the information.
my question is ,that i managed to save all the fields in the structure except the radio button(RDFemale--RDMale)
Does anyone know how to save the checked radio button in the structure?

I am saving the other fields like this:

_info = New _schoolinfo With _info
.Code = txtCode.Text
.Name = txtName.Text
.PhoneNumber = txtPhoneNumber.Text
.Address = txtAddress.Text
End With

txtCode
txtName
txtPhoneNumber
txtAddress

those are the one that the user enters in the app.


Thank you for your help :)
 
Last edited:
Hi,

You simply need to use an If statement to test the Checked Property of any one of your RadioButtons and then set your .Sex value accordingly. i.e:-

If YourMaleRadioButton.Checked Then
 .Sex = "Male"
Else
 .Sex = "Female"
End If


Hope that helps.

Cheers,

Ian
 
Thanks man. Another question Please.I am working with a structure as you saw. If i want to delete an item. i have to reduce reduce the index and retrieve the next item to be put in it's place. Right?so if you can help me do that,i will be great.Thank you :)
 
Hi,

Just for future reference, if you have an unrelated question to that of the original post then please make a new Thread to ask that separate question.

In this case, I assume that what you mean is that you have a Collection of "_schoolinfo" objects in either an Array or a List of some type and you want to delete one of those objects? If so, then:-

1) If you are using a List then you can use the Remove or RemoveAt methods to delete an object in the list
or
2) If you are using an Array then it a bit more long winded. One option is to get the Index of the item to be deleted and then overwrite that index with the next item in the array. You would then do the same thing for all the index's after the one that needs deleting (effectively moving all the elements after the one that needs deleting to the left by 1). You can then re-dimension the Array as you need. Have a play with this to help explain this better:-

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  Dim myNumbers() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9}
 
  'This is what we start with
  MsgBox(String.Join(", ", myNumbers))
 
  'Lets say we want to delete the number 3 which is the index number 2 in the array you can say:-
  For currentIndex As Integer = 2 To myNumbers.GetUpperBound(0) - 1
    myNumbers(currentIndex) = myNumbers(currentIndex + 1)
  Next
  ReDim Preserve myNumbers(7)
 
  'This is what we finish with
  MsgBox(String.Join(", ", myNumbers))
End Sub


Hope that helps.

Cheers,

Ian
 
Back
Top