d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help With Basic Array And Input Functions > Fairly New To Vb
Add Reply New Topic New Poll
Member
Posts: 3,379
Joined: Sep 2 2006
Gold: 15,870.70
Jun 14 2012 09:44pm
I am new to using VB2010 (and coding in general). Okay so I am making a program that:
allows the user enter the number of customers served for each of 12 months into an array. The application should calculate and
display the following statistics: total number of customers for the year, the average monthly number of customers, and the months with
the highest and lowest numbers of customers. Use inputBox to get user input. Do not accept non-numeric or negative numbers.


The problem that I am having is that I do not know how to display which was the best and worst month. I imagine I need something that targets the
highest/lowest number and finds the text in the corresponding index but I'm not sure how to do this.

Here is a link to pastebin with my code so far. http://pastebin.com/b5qe5jkK
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 14 2012 09:50pm
so you're asking for the algorithm to find the max/min value?

1. grab the first item. call it lowestValue. assume this is min
2. go through entire array. if there is a lower value, set lowestValue to be this
3. when you finish the array, lowestValue has the lowest value
Member
Posts: 3,379
Joined: Sep 2 2006
Gold: 15,870.70
Jun 14 2012 09:53pm
Quote (carteblanche @ Jun 14 2012 11:50pm)
so you're asking for the algorithm to find the max/min value?

1. grab the first item. call it lowestValue. assume this is min
2. go through entire array. if there is a lower value, set lowestValue to be this
3. when you finish the array, lowestValue has the lowest value


Yes, but I need to display the month that corresponds with said value.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 14 2012 09:57pm
i recommend creating a class with three properties: month (string), #customers (int), and display (month concat with #)
when user enters data, create an object with the appropriate month and #
add this object to the listbox.Items collection
set the listbox's display property to display
set the listbox's value property to #customers

to find the min, iterate over listbox.Items collection and compare the objects via the #. you will get the object for the min and the object for the max. to display the month, simply call the object's month property
Member
Posts: 3,379
Joined: Sep 2 2006
Gold: 15,870.70
Jun 14 2012 10:01pm
Quote (carteblanche @ Jun 14 2012 11:57pm)
i recommend creating a class with three properties: month (string), #customers (int), and display (month concat with #)
when user enters data, create an object with the appropriate month and #
add this object to the listbox.Items collection
set the listbox's display property to display
set the listbox's value property to #customers

to find the min, iterate over listbox.Items collection and compare the objects via the #. you will get the object for the min and the object for the max. to display the month, simply call the object's month property


I really have no idea how to go about doing this.
Member
Posts: 13,766
Joined: Jan 10 2005
Gold: 30,758.00
Jul 15 2012 12:07pm

Quote (Road2Death @ Jun 15 2012 05:01am)
I really have no idea how to go about doing this.


no need to use classes, here is solution (I think):
http://pastebin.com/EuSDqWWF
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll