+ Reply to Thread
Results 1 to 10 of 10

Thread: If statement for a combo box

  1. #1
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102

    Question If statement for a combo box

    In one of my subroutines I want to test for an option in a certian combobox. It doesn't matter which option the user has choosen, just that they have chosen one at all.

    How do I word the If statement to test for this.

    Thanks in advance for any help!
    Amber

  2. #2
    Jim Thomlinson
    Guest

    RE: If statement for a combo box

    This check the length of the text in the combobox...

    If CBool(Len(ComboBox1.Text)) Then
    MsgBox "Something"
    Else
    MsgBox "Nothing"
    End If

    Just change ComboBox1 to the name of your combobox...
    --
    HTH...

    Jim Thomlinson


    "Amber_D_Laws" wrote:

    >
    > In one of my subroutines I want to test for an option in a certian
    > combobox. It doesn't matter which option the user has choosen, just
    > that they have chosen one at all.
    >
    > How do I word the If statement to test for this.
    >
    > Thanks in advance for any help!
    > Amber
    >
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=509553
    >
    >


  3. #3
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102
    Thank You Jim,

    What you have seems to make sense, but I am unfamilar with "CBool" and "Len". What exactly do these functions(?) do?

    This question is of course out of pure curiosity. The meat of the matter is that presumably the code you provided will test for any selection in the combobox by testing for any lenght of text. Which if I am reading what you wrote correctly, means that I can just paste in the code I have written (the stuff I want it to do if the user has made a selection in the combo box) into where you have MsgBox "Something". Right?

    Regards,
    Amber


    Quote Originally Posted by Jim Thomlinson
    This check the length of the text in the combobox...

    If CBool(Len(ComboBox1.Text)) Then
    MsgBox "Something"
    Else
    MsgBox "Nothing"
    End If

    Just change ComboBox1 to the name of your combobox...
    --
    HTH...

    Jim Thomlinson


    "Amber_D_Laws" wrote:

    >
    > In one of my subroutines I want to test for an option in a certian
    > combobox. It doesn't matter which option the user has choosen, just
    > that they have chosen one at all.
    >
    > How do I word the If statement to test for this.
    >
    > Thanks in advance for any help!
    > Amber
    >
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=509553
    >
    >

  4. #4
    Jim Thomlinson
    Guest

    Re: If statement for a combo box

    CBool is like Cint or CStr. It converts what you have to a data type. In this
    case a boolean. This works because in a computer 0 is false and everything
    else is true. So if the lenght is 0 CBool returns False. If the length is
    anything other than 0 then CBool returns True. You could also write the
    function...

    If Len(ComboBox1.Text)>0 Then
    MsgBox "Something"
    Else
    MsgBox "Nothing"
    End If

    Either way is just fine.
    --
    HTH...

    Jim Thomlinson


    "Amber_D_Laws" wrote:

    >
    > Thank You Jim,
    >
    > What you have seems to make sense, but I am unfamilar with "CBool" and
    > "Len". What exactly do these functions(?) do?
    >
    > This question is of course out of pure curiosity. The meat of the
    > matter is that presumably the code you provided will test for any
    > selection in the combobox by testing for any lenght of text. Which if I
    > am reading what you wrote correctly, means that I can just paste in the
    > code I have written (the stuff I want it to do if the user has made a
    > selection in the combo box) into where you have MsgBox "Something".
    > Right?
    >
    > Regards,
    > Amber
    >
    >
    > Jim Thomlinson Wrote:
    > > This check the length of the text in the combobox...
    > >
    > > If CBool(Len(ComboBox1.Text)) Then
    > > MsgBox "Something"
    > > Else
    > > MsgBox "Nothing"
    > > End If
    > >
    > > Just change ComboBox1 to the name of your combobox...
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "Amber_D_Laws" wrote:
    > >
    > > >
    > > > In one of my subroutines I want to test for an option in a certian
    > > > combobox. It doesn't matter which option the user has choosen, just
    > > > that they have chosen one at all.
    > > >
    > > > How do I word the If statement to test for this.
    > > >
    > > > Thanks in advance for any help!
    > > > Amber
    > > >
    > > >
    > > > --
    > > > Amber_D_Laws
    > > >

    > > ------------------------------------------------------------------------
    > > > Amber_D_Laws's Profile:

    > > http://www.excelforum.com/member.php...o&userid=30012
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=509553
    > > >
    > > >

    >
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=509553
    >
    >


  5. #5
    Tom Ogilvy
    Guest

    Re: If statement for a combo box

    For an ActiveX combobox from the Control toolbox toolbar, if you limit the
    selection to items in the list you can use

    if Combobox1.ListIndex <> -1 then
    ' as selection has been made

    If you don't want to allow type in entries (required an item in the
    list -they can still type that item in), you should set its properties so
    they are not allowed.

    --
    Regards,
    Tom Ogilvy

    "Amber_D_Laws" <Amber_D_Laws.22vppa_1139349003.9848@excelforum-nospam.com>
    wrote in message
    news:Amber_D_Laws.22vppa_1139349003.9848@excelforum-nospam.com...
    >
    > In one of my subroutines I want to test for an option in a certian
    > combobox. It doesn't matter which option the user has choosen, just
    > that they have chosen one at all.
    >
    > How do I word the If statement to test for this.
    >
    > Thanks in advance for any help!
    > Amber
    >
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile:

    http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=509553
    >




  6. #6
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102
    Makes perfect sense Jim. I appreciate the explination. However, it leads me to a second question.

    What does "Len" mean in coding terms?

    Amber


    Quote Originally Posted by Jim Thomlinson
    CBool is like Cint or CStr. It converts what you have to a data type. In this
    case a boolean. This works because in a computer 0 is false and everything
    else is true. So if the lenght is 0 CBool returns False. If the length is
    anything other than 0 then CBool returns True. You could also write the
    function...

    If Len(ComboBox1.Text)>0 Then
    MsgBox "Something"
    Else
    MsgBox "Nothing"
    End If

    Either way is just fine.
    --
    HTH...

    Jim Thomlinson


    "Amber_D_Laws" wrote:

    >
    > Thank You Jim,
    >
    > What you have seems to make sense, but I am unfamilar with "CBool" and
    > "Len". What exactly do these functions(?) do?
    >
    > This question is of course out of pure curiosity. The meat of the
    > matter is that presumably the code you provided will test for any
    > selection in the combobox by testing for any lenght of text. Which if I
    > am reading what you wrote correctly, means that I can just paste in the
    > code I have written (the stuff I want it to do if the user has made a
    > selection in the combo box) into where you have MsgBox "Something".
    > Right?
    >
    > Regards,
    > Amber
    >
    >
    > Jim Thomlinson Wrote:
    > > This check the length of the text in the combobox...
    > >
    > > If CBool(Len(ComboBox1.Text)) Then
    > > MsgBox "Something"
    > > Else
    > > MsgBox "Nothing"
    > > End If
    > >
    > > Just change ComboBox1 to the name of your combobox...
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "Amber_D_Laws" wrote:
    > >
    > > >
    > > > In one of my subroutines I want to test for an option in a certian
    > > > combobox. It doesn't matter which option the user has choosen, just
    > > > that they have chosen one at all.
    > > >
    > > > How do I word the If statement to test for this.
    > > >
    > > > Thanks in advance for any help!
    > > > Amber
    > > >
    > > >
    > > > --
    > > > Amber_D_Laws
    > > >

    > > ------------------------------------------------------------------------
    > > > Amber_D_Laws's Profile:

    > > http://www.excelforum.com/member.php...o&userid=30012
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=509553
    > > >
    > > >

    >
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=509553
    >
    >

  7. #7
    Jim Thomlinson
    Guest

    Re: If statement for a combo box

    The Len function returns the length of a string.
    --
    HTH...

    Jim Thomlinson


    "Amber_D_Laws" wrote:

    >
    > Makes perfect sense Jim. I appreciate the explination. However, it leads
    > me to a second question.
    >
    > What does "Len" mean in coding terms?
    >
    > Amber
    >
    >
    > Jim Thomlinson Wrote:
    > > CBool is like Cint or CStr. It converts what you have to a data type. In
    > > this
    > > case a boolean. This works because in a computer 0 is false and
    > > everything
    > > else is true. So if the lenght is 0 CBool returns False. If the length
    > > is
    > > anything other than 0 then CBool returns True. You could also write
    > > the
    > > function...
    > >
    > > If Len(ComboBox1.Text)>0 Then
    > > MsgBox "Something"
    > > Else
    > > MsgBox "Nothing"
    > > End If
    > >
    > > Either way is just fine.
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "Amber_D_Laws" wrote:
    > >
    > > >
    > > > Thank You Jim,
    > > >
    > > > What you have seems to make sense, but I am unfamilar with "CBool"

    > > and
    > > > "Len". What exactly do these functions(?) do?
    > > >
    > > > This question is of course out of pure curiosity. The meat of the
    > > > matter is that presumably the code you provided will test for any
    > > > selection in the combobox by testing for any lenght of text. Which if

    > > I
    > > > am reading what you wrote correctly, means that I can just paste in

    > > the
    > > > code I have written (the stuff I want it to do if the user has made

    > > a
    > > > selection in the combo box) into where you have MsgBox "Something".
    > > > Right?
    > > >
    > > > Regards,
    > > > Amber
    > > >
    > > >
    > > > Jim Thomlinson Wrote:
    > > > > This check the length of the text in the combobox...
    > > > >
    > > > > If CBool(Len(ComboBox1.Text)) Then
    > > > > MsgBox "Something"
    > > > > Else
    > > > > MsgBox "Nothing"
    > > > > End If
    > > > >
    > > > > Just change ComboBox1 to the name of your combobox...
    > > > > --
    > > > > HTH...
    > > > >
    > > > > Jim Thomlinson
    > > > >
    > > > >
    > > > > "Amber_D_Laws" wrote:
    > > > >
    > > > > >
    > > > > > In one of my subroutines I want to test for an option in a

    > > certian
    > > > > > combobox. It doesn't matter which option the user has choosen,

    > > just
    > > > > > that they have chosen one at all.
    > > > > >
    > > > > > How do I word the If statement to test for this.
    > > > > >
    > > > > > Thanks in advance for any help!
    > > > > > Amber
    > > > > >
    > > > > >
    > > > > > --
    > > > > > Amber_D_Laws
    > > > > >
    > > > >

    > > ------------------------------------------------------------------------
    > > > > > Amber_D_Laws's Profile:
    > > > > http://www.excelforum.com/member.php...o&userid=30012
    > > > > > View this thread:
    > > > > http://www.excelforum.com/showthread...hreadid=509553
    > > > > >
    > > > > >
    > > >
    > > >
    > > > --
    > > > Amber_D_Laws
    > > >

    > > ------------------------------------------------------------------------
    > > > Amber_D_Laws's Profile:

    > > http://www.excelforum.com/member.php...o&userid=30012
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=509553
    > > >
    > > >

    >
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=509553
    >
    >


  8. #8
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102

    Red face

    Jim,

    Why is it that the simplest things can make us feel so stupid. I mean, well... duh.... Len=Length, my god could it be more obvious. Sometimes I think I must not be thinking when I ask these things.

    Thanks!

    Quote Originally Posted by Jim Thomlinson
    The Len function returns the length of a string.
    --
    HTH...

    Jim Thomlinson


    "Amber_D_Laws" wrote:

    >
    > Makes perfect sense Jim. I appreciate the explination. However, it leads
    > me to a second question.
    >
    > What does "Len" mean in coding terms?
    >
    > Amber
    >
    >
    > Jim Thomlinson Wrote:
    > > CBool is like Cint or CStr. It converts what you have to a data type. In
    > > this
    > > case a boolean. This works because in a computer 0 is false and
    > > everything
    > > else is true. So if the lenght is 0 CBool returns False. If the length
    > > is
    > > anything other than 0 then CBool returns True. You could also write
    > > the
    > > function...
    > >
    > > If Len(ComboBox1.Text)>0 Then
    > > MsgBox "Something"
    > > Else
    > > MsgBox "Nothing"
    > > End If
    > >
    > > Either way is just fine.
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "Amber_D_Laws" wrote:
    > >
    > > >
    > > > Thank You Jim,
    > > >
    > > > What you have seems to make sense, but I am unfamilar with "CBool"

    > > and
    > > > "Len". What exactly do these functions(?) do?
    > > >
    > > > This question is of course out of pure curiosity. The meat of the
    > > > matter is that presumably the code you provided will test for any
    > > > selection in the combobox by testing for any lenght of text. Which if

    > > I
    > > > am reading what you wrote correctly, means that I can just paste in

    > > the
    > > > code I have written (the stuff I want it to do if the user has made

    > > a
    > > > selection in the combo box) into where you have MsgBox "Something".
    > > > Right?
    > > >
    > > > Regards,
    > > > Amber
    > > >
    > > >
    > > > Jim Thomlinson Wrote:
    > > > > This check the length of the text in the combobox...
    > > > >
    > > > > If CBool(Len(ComboBox1.Text)) Then
    > > > > MsgBox "Something"
    > > > > Else
    > > > > MsgBox "Nothing"
    > > > > End If
    > > > >
    > > > > Just change ComboBox1 to the name of your combobox...
    > > > > --
    > > > > HTH...
    > > > >
    > > > > Jim Thomlinson
    > > > >
    > > > >
    > > > > "Amber_D_Laws" wrote:
    > > > >
    > > > > >
    > > > > > In one of my subroutines I want to test for an option in a

    > > certian
    > > > > > combobox. It doesn't matter which option the user has choosen,

    > > just
    > > > > > that they have chosen one at all.
    > > > > >
    > > > > > How do I word the If statement to test for this.
    > > > > >
    > > > > > Thanks in advance for any help!
    > > > > > Amber
    > > > > >
    > > > > >
    > > > > > --
    > > > > > Amber_D_Laws
    > > > > >
    > > > >

    > > ------------------------------------------------------------------------
    > > > > > Amber_D_Laws's Profile:
    > > > > http://www.excelforum.com/member.php...o&userid=30012
    > > > > > View this thread:
    > > > > http://www.excelforum.com/showthread...hreadid=509553
    > > > > >
    > > > > >
    > > >
    > > >
    > > > --
    > > > Amber_D_Laws
    > > >

    > > ------------------------------------------------------------------------
    > > > Amber_D_Laws's Profile:

    > > http://www.excelforum.com/member.php...o&userid=30012
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=509553
    > > >
    > > >

    >
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=509553
    >
    >

  9. #9
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102
    Sorry I didn't respond sooner Tom, your comment kinda slipped by me.

    So, after reading... Which property controls if the user can use typed in entries or not? I have wanted to change that, but I didn't know I could.

    Quote Originally Posted by Tom Ogilvy
    For an ActiveX combobox from the Control toolbox toolbar, if you limit the
    selection to items in the list you can use

    if Combobox1.ListIndex <> -1 then
    ' as selection has been made

    If you don't want to allow type in entries (required an item in the
    list -they can still type that item in), you should set its properties so
    they are not allowed.

    --
    Regards,
    Tom Ogilvy

    "Amber_D_Laws" <Amber_D_Laws.22vppa_1139349003.9848@excelforum-nospam.com>
    wrote in message
    news:Amber_D_Laws.22vppa_1139349003.9848@excelforum-nospam.com...
    >
    > In one of my subroutines I want to test for an option in a certian
    > combobox. It doesn't matter which option the user has choosen, just
    > that they have chosen one at all.
    >
    > How do I word the If statement to test for this.
    >
    > Thanks in advance for any help!
    > Amber
    >
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile:

    http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=509553
    >

  10. #10
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102
    Nevermind.....I found it. Match Required! Thanks for the advice, and the code worked like a charm, as usual. What would I do without you Tom?

    Sincerely,
    Amber

    Quote Originally Posted by Amber_D_Laws
    Sorry I didn't respond sooner Tom, your comment kinda slipped by me.

    So, after reading... Which property controls if the user can use typed in entries or not? I have wanted to change that, but I didn't know I could.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0