Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Populating a Combobox
#1
I tried using a FOR/Next to quickly populate a Combobox and a Listbox control, but it wouldn't work correctly, unlike when I tried it in other basics.

This didn't work:

Code:
FOR x = 0 TO  3                                      
     itm = "Item" + STR$(x)                        ' Create an Item
     SendMessage hComboBox1, CB_ADDSTRING, 0, STRPTR(itm)     '
NEXT X



This did work:

Code:
SendMessage hComboBox2, CB_ADDSTRING, 0, "Item 1 "
        SendMessage hComboBox2, CB_ADDSTRING, 0, "Item 2 "
        SendMessage hComboBox2, CB_ADDSTRING, 0, "Item 3 "
        SendMessage hComboBox2, CB_ADDSTRING, 0, "Item 4 "



Should I do something different to make the variable work.
Reply
#2
STRPTR?
I'd knock on wood, but my desk is particle board.
Reply
#3
I tried removing the STRPTR before I posted the first time. It didn't help
Reply
#4
Maybe the declaration is incorrect in the include file...that's a pretty good possibility.
I'd knock on wood, but my desk is particle board.
Reply
#5
Hi:

SendMessage() is defined Visual Basic style in the headerfiles, which is different to how it is defined in C. Your code looks logical, but as you found out, it does not work. Try this code:

Code:
FOR x = 0 TO  3                                      
     itm = "Item" + STR$(x)                        ' Create an Item
     SendMessage hComboBox1, CB_ADDSTRING, 0, BYVAL itm
NEXT X

This is like the way I have used it in a list box. If you look back through the posts, you will see I asked the same question about how to use SendMessage() a few days ago.

Garvan
Reply
#6
Thanks, I didn't try BYVAL itm

I guess I should go back and read some of these things, I might learn how to use freebasic.
Reply
#7
Yeah, VB weirdness, BYREF AS ANY accepts anything, but with string's, pointers and literals you have to use the BYVAL clause.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)