|
-
May 5th, 2002, 10:29 PM
#1
Thread Starter
Hyperactive Member
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
-
May 5th, 2002, 10:36 PM
#2
Stuck in the 80s
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?
-
May 5th, 2002, 10:37 PM
#3
Thread Starter
Hyperactive Member
yes, exactly, and it works fine up untill it hits end sub, when it erases whats in there
-
May 5th, 2002, 10:39 PM
#4
Thread Starter
Hyperactive Member
here is one of them
VB Code:
CS Lansing 1.3 198.109.160.152:27016
-
May 5th, 2002, 10:44 PM
#5
Stuck in the 80s
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.
-
May 5th, 2002, 10:45 PM
#6
Thread Starter
Hyperactive Member
actually, the change event doesnt go unless you actually type somthing in
-
May 5th, 2002, 10:47 PM
#7
Stuck in the 80s
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.
-
May 5th, 2002, 10:48 PM
#8
PowerPoster
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]
-----------------------------------------
-
May 5th, 2002, 10:50 PM
#9
Stuck in the 80s
He wants to change the text property, not the item's text property.
-
May 5th, 2002, 10:51 PM
#10
PowerPoster
Give me some code to fix then.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
May 5th, 2002, 10:51 PM
#11
Thread Starter
Hyperactive Member
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
-
May 5th, 2002, 10:53 PM
#12
Thread Starter
Hyperactive Member
thats only if nobody can think of anything else
-
May 5th, 2002, 10:56 PM
#13
PowerPoster
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
May 5th, 2002, 11:00 PM
#14
PowerPoster
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]
-----------------------------------------
-
May 5th, 2002, 11:05 PM
#15
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!
-
May 5th, 2002, 11:10 PM
#16
PowerPoster
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]
-----------------------------------------
-
May 5th, 2002, 11:17 PM
#17
The problem is with the sapce's, I just tested with known short
text and it works fine... hang on
-
May 5th, 2002, 11:24 PM
#18
PowerPoster
Could u chuck an exit sub in there?
-
May 5th, 2002, 11:29 PM
#19
PowerPoster
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]
-----------------------------------------
-
May 5th, 2002, 11:31 PM
#20
PowerPoster
Well... hmm....... bugger me...
-
May 5th, 2002, 11:54 PM
#21
PowerPoster
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]
-----------------------------------------
-
May 5th, 2002, 11:55 PM
#22
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.
-
May 5th, 2002, 11:56 PM
#23
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
-
May 6th, 2002, 12:14 AM
#24
Thread Starter
Hyperactive Member
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?
-
May 6th, 2002, 12:32 AM
#25
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:
Option Explicit
Private Sub Form_Load()
Combo1.AddItem "ABC"
Combo1.AddItem "123"
End Sub
Private Sub Combo1_Click()
Text1.SetFocus
End Sub
Private Sub Text1_GotFocus()
Combo1.Text = "New Stuff"
Combo1.SetFocus
End Sub
-
May 6th, 2002, 12:40 AM
#26
Including ur modified Code:
VB Code:
Option Explicit
Dim myBLAH As String
Private Sub Form_Load()
Combo1.AddItem "CS Lansing 1.3 198.109.160.152:27016 "
Combo1.AddItem "CS Lansing 1.2 200.100.160.152:12354 "
End Sub
Private Sub Combo1_Click()
Dim sBuff As String
sBuff = Combo1.List(Combo1.ListIndex)
sBuff = Replace(sBuff, " ", "")
myBLAH = Mid$(sBuff, Len(sBuff) - (InStrRev(sBuff, ":") - 8), 15)
Text1.SetFocus
End Sub
Private Sub Text1_GotFocus()
Combo1.Text = myBLAH
Combo1.SetFocus
End Sub
Bruce.
Last edited by Bruce Fox; May 6th, 2002 at 12:52 AM.
-
May 20th, 2002, 09:47 PM
#27
Thread Starter
Hyperactive Member
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?
-
May 21st, 2002, 02:57 AM
#28
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|