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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculate the total number in the microsoft foxpro listbox

Status
Not open for further replies.

icecr3amc4k3

Programmer
Apr 25, 2023
7
ID
if i have a list box and the listbox items value is 1,2,3,4,and 5 how to add up all the numbers (items) listbox to get 15(in the text. value)
 
This is quite easy. A Listbox has a property called List, which is an array containing the actual items in the Listbox. So you can loop through it, just as you would with any other array:

Code:
lnTotal = 0
lnCount = THISFORM.MyListBox.ListCount()
FOR lnI = 1 TO lnCount
  lnTotal = lnTotal + VAL(THISFORM.MyListBox.List(lnI))
ENDFOR

THISFORM.MyTextBox.Value = lnTotal

Note the user of th VAL() function. This is needed because the contents of a Listbox is always a character string, even if it represents numbers.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I'd suggest you look at the help chapters about the Listbox properties List and ListCount and figure it out yourself. You never learn if you just let others do your tasks.


Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top