Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

Setting the text of a ComboBox in code VB4 vs VB6

The user drops the ComboBox list,
clicks an item, and the text appears in
the ComboBox field -- with the characters changed according to a
certain rule.  That's the way it works,
and should work, in VB 4.  

The same program in VB 6 does the
following: the field goes completely
blank when you click on any item.  

Here's the gist of the code:
   sub Combo_Click()
    a = Combo
    Combo = modify(a)
   end sub

How do I get it to work in VB6 as it
does in VB4 ?

0
markogonzo
Asked:
markogonzo
  • 10
  • 7
  • 3
  • +1
1 Solution
 
AzraSoundCommented:
what do you mean by the characters change according to a certain rule?
0
 
wsh2Commented:
This appears to be a bug in the ComboBox.. <sigh>. But.. here is a workaround.. <smile>.

<----- Code Begin ----->

Private Sub Combo1_Click()
With Combo1

   dim strModify as String
   strModify = "***" _
      & .List(.ListIndex) _
      & "***" ' Or any change you want
   SendKeys strModify

End With
End Sub

<----- Code End ----->

0
 
markogonzoAuthor Commented:
The rule doesn't matter, the same problem occurs.  But if you must know,  the first letter is removed. Thus if the user clicks  "ABC" on the drop down list what should appear in the field is "BC"  -- and it does in VB 4,  but in VB 6 the field goes blank.  You could replace that with any other rule (I've tried several, and I'm generalizing.)

NOTE:  If you watch closely on a slow machine, for a momentary flicker you do see the proper string in the ComboBox field, then it goes blank.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
markogonzoAuthor Commented:
The rule doesn't matter, the same problem occurs.  But if you must know,  the first letter is removed. Thus if the user clicks  "ABC" on the drop down list what should appear in the field is "BC"  -- and it does in VB 4,  but in VB 6 the field goes blank.  You could replace that with any other rule (I've tried several, and I'm generalizing.)

NOTE:  If you watch closely on a slow machine, for a momentary flicker you do see the proper string in the ComboBox field, then it goes blank.
0
 
TheMaskCommented:
Can you explain more the code you wrote above, it doesn't make sense
0
 
markogonzoAuthor Commented:
Reply to wsh2:

Wow! A rather big bug too.

Your work-around doesn't work
as given.  If you delete the
two & continuation lines it does,
though the user's PC beeps rapidly for
the longer items of the list.

This is a klugy solution I'd already
considered.  Is there no other?

Thank you for your response.

Mark Hunter

0
 
markogonzoAuthor Commented:
Edited text of question.
0
 
AzraSoundCommented:
heres my workaround:

Private Sub Combo1_Click()
    i = Combo1.ListIndex
    Combo1.List(i) = Right(Combo1.List(i), Len(Combo1.List(i)) - 1)
End Sub


it shows up in the combobox too

0
 
wsh2Commented:
What markogonzo wants to do.. is when the user clicks on a dropdown item.. modify the Text before it appears in the Combobox.Text field. If you code the following..

Private Sub Combo1_Click()
With Combo1

   Combo1.Text = "***" _
      & .List(.ListIndex) _
      & "***" ' Or any change you want

End With
End Sub

... sure enough you get a Blank Text box.

The way to get around it.. is to just Sendeys to the Combo1.Text, as focus returns to it right after the click.. <smile>
0
 
markogonzoAuthor Commented:
Reply to AzraSound --

Your code works as far as silently
placing the correct text in the combo
box.

BUT, it modifies the item in the list as well.  I want the list to remain unchanged -- as it does in VB 4.

Thank you for your response.

Mark
0
 
wsh2Commented:
markogonzo set:

Combo.Locked = False
Combo.Style = 0

and it will work fine.. <smile>
0
 
markogonzoAuthor Commented:
Reply to wsh2 -- 2:58 PST

No it won't.  I already have those
settings.
0
 
wsh2Commented:
Makogonzo: Works fine.. assuming that you do not have non-character data in your Combobox list items.. and do not have non-character data in your Combo List modify routine.. <smile>.

0
 
markogonzoAuthor Commented:
Reply to wsh2 -- 3:04 PST

Hm... There must be something else in
the stew, because I'm  working with
only letters and digits, Locked is
false, and Style is 0  -- I checked
both after your post.

Let me explain how I compare VB4 with VB6.   I keep the project in VB4 format
-- I always save using VB4.  Then I can run the code in either 4 or 6, because 6 will convert 4 to 6.

For following the advice here, I have
been using VB 6 exclusively -- but not
saving the changes.

Thanks again.

Mark
0
 
AzraSoundCommented:
you can place a textbox with the exact dimensions over the combobox control and place the text in there..kinda reaching here   =)

Private Sub Combo1_Click()
    i = Combo1.ListIndex
    Text1.Text = Right(Combo1.List(i), Len(Combo1.List(i)) - 1)
End Sub

0
 
wsh2Commented:
Boy do I have a solution for you.. <smile>. Feeling dangerous?.. LOL. Ok here goes.. try using the "Microsoft Forms 2.0 Object Library" (Vb Menu -> Project -> Components). In it you will find a ComboBox1 Control.. place it on your form and name it Combo1 (or whatever your control is named) for temporary code compatability. With it.. guess what.. the following works !!!

Private Sub Combobox1_Click()
With ComboBox1

   .Text = "*************************************" _
      & (.List(.ListIndex) _
      & "****************************************")

End With
End Sub
0
 
markogonzoAuthor Commented:
Reply to AzraSound --
  Very clever.  I'll wait a bit, and if no one thinks of a better solution by tomorrow, I'll accept yours.

Thanks,
Mark
0
 
markogonzoAuthor Commented:
Reply to wsh2 --

Dangerous is right.  For the first time
ever with VB6 I got "This program has performed an illegal operation and
will be arrested"  or something like that.

Anyway, I'd prefer not to clutter my
toolbox with duplicate controls.

Mark
0
 
wsh2Commented:
Wait a second.. have you installed VB6 Service Pack 3? If not, get it done.. <smile>.
0
 
markogonzoAuthor Commented:
Reply to wsh2 - 4:19 PST:

Yes, I'm running VB6 SP3.
0
 
wsh2Commented:
Welp.. you are on your own then.. <sighing>. All that was mentioned, worked well here.. I must say.. the abends at your site.. are quite disconcerting. Oh well.. such is life in the Microsoft lane.. Good luck in your endeavors.. <smile>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 10
  • 7
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now