Is it possible to get a value from a listbox in this manner
What im doing is liting all available features in the first box. Then when a feature would be added to a plan, get the value of it and have it displayed at the bottom when th command button calculate is pressed. Multiple features may be listed in the second list box so I would like for it to get the total of all of them.
so what you mean is when you click on the "calculate" button, the value form the 1st listbox should be added to the below listbox without deleting anything in the 2nd listbox... is that what you want?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
I already have got it to do that, I just didnt show it in the pic. Like in the first box, where it has Insurance - $4.99, after I highlight is and click add, it is added to the second listbox. What I would like for it to do, is when I click calculate, get the currency $4.99 (from the second listbox) and make it show up in the label I have next to total.
I would create a text file that loads on startup that might contain:
"Insurance", 4.99 (comma separated values)
and so on...
Read the file concatenating the two fields into the upper listbox. Place/copy the second field (4.99) into a variable (as single) so you can simply use the index to get the value without having to parse it from the listbox. When the user selects one then additem it to the bottom box checking first to see that it does not already exist. Then, if adding, automatically add the value to your featuretotal. The Calculate button is not really necessary since you will know whether the item is not in the lower box and so must be added to the total.
Having a separate text file makes it easy to add or change entries without having to recompile the program.
if you mean without the currency sign then use the format function...
Well its showing all the text in the label, instead of just the numeric value. Can you briefly explain the format button. Thx for sticking with me on this
Private Sub cmdaddfeature_Click()
listaddedfeatures.AddItem listfeatures.Text
End Sub
Private Sub cmdcalculate_Click()
For i = 0 To listfeatures.ListCount - 1
temp = listaddedfeatures.List(i) + temp
Next
lblfeaturetotal.Caption = temp
End Sub
Private Sub cmdremovefeature_Click()
On Error Resume Next
listaddedfeatures.RemoveItem listaddedfeatures.ListIndex
End Sub
Private Sub Form_Load()
listfeatures.AddItem "Insurance - $4.99"
listfeatures.AddItem "Test Feature - $99.99"
End Sub
________________________
In the label it shows
Insurance - $4.99
Test Feature - $99.99
I would like it to add the 4.99 and 99.99 together
That will work. Or even if the full text insurance - $4.99 is added to the second box, I only want the numbers added together and displayed in the lblfeaturetotal label when i press calculate.
Private Sub cmdcalculate_Click()
Dim ar() As String, temp As Long
For i = 0 To listfeatures.ListCount - 1
ar = Split(listaddedfeatures.List(i), "$")
temp = Val(ar(1)) + temp
'the above will fail if the listbox is empty
'can put an error check there
ReDim ar(1)
Next
lblfeaturetotal.Caption = temp
End Sub
Last edited by Siddharth Rout; Sep 9th, 2008 at 01:54 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Private Sub cmdcalculate_Click()
Dim ar() As String, temp As Long
For i = 0 To listfeatures.ListCount - 1
If Len(listaddedfeatures.List(i)) <> 0 Then
ar = Split(listaddedfeatures.List(i), "$")
temp = Val(ar(1)) + temp
ReDim ar(1)
End If
Next
lblfeaturetotal.Caption = Format(temp, "$#,##0.00")
End Sub
Last edited by Siddharth Rout; Sep 9th, 2008 at 02:03 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Ok, I really appreciate it. Now that I think about it I dont want to include the dollar sign since no other values on my main form have it. And why would their be blank values in the listbox if I didnt add them?
Great! One last thing. Is there anyway to make it not round up/down as it makes a difference in what im making it for? it lists 99.99 as 100 and 4.99 as 5.
Great! One last thing. Is there anyway to make it not round up/down as it makes a difference in what im making it for? it lists 99.99 as 100 and 4.99 as 5.
try this
lblfeaturetotal.Caption = Format(temp, "0.00")
Edit:
Please Mark your Thread "Resolved", if the query is solved...
check the link below on how to do it...
Last edited by Siddharth Rout; Sep 9th, 2008 at 02:30 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero