Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2007
Posts: 9
Reputation: louislam123 is an unknown quantity at this point 
Solved Threads: 0
louislam123 louislam123 is offline Offline
Newbie Poster

DropList Help?

 
0
  #1
Oct 2nd, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 50
Reputation: Prozeen is an unknown quantity at this point 
Solved Threads: 4
Prozeen's Avatar
Prozeen Prozeen is offline Offline
Junior Poster in Training

Re: DropList Help?

 
0
  #2
Oct 2nd, 2007
Do you mean the listindex property (for a listbox)?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim a As Integer
  2. Dim b As Integer
  3.  
  4. Private Sub Command1_Click()
  5. If List1.ListIndex = -1 Then
  6. MsgBox "nothing selected"
  7. ElseIf List1.ListIndex = 0 Then
  8. a = List1.ListIndex + 1
  9. MsgBox "The value is " & a
  10. a = 0
  11. b = 0
  12. Exit Sub
  13. ElseIf List1.ListIndex = 1 Then
  14. b = List1.ListIndex + 1
  15. MsgBox "The value is " & b
  16. a = 0
  17. b = 0
  18. Exit Sub
  19. End If
  20. End Sub
  21.  
  22. Private Sub Form_Load()
  23. List1.AddItem "Cat"
  24. List1.AddItem "Dog"
  25. End Sub
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,122
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 129
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: DropList Help?

 
0
  #3
Oct 2nd, 2007
Try to use the Listindex of the item

else

try to use ItemData property of the control.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 9
Reputation: louislam123 is an unknown quantity at this point 
Solved Threads: 0
louislam123 louislam123 is offline Offline
Newbie Poster

Re: DropList Help?

 
0
  #4
Oct 2nd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,122
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 129
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: DropList Help?

 
0
  #5
Oct 3rd, 2007
The code is already provided to you.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 50
Reputation: Prozeen is an unknown quantity at this point 
Solved Threads: 4
Prozeen's Avatar
Prozeen Prozeen is offline Offline
Junior Poster in Training

Re: DropList Help?

 
0
  #6
Oct 3rd, 2007
Maybe try this? Amazing things you can do with the Listbox control Or, check out the zip file. Good luck.
Attached Files
File Type: zip Project Listbox.zip (5.5 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: DropList Help?

 
0
  #7
Oct 3rd, 2007
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
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 9
Reputation: louislam123 is an unknown quantity at this point 
Solved Threads: 0
louislam123 louislam123 is offline Offline
Newbie Poster

Re: DropList Help?

 
0
  #8
Oct 3rd, 2007
can you further explain how the code works? What does each part mean? That would be really helpful.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,122
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 129
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: DropList Help?

 
0
  #9
Oct 3rd, 2007
Now its really too much. The code is so simple ,very basic level . How do u expect all the spoon feeding after being provided with alll the sample code on a free forum like this.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: DropList Help?

 
0
  #10
Oct 4th, 2007
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
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC