| | |
DropList Help?
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2007
Posts: 9
Reputation:
Solved Threads: 0
I have several drop lists on my form, with either numbers or names on them. I want to change it so each item on the drop list has a certain "value" to it. For example, if a was "1" on my first drop list and hello was "23", wen I select "a" and "hello" from the list and I click calculate, it will do the mathematical equation of 1*23. Is there any way?
Do you mean the listindex property (for a listbox)?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim a As Integer Dim b As Integer Private Sub Command1_Click() If List1.ListIndex = -1 Then MsgBox "nothing selected" ElseIf List1.ListIndex = 0 Then a = List1.ListIndex + 1 MsgBox "The value is " & a a = 0 b = 0 Exit Sub ElseIf List1.ListIndex = 1 Then b = List1.ListIndex + 1 MsgBox "The value is " & b a = 0 b = 0 Exit Sub End If End Sub Private Sub Form_Load() List1.AddItem "Cat" List1.AddItem "Dog" End Sub
•
•
Join Date: Sep 2007
Posts: 9
Reputation:
Solved Threads: 0
I have no idea, but I think both of you are right. Prozeen, can you please explain how the listbox property works? My file should look like this, to make my situation more clear.
http://img404.imageshack.us/img404/4...athtollwk3.jpg
http://img404.imageshack.us/img404/4...athtollwk3.jpg
Maybe try this? Amazing things you can do with the Listbox control Or, check out the zip file. Good luck.
use this simple code.
Private Sub Command1_Click()
MsgBox Combo1.ListIndex + 1 & "*" & Combo2.ListIndex + 1
End Sub
Private Sub Form_Load()
With Combo1
.AddItem "a"
.AddItem "b"
.AddItem "c"
End With
With Combo2
.AddItem "welcome"
.AddItem "to"
.AddItem "vb"
.AddItem "programming"
End With
End Sub
Private Sub Command1_Click()
MsgBox Combo1.ListIndex + 1 & "*" & Combo2.ListIndex + 1
End Sub
Private Sub Form_Load()
With Combo1
.AddItem "a"
.AddItem "b"
.AddItem "c"
End With
With Combo2
.AddItem "welcome"
.AddItem "to"
.AddItem "vb"
.AddItem "programming"
End With
End Sub
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
Thanks Debashis. I appreciate your reply. But I think I can explain this too. Hope you will recognize that.
n louislam 123 here are explanations. go through it......
the code in the form_load event simply adds some elements in the two combo boxes.three elements in combo1 and four elements in combo2.
now the code in command1_click event :-
whenver you select an item from both the combo boxes it will trap the index value for the selected item and add 1 to it,so that it can be looked as real numbers.hope u know that the combo box is a sort of array and the elements stored in an array is identified by its position no.,also known as index or subscript value and this index value always starts from 0.so,when you select the first item in the combo1 the event will trap its index as 0 and add 1 to it.so,it will become 0+1=1.same thing is for combo2 also.after this the code will just concate the two resulted index values and put an asterix between them.
hope the above explanation is enough for you to understand the logic behind this coding.
regards
Shouvik
n louislam 123 here are explanations. go through it......
the code in the form_load event simply adds some elements in the two combo boxes.three elements in combo1 and four elements in combo2.
now the code in command1_click event :-
whenver you select an item from both the combo boxes it will trap the index value for the selected item and add 1 to it,so that it can be looked as real numbers.hope u know that the combo box is a sort of array and the elements stored in an array is identified by its position no.,also known as index or subscript value and this index value always starts from 0.so,when you select the first item in the combo1 the event will trap its index as 0 and add 1 to it.so,it will become 0+1=1.same thing is for combo2 also.after this the code will just concate the two resulted index values and put an asterix between them.
hope the above explanation is enough for you to understand the logic behind this coding.
regards
Shouvik
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
![]() |
Similar Threads
- trojans wont let me connect to internet (Viruses, Spyware and other Nasties)
- help with hjt and vx2/urllogic (Viruses, Spyware and other Nasties)
- help with hjt and vx2/urllogic (split from http://www.daniweb.com/techtalkforums/showthread.php?t=18540&page=1&pp=15) (Viruses, Spyware and other Nasties)
- 213.159.117.130 trojan.. help!! (Viruses, Spyware and other Nasties)
- Populating a fields on a form base on a selected item from a droplist. (PHP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: error "Unrecognized database format"
- Next Thread: Passing Variants from VB to VC++
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






