Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Help, ever so simple should take a pro. about 4-5 secs. to ans!

Status
Not open for further replies.

opSpy

Programmer
May 18, 2002
18
DE
I have a list of values, in a list box. and a total in a text box.

On clicking my remove item from the list, i want it to minus the item in the list from the text box..

please help...

Hugely Appreciated for anyone who does!! :) Create Like a God
Command Like a King
Work Like a Slave
 

Hi,

You could subtract the number from the textbox. However I would prefer something like:
---------------------------------------------------------
Private Sub Command1_Click()
Dim i As Integer, s As Single
GoAgian:
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
List1.RemoveItem (i)
GoTo GoAgian
End If
Next i
s = 0
For i = 0 To List1.ListCount - 1
s = s + CSng(List1.List(i))
Next i
Text1.Text = CStr(s)
End Sub
-----------------------------------------------------------

Which also supports multiple selections.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
AHH!

thanks but way too complicated..

I just need to know how to talk about: The value of the one that is selected in the list!!

HElp :-( Create Like a God
Command Like a King
Work Like a Slave
 
Hi,

If the .multiselect property is set to '0 - None', only one item in the list can be selected. There are 2 approaches:

1) use the .text property to return the text of the selected item. You can translate the text into a numeric value using e.g. csng(list1.text) (that is called a typecast).
If no items are selected list1.text is empty and csgn(list1.text) will be 0.
So if text1.text contains the sum,
text1.text = cstr(csng(text1.text) - csng(list1.text))
will subtract the value of the selected item in the list.

2) Loop through the list to find the selected items. This is basically the method showed above.

Hope that helps.

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Brilliant, both lots of help..

thx a lot people. Much Much Apprecited.. :) Create Like a God
Command Like a King
Work Like a Slave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top