Results 1 to 3 of 3

Thread: if statement blues

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    40

    if statement blues

    I have a if statement that is suppose to validate 2 radio buttons on the form. The way i have it set up is if the radio button1 check = false the fire message box or if radio button2 is not check fire message. Here is my code

    If Me.rdoJC.Checked = False Then



    Me.lstJCBookID.Items.Add(Me.txtBookID.Text)
    Me.lstJCAuthor.Items.Add(Me.txtAuthor.Text)
    Me.lstJCTitle.Items.Add(Me.txtTitle.Text)
    Me.lstJCCost.Items.Add(Me.txtCost.Text)
    Me.lstJCCopies.Items.Add(Me.txtCopies.Text)
    Else
    MessageBox.Show("Please select what library to add book to")


    End If
    Exit Sub
    If Me.rdoEL.Checked = True Then


    Me.lstELBookID.Items.Add(Me.txtBookID.Text)
    Me.lstELAuthor.Items.Add(Me.txtAuthor.Text)
    Me.lstELTitle.Items.Add(Me.txtTitle.Text)
    Me.lstELCost.Items.Add(Me.txtCost.Text)
    Me.lstELCopies.Items.Add(Me.txtCopies.Text)
    Else
    MessageBox.Show("test")
    End If

    Thanks in advance for any help.

  2. #2
    Hyperactive Member nothingofvalue's Avatar
    Join Date
    Jul 2005
    Location
    Arizona
    Posts
    489

    Re: if statement blues

    I would reccommend that you put both the radio buttons in a groupbox which will then only allow one radio button at a time to be selected. This looks better usually and saves you the coding. Then use something like this:

    VB Code:
    1. '   If EL is Checked and JC is not then add to EL
    2.         If Me.rdoEL.Checked Then
    3.  
    4.             Me.lstELBookID.Items.Add(Me.txtBookID.Text)
    5.             Me.lstELAuthor.Items.Add(Me.txtAuthor.Text)
    6.             Me.lstELTitle.Items.Add(Me.txtTitle.Text)
    7.             Me.lstELCost.Items.Add(Me.txtCost.Text)
    8.             Me.lstELCopies.Items.Add(Me.txtCopies.Text)
    9.  
    10.             '   If JC is checked and EL is not then add to JC
    11.         ElseIf Me.rdoJC.Checked Then
    12.  
    13.             Me.lstJCBookID.Items.Add(Me.txtBookID.Text)
    14.             Me.lstJCAuthor.Items.Add(Me.txtAuthor.Text)
    15.             Me.lstJCTitle.Items.Add(Me.txtTitle.Text)
    16.             Me.lstJCCost.Items.Add(Me.txtCost.Text)
    17.             Me.lstJCCopies.Items.Add(Me.txtCopies.Text)
    18.  
    19.         End If

    Just specify at design time which one is checked by default
    "Imagination is more important than knowledge..."

    Albert Einstein
    -----------------------------------------------
    If my reply helped you then you really were lost, but I still took the time to help, please rate it anyway

  3. #3
    Member
    Join Date
    Nov 2005
    Location
    Kent
    Posts
    40

    Re: if statement blues

    To add to nothing of values post the message boxes would be placed..

    If Me.rdoEL.Checked Then
    MessageBox.Show("test")
    ....rest of code.....

    ElseIf Me.rdoJC.Checked Then
    MessageBox.Show("Please select what library to add book to")
    ....rest of code.....
    It's only easy if you know!
    VB.NET2003/1.1
    VB2005/2.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width