|
-
Dec 7th, 2002, 02:45 PM
#1
Thread Starter
Lively Member
i look stupid but i need help
hello. i m new 2 this forum and i m new 2 programming. so i have an elementary question(actually much more than one, but just 4 now)
how do i get a selected value from the listbox?
eg.
choice = list1.getselecteditem?
also, how do i declare variables in general, as in it can be shared between 2 different forms.
sorry if i sound really stupid, but i have2 start sumwhere. i tried looking 4 tutorials online, but i don't really understand the variables question.
and online tutorials i can't find the code 2 get selected value from listbox. i don't evn know what most of the properties do 4 the listbox.
my listbox has say, 5 values
qwerty
qwert
qwer
qwe
qw
how 2 make it when i select qwer, it return value 3.
thx alot in advance and sorry 4 spamming ur board with useless questions. i expect 2 learn much from u all.
-
Dec 7th, 2002, 02:50 PM
#2
Frenzied Member
If you want the text of the item selected from a listbox:
...the index of the item selected
Please note the listbox is 0-based, meaning the first item has an index of 0
To declare variables for use throughout your program, declare them as public
-
Dec 7th, 2002, 02:54 PM
#3
Addicted Member
to get the listbox value use this code:
Code:
msgbox me.listbox1.listindex
For the variable to be shared between 2 forms I would add a module to your project and declare the variable publically ie:
Code:
Public MyVariable as String
Good Luck
-
Dec 7th, 2002, 02:59 PM
#4
Thread Starter
Lively Member
-
Dec 7th, 2002, 03:02 PM
#5
Thread Starter
Lively Member
what is the itemdata property for?
how izzit different from index? index is auto numbered?
so if thta's the case, how do i get teh itemdata instead
choice = listbox.itemdata?
-
Dec 7th, 2002, 03:06 PM
#6
Addicted Member
When you enter a value into the listbox you can also set the itemdata which holds a numeric value. This can be a value of your choice which can be queried once the user has selected your item from the list ie:
If the list was:
baked beans
tomato sauce
carrots
the item data could hold the price ie:
399
299
199
these prices are in pence of course.
Regards
-
Dec 7th, 2002, 03:07 PM
#7
Frenzied Member
Index is autonumbered and read-only (0-based)
ItemData can be set to any number (long) you wish. For example, if you wanted to index your values starting with 1, you could do so in ItemData, simply setting the value when you load the listbox.
VB Code:
choice = listbox.ItemData(Index)
'or
listbox.ItemData(Index) = 1
You must specify the index of the ItemData you want to return or set.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|