Solved

Setting the text of a ComboBox in code  VB4 vs VB6

Posted on 2000-03-31
21
336 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
  • 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 100 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now