Solved

CB_INSERTSTRING

Posted on 1997-08-11
7
522 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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