hello !
im new here and to VB. and i need some help on input validation for text boxes that are linked to radio buttons... at the moment im using If..Then, if i should do something different let me know..
i have 24 text boxes linked to 8 radio buttons and i want to validate certain text boxes per radio, how is it done?????

If rad1.Checked And txt1.Text.Length Or txt2.Text.Length Or txt3.Text.Length Or txt4.Text.Length Or txt5.Text.Length < 1 Then
            MessageBox.Show("Fill all boxes to read story", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        ElseIf rad2.Checked And txt1.Text.Length Or txt2.Text.Length Or txt3.Text.Length Or txt4.Text.Length Or txt5.Text.Length Or txt6.Text.Length Or txt7.Text.Length Or txt8.Text.Length Or txt9.Text.Length < 1 Then
            MessageBox.Show("Fill all boxes to read story", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        ElseIf rad3.Checked And txt1.Text.Length Or txt2.Text.Length Or txt3.Text.Length Or txt4.Text.Length Or txt5.Text.Length Or txt6.Text.Length Or txt7.Text.Length Or txt8.Text.Length Or txt9.Text.Length < 1 Then
            MessageBox.Show("Fill all boxes to read story", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        ElseIf rad4.Checked And txt1.Text.Length Or txt2.Text.Length Or txt3.Text.Length Or txt4.Text.Length Or txt5.Text.Length Or txt6.Text.Length Or txt7.Text.Length Or txt8.Text.Length Or txt9.Text.Length Or txt10.Text.Length Or txt11.Text.Length Or txt12.Text.Length Or txt13.Text.Length Or txt14.Text.Length Or txt15.Text.Length Or txt16.Text.Length Or txt17.Text.Length Or txt18.Text.Length Or txt19.Text.Length Or txt20.Text.Length Or txt21.Text.Length Or txt22.Text.Length Or txt23.Text.Length < 1 Then
            MessageBox.Show("Fill all boxes to read story", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        ElseIf rad5.Checked And txt1.Text.Length Or txt2.Text.Length Or txt3.Text.Length Or txt4.Text.Length Or txt5.Text.Length Or txt6.Text.Length Or txt7.Text.Length Or txt8.Text.Length Or txt9.Text.Length Or txt10.Text.Length Or txt11.Text.Length < 1 Then
            MessageBox.Show("Fill all boxes to read story", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        ElseIf rad6.Checked And txt1.Text.Length Or txt2.Text.Length Or txt3.Text.Length Or txt4.Text.Length Or txt5.Text.Length Or txt6.Text.Length Or txt7.Text.Length < 1 Then
            MessageBox.Show("Fill all boxes to read story", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        ElseIf rad7.Checked And txt1.Text.Length Or txt2.Text.Length Or txt3.Text.Length Or txt4.Text.Length Or txt5.Text.Length Or txt6.Text.Length Or txt7.Text.Length Or txt8.Text.Length Or txt9.Text.Length Or txt10.Text.Length Or txt11.Text.Length Or txt12.Text.Length Or txt13.Text.Length Or txt14.Text.Length Or txt15.Text.Length Or txt16.Text.Length Or txt17.Text.Length Or txt18.Text.Length Or txt19.Text.Length Or txt20.Text.Length Or txt21.Text.Length Or txt22.Text.Length Or txt23.Text.Length Or txt24.Text.Length < 1 Then
            MessageBox.Show("Fill all boxes to read story", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        ElseIf rad8.Checked And txt1.Text.Length Or txt2.Text.Length Or txt3.Text.Length Or txt4.Text.Length Or txt5.Text.Length Or txt6.Text.Length Or txt7.Text.Length Or txt8.Text.Length Or txt9.Text.Length Or txt10.Text.Length Or txt11.Text.Length Or txt12.Text.Length Or txt13.Text.Length Or txt14.Text.Length < 1 Then
            MessageBox.Show("Fill all boxes to read story", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Else

I would probably use a function to validate the textboxes, your current method doesn't work (you need to write txt1.Text.Length < 1 Or txt2.Text.Length < 1 Or txt3.Text.Length < 1 etc). It might also be easier to just do .Text.Length = 0

You could write a function to simplify the messagebox:

Private Sub ShowError()
        MessageBox.Show("Fill all boxes to read story", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    End Sub

hi

u can try this also .make a function which validate the textbox should not empty and check the condition either radio btn checked.

'Declaring Function
 Public Sub empty(ByVal txt As String, ByVal y As String)
        If txt = "" Then
            Throw New Exception(y & "fields could not be empty")
        End If
    End Sub
'Calling function
 empty(cmbbatchno.Text, " Batch No")

i hope it will help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.