dcsimg
Results 1 to 3 of 3

Thread: Combobox changing selection disables button again

  1. #1

    Thread Starter
    Member G33kman's Avatar
    Join Date
    Nov 2009
    Location
    Mankato, MN
    Posts
    40

    Question Combobox changing selection disables button again

    Ok so i'm trying to set up my program so that when I choose WinRar it opens a new window asking which architecture to use. I have a combobox set up with both architectures in it. I have the accept button disabled so that you have to choose an architecture and I figured out how to make it so that when you select one architecture it will enable the accept button but if you choose the other architecture it disables the button.
    I'm thinking that this has to do with the way I have my code setup but i'm not sure how to change it.
    Any ideas?

    Here's my code:
    Code:
    Private Sub cmbx_rar_wdw_arch_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbx_rar_wdw_arch.SelectedIndexChanged
            If cmbx_rar_wdw_arch.SelectedItem = ("32-Bit (x86)") Then
                btn_rar_wdw_acpt.Enabled = True
            Else : btn_rar_wdw_acpt.Enabled = False
            End If
            If cmbx_rar_wdw_arch.SelectedItem = ("64-Bit (x64)") Then
                btn_rar_wdw_acpt.Enabled = True
            Else : btn_rar_wdw_acpt.Enabled = False
            End If
        End Sub

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,900

    Re: Combobox changing selection disables button again

    As I suggested in one of your previous posts, look at your code one line at a time and ask yourself exactly what's going to happen at each line. You have two separate If blocks and the second If block is going to set the Enabled property of your Button to True or False, depending on whether or not x64 is selected. As such, whatever the first If block did is irrelevant because it will be overridden by what the second If block does.

    I think the first thing you need to do is work out the logic of what you're actually trying to do before you write any code because that code doesn't make any sense. You're trying to enable the Button if x86 is selected and if x64 is selected and disable it if x86 is not selected or if x64 is not selected. That means that if x86 is seleected then x64 is not selected so you're trying to enable and disable the Button at the same time.

  3. #3

    Thread Starter
    Member G33kman's Avatar
    Join Date
    Nov 2009
    Location
    Mankato, MN
    Posts
    40

    Re: Combobox changing selection disables button again

    Quote Originally Posted by jmcilhinney View Post
    As I suggested in one of your previous posts, look at your code one line at a time and ask yourself exactly what's going to happen at each line. You have two separate If blocks and the second If block is going to set the Enabled property of your Button to True or False, depending on whether or not x64 is selected. As such, whatever the first If block did is irrelevant because it will be overridden by what the second If block does.

    I think the first thing you need to do is work out the logic of what you're actually trying to do before you write any code because that code doesn't make any sense. You're trying to enable the Button if x86 is selected and if x64 is selected and disable it if x86 is not selected or if x64 is not selected. That means that if x86 is seleected then x64 is not selected so you're trying to enable and disable the Button at the same time.
    Oh... Alright I'll check out that other post I didn't think it was the same thing. Thanks
    It's those dang ELSE statements everytime!
    http://www.vbforums.com/showthread.php?t=591994
    Last edited by G33kman; Nov 19th, 2009 at 04:41 PM. Reason: Added link to other post...

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width