|
-
Mar 27th, 2007, 02:30 PM
#1
Thread Starter
Addicted Member
[RESOLVED] add item to combo box and related price
Hi again guys.
I've been developing an application for a friend just for fun and practice(I'm just beginning as you can tell right away) and I have a combobox for the services.
I've made a select case procedure to make the price of each initial service shows on a label each time the user clicks a selection. So okay, everything works fine.
What I want to accomplish though is to make the user be able to add a service(I know this part) and a price for such a service.
Is there a method to make the price show on the label or do I have to make a database for them? (No clue about databases, yet!)
Sorry if it looks like a silly question.
Last edited by pukisoft; Mar 27th, 2007 at 04:23 PM.
-
Mar 27th, 2007, 04:13 PM
#2
Re: add item to combo box and related price
You can use the Itemdata property of thre combo to store the price.
vb Code:
Combo1.AddItem "A Service"
Combo1.ItemData(Combo1.NewIndex) = "1.98"
Combo1.AddItem "Another Service"
Combo1.ItemData(Combo1.NewIndex) = "5.67"
-
Mar 27th, 2007, 04:21 PM
#3
Thread Starter
Addicted Member
Re: add item to combo box and related price
And to display it on the label during run time? I mean, Each time the user clicks a new service on the combo box the label has to display the price.
-
Mar 27th, 2007, 04:26 PM
#4
Thread Starter
Addicted Member
Re: add item to combo box and related price
So I did that
Code:
Private Sub Command1_Click()
Combo1.AddItem "A new service"
Combo1.ItemData(0) = "1.98"
Label3 = Combo1.ItemData(0)
End Sub
but in the label it only shows a rounded number. :S
-
Mar 27th, 2007, 04:40 PM
#5
Hyperactive Member
Re: add item to combo box and related price
 Originally Posted by pukisoft
but in the label it only shows a rounded number. :S
What do you mean a rounded number? As i 1.98 becomes 2 or does it chop off the decimal?
If so, you could do this with the code above:
Code:
Private Sub Command1_Click()
Combo1.AddItem "A new service"
Combo1.ItemData(0) = "1.98"
Label3.Caption = FormatCurrency(Combo1.ItemData(0),2)
End Sub
-
Mar 27th, 2007, 05:58 PM
#6
Re: add item to combo box and related price
The ItemData property can only store Integers. One option is to multiply the value by 100 when it is stored and obviously divide by 100 when the value is retrieved.
Code:
Option Explicit
Private Sub Form_Load()
Dim sngValue As Single
sngValue = 1.98
Combo1.AddItem "A new service"
Combo1.ItemData(0) = sngValue * 100
Combo1.ListIndex = 0
End Sub
Private Sub Combo1_Click()
Label1.Caption = FormatCurrency(Combo1.ItemData(0) / 100, 2)
End Sub
-
Mar 27th, 2007, 05:59 PM
#7
Re: add item to combo box and related price
Sorry my mistake. ItemData is stored as a Long Integer so it will convert the strings that I added to whole numbers. Do this instead.
vb Code:
Dim strPrice() As Currency
ReDim strPrice(0)
Combo1.AddItem "A Service"
strPrice(0) = 1.98
Combo1.AddItem "Another Service"
ReDim Preserve strPrice(UBound(strPrice) + 1)
strPrice(UBound(strPrice)) = 5.67
Label1.Caption = strPrice(0)
-
Mar 27th, 2007, 06:00 PM
#8
Re: add item to combo box and related price
 Originally Posted by brucevde
The ItemData property can only store Integers. One option is to multiply the value by 100 when it is stored and obviously divide by 100 when the value is retrieved.
Code:
Option Explicit
Private Sub Form_Load()
Dim sngValue As Single
sngValue = 1.98
Combo1.AddItem "A new service"
Combo1.ItemData(0) = sngValue * 100
Combo1.ListIndex = 0
End Sub
Private Sub Combo1_Click()
Label1.Caption = FormatCurrency(Combo1.ItemData(0) / 100, 2)
End Sub
Nice idea.
-
Mar 28th, 2007, 09:48 AM
#9
Thread Starter
Addicted Member
Re: [RESOLVED] add item to combo box and related price
Thnkx guys. now I have two ways of solving it.
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
|