Results 1 to 28 of 28

Thread: on combobox click..

  1. #1

    Thread Starter
    Hyperactive Member FUBAR's Avatar
    Join Date
    Jan 2000
    Posts
    307

    on combobox click..

    ok, i have a combo box that has some stuff in the list that has
    a descriptions, then bunch of spaces and an ip address, basicly u pull down the combo box and click the descriptions, and i want the ip to go in for the text, but my code doesnt work, the combobox text always ends up blank

    here is my code, this code worked when i replaced myBLAH with like text1.text or somthing

    Private Sub Combo1_Click()
    Dim myBLAH As String
    Debug.Print Trim$(Right$(Combo1.List(Combo1.ListIndex), 50))
    myBLAH = Trim$(Right$(Combo1.List(Combo1.ListIndex), 50))
    Combo1.Text = myBLAH
    End Sub

    when i debug it, it goes in there on the combo1.text = myBLAH, but then as soon as it hits end sub combo1.text goes blank

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    So you have it like this:

    Code:
    Description      IP
    Description      IP
    Description      IP
    Description      IP
    And when they select one, you just want the text in the combo to show the IP?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Hyperactive Member FUBAR's Avatar
    Join Date
    Jan 2000
    Posts
    307
    yes, exactly, and it works fine up untill it hits end sub, when it erases whats in there

  4. #4

    Thread Starter
    Hyperactive Member FUBAR's Avatar
    Join Date
    Jan 2000
    Posts
    307
    here is one of them

    VB Code:
    1. CS Lansing 1.3                                    198.109.160.152:27016

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Yeah, I see what you mean. It's because you have your code in the click event, and the change event fires after the click event.

    How you would fix it, I have no idea.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Hyperactive Member FUBAR's Avatar
    Join Date
    Jan 2000
    Posts
    307
    actually, the change event doesnt go unless you actually type somthing in

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    hmm...well something is causing it. because if you put a message box before the end sub, you can see that it changed it, but then it goes away after you close the message box.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    The reason is that the Combo.Text property of a combo box only refers to the text of a displayed item. You can't change the actuall value of that item through the .Text property.

    You will need to do something with the .ListItems property, or perhaps a .RemoveItem/.AddItem combination.
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    He wants to change the text property, not the item's text property.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Give me some code to fix then.
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  11. #11

    Thread Starter
    Hyperactive Member FUBAR's Avatar
    Join Date
    Jan 2000
    Posts
    307
    sounds like too much work, ill just use a not quite effecient methoad, but works, i turna timer on b4 end sub, then in the timer it changes combo1.text = myBLAH

  12. #12

    Thread Starter
    Hyperactive Member FUBAR's Avatar
    Join Date
    Jan 2000
    Posts
    307
    thats only if nobody can think of anything else

  13. #13
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Give us a minute.
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  14. #14
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    I would suggest that after you click the combo, it also selects an item (in the background) - so when you try to set the text in the Click event, it tries to change the listindex to whichever item matches that text, can't find it and defaults to -1, which then also clears the text.

    In conclusion -> you can't set the combo text in the click event.

    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  15. #15
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Can u use an IF Then clause with a "Display Text" Constant.

    In other words, if the Text is'nt what u want during the Change_Event, then change it. Subsiquantly, the change event will, fire once the constant has be set, however, u could include
    an Exit Sub in th eIf Then clause... Hope that makes sense!

  16. #16
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Originally posted by Bruce Fox
    Hope that makes sense!
    No, not really...

    Any text that isn't a listitem in the Click event will get removed, I believe.
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  17. #17
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    The problem is with the sapce's, I just tested with known short
    text and it works fine... hang on

  18. #18
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Could u chuck an exit sub in there?
    Don't Rate my posts.

  19. #19
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Originally posted by Pc_Madness
    Could u chuck an exit sub in there?
    Nope. The 'deletion' is happening in the control not on the form.
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  20. #20
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Well... hmm....... bugger me...
    Don't Rate my posts.

  21. #21
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    That works because the .Text you set in the combo matches one of the ListItems - so it doesn't get removed. However, when the text doesn't match, it won't work, because, as I said, I think the combo looks for an item matching after it raised the click event, and if there's no match, it reverts to its default (.ListIndex = -1)

    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  22. #22
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Sorry Guys, I misslead myself...

    I saw a result and came to the wrong conclusion. (I thought It worked).

    As rjlohan said: In conclusion -> you can't set the combo text in the click event.


  23. #23
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Originally posted by rjlohan
    That works because the .Text you set in the combo matches one of the ListItems - so it doesn't get removed.
    Yep, that was what I just 'clicked' too....
    I have punished myself

  24. #24

    Thread Starter
    Hyperactive Member FUBAR's Avatar
    Join Date
    Jan 2000
    Posts
    307
    grr, nobody knows, do u think my idea would be ok then with the timer or what?

    or um, is there anyway to just run a sub after that sub has completed?

  25. #25
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    The way I just got around that was to 'hide' a TextBox, and in the Combo
    _Click Event, I SetFocus to Text1.
    In the Text1 GotFocus Event I placed the new ComBo1.Text, then
    returned the Focus back to the Combo1.

    Like;
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Combo1.AddItem "ABC"
    5.     Combo1.AddItem "123"
    6. End Sub
    7.  
    8. Private Sub Combo1_Click()
    9.     Text1.SetFocus
    10. End Sub
    11.  
    12. Private Sub Text1_GotFocus()
    13.     Combo1.Text = "New Stuff"
    14.     Combo1.SetFocus
    15. End Sub

  26. #26
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Including ur modified Code:
    VB Code:
    1. Option Explicit
    2.  Dim myBLAH As String
    3.  
    4. Private Sub Form_Load()
    5.     Combo1.AddItem "CS Lansing 1.3                                    198.109.160.152:27016                             "
    6.     Combo1.AddItem "CS Lansing 1.2                                    200.100.160.152:12354                             "
    7. End Sub
    8.  
    9. Private Sub Combo1_Click()
    10.     Dim sBuff As String
    11.  
    12.     sBuff = Combo1.List(Combo1.ListIndex)
    13.     sBuff = Replace(sBuff, " ", "")
    14.  
    15.     myBLAH = Mid$(sBuff, Len(sBuff) - (InStrRev(sBuff, ":") - 8), 15)
    16.  
    17.    Text1.SetFocus
    18. End Sub
    19.  
    20. Private Sub Text1_GotFocus()
    21.     Combo1.Text = myBLAH
    22.     Combo1.SetFocus
    23. End Sub


    Bruce.
    Last edited by Bruce Fox; May 6th, 2002 at 12:52 AM.

  27. #27

    Thread Starter
    Hyperactive Member FUBAR's Avatar
    Join Date
    Jan 2000
    Posts
    307
    thanx, the text1.setfocus worked for that

    1 other problem, i hope someone can solve

    if i try and load, and set the currenet listindex on formload because the controls arnt built yet, it tires to do the setfocus, so does anybody know a way to make it so when the program first loads it wont do the setfocus, but will work like that after the program loaded?

  28. #28
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Try putting it in the Form_Activate event instead of Form_Load.
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

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