Solved

CB_INSERTSTRING

Posted on 1997-08-11
7
526 Views
Last Modified: 2008-03-06
All,

Why does it not work, I use VB 5.0, have one combo-box on my form and a command button. When I click on the button a string should be added to the combo (list) box.
But everytime I click 'rare' characters will be added such as |%ù but NOT the string, please help

The code :

Dim a&
Dim b as String

b=String$(255,Chr$(0))

b="Johan"

a=SendMessage(combo1.hWnd,CB_INSERTSTRING,-1,b)

What goes wrong ?
Regards
Johan Loos
jloos@glo.be
0
Comment
Question by:Johanl
[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
7 Comments
 
LVL 2

Expert Comment

by:msiman
ID: 1430258
what so wrong with combo1.additem b ?
the easiest and the safest...
msiman
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1430259
Try
 b ="Johan" & Chr(0)
instead and see if it helps.
0
 
LVL 2

Expert Comment

by:msiman
ID: 1430260
btw: the reason for your problem, is
(I guess...) that in the sendmessage API
the last parameter should be integer, and here,
b is a string...
MSIMAN
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!

 
LVL 5

Expert Comment

by:y96andha
ID: 1430261
I assume that you have declared the parameters for SendMessage like this:

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

0
 

Author Comment

by:Johanl
ID: 1430262
To y96andha : Does not work with chr$(0) at the end.

To msiman and y96andha : yes, my last param is a string . I used the declaration as y96andha say.

strange thing ?
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1430263
And you have also added a ByVal in front of lParam? Svensk?
0
 
LVL 7

Accepted Solution

by:
tward earned 50 total points
ID: 1430264
The Following works just fine for me:

Private Const CB_INSERTSTRING = &H14A
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Dim a&
Dim b As String

b = String$(255, Chr$(0))

b = "Johan"

a = SendMessage(Combo1.hwnd, CB_INSERTSTRING, -1, b)
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 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…
Suggested Courses
Course of the Month6 days, 7 hours left to enroll

634 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