Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting the text of a ComboBox in code  VB4 vs VB6

Posted on 2000-03-31
21
Medium Priority
?
353 Views
Last Modified: 2010-05-02
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
Comment
Question by:markogonzo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
  • 3
  • +1
21 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2674775
what do you mean by the characters change according to a certain rule?
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2674845
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
 

Author Comment

by:markogonzo
ID: 2674861
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:markogonzo
ID: 2674896
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
 

Expert Comment

by:TheMask
ID: 2674911
Can you explain more the code you wrote above, it doesn't make sense
0
 

Author Comment

by:markogonzo
ID: 2674941
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
 

Author Comment

by:markogonzo
ID: 2674943
Edited text of question.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2674944
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2674946
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
 

Author Comment

by:markogonzo
ID: 2674973
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2674976
markogonzo set:

Combo.Locked = False
Combo.Style = 0

and it will work fine.. <smile>
0
 

Author Comment

by:markogonzo
ID: 2674980
Reply to wsh2 -- 2:58 PST

No it won't.  I already have those
settings.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2674990
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
 

Author Comment

by:markogonzo
ID: 2675031
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
 
LVL 28

Accepted Solution

by:
AzraSound earned 300 total points
ID: 2675042
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2675066
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
 

Author Comment

by:markogonzo
ID: 2675114
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
 

Author Comment

by:markogonzo
ID: 2675119
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2675141
Wait a second.. have you installed VB6 Service Pack 3? If not, get it done.. <smile>.
0
 

Author Comment

by:markogonzo
ID: 2675152
Reply to wsh2 - 4:19 PST:

Yes, I'm running VB6 SP3.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2675213
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question