For this assignment you are required to create a single program. This program will feature arrays and modules.
Using a ListBox, accept from the user a series of numbers of type Decimal. The application should feature a button which then calculates the following:
•count of items in the array;
•mean;
The results of the calculations should be displayed in text boxes next to the ListBox. The user should not be able to edit the content of the text boxes.
The calculations above should be performed by functions in a module called ArrayStatistics. Each of these values should be calculated in a separate function. For example, you will have a function called “calculateMean”, which will calculate the mean of the values stored in the array. This function would accept the array as argument and return the mean as a Double.
I have everything worked out except doing the functions in the module how to I retrieve users input from the listbox....I;m completely lost as to how to get the info from the listbox over to the module also user can input as many numbers as they want too
Listbox and averages,
Page 1 of 111 Replies - 948 Views - Last Post: 14 May 2014 - 03:06 AM
Replies To: Listbox and averages,
#2
Re: Listbox and averages,
Posted 13 May 2014 - 01:02 PM
Quote
how to I retrieve users input from the listbox
Listboxes tend to have collections called 'items'. I would suggest looking at iterating over that collection or checking the 'selected items'.
#3
Re: Listbox and averages,
Posted 13 May 2014 - 01:10 PM
but the user inputs the data so they really wouldn't select it
input = InputBox("Type in Number", "Input required", "0")
ListBox_Numbers.Items.Add(input)
input = InputBox("Type in Number", "Input required", "0")
ListBox_Numbers.Items.Add(input)
#4
Re: Listbox and averages,
Posted 13 May 2014 - 01:14 PM
okay.. then re-read the first part about the collection called 'items' that is of all the items in the listbox.
http://msdn.microsof...=vs.110%29.aspx
Use that with a for loop.
THough, typically, a listbox isn't used in this fashion. A listbox is about selection choices.. if you are just inputting images and spewing that information then something like a 'grid' (with one column) would be a more logical choice.
http://msdn.microsof...=vs.110%29.aspx
Use that with a for loop.
THough, typically, a listbox isn't used in this fashion. A listbox is about selection choices.. if you are just inputting images and spewing that information then something like a 'grid' (with one column) would be a more logical choice.
#5
Re: Listbox and averages,
Posted 13 May 2014 - 02:52 PM
So now my listbox won't appear at all in my module. is there something I'm doing wrong and I still can't figure out how to average the users input to the listbox, Ive gotten it to count the numbers but not add them up and divided by the count.
#6
Re: Listbox and averages,
Posted 13 May 2014 - 02:56 PM
Quote
Ive gotten it to count the numbers but not add them up and divided by the count.
Again, use a for loop. Go to each value in the collection and add to a temp variable.
Quote
So now my listbox won't appear at all in my module. is there something I'm doing wrong
I have no idea what you are doing.. perhaps show us your code?
#7
Re: Listbox and averages,
Posted 13 May 2014 - 02:59 PM
Module ArrayStatistics
Dim i As Integer
Dim listcount As Integer
private Function calculatemean(ByVal numbers As Double()) As Double)
Dim Mean As Double = 0
Dim item As Integer
For item = 0 To ListNumbers.listcount - 1
Next
' listcount = ListBox_numbers(_number
End Function
Dim i As Integer
Dim listcount As Integer
private Function calculatemean(ByVal numbers As Double()) As Double)
Dim Mean As Double = 0
Dim item As Integer
For item = 0 To ListNumbers.listcount - 1
Next
' listcount = ListBox_numbers(_number
End Function
#8
Re: Listbox and averages,
Posted 13 May 2014 - 04:42 PM
Is this for VB6 or VB.Net?
ListCount is not a method of a VB.Net ListBox.
ListCount is not a method of a VB.Net ListBox.
#10
Re: Listbox and averages,
Posted 13 May 2014 - 06:06 PM
inumike, on 13 May 2014 - 04:50 PM, said:
Vb.net
Ok, I'll give you a little help.
Let's say we have a listbox that is populated with numbers from 1 through 10 and we want to sum those numbers.
CharlieMay advised you to use a loop with for each:
For each digit As Integer in ListBox1.items total = total + digit Next
how many numbers are there in lisbox1?
To answer that, use listbox1.items.count-1
Now you have total and mean.
An advice: you don't know how to use "For each", then go to MSDN. There you'll find explanations along with examples.
Good luck.
#11
Re: Listbox and averages,
Posted 13 May 2014 - 06:13 PM
Oppemaj, on 13 May 2014 - 06:06 PM, said:
inumike, on 13 May 2014 - 04:50 PM, said:
Vb.net
Ok, I'll give you a little help.
Let's say we have a listbox that is populated with numbers from 1 through 10 and we want to sum those numbers.
CharlieMay advised you to use a loop with for each:
For each digit As Integer in ListBox1.items total = total + digit Next
how many numbers are there in lisbox1?
To answer that, use listbox1.items.count-1
Now you have total and mean.
the user can enter how many number he or she wants so there is no limit
but thanks i'll try that out
An advice: you don't know how to use "For each", then go to MSDN. There you'll find explanations along with examples.
Good luck.
#12
Re: Listbox and averages,
Posted 14 May 2014 - 03:06 AM
"the user can enter how many number he or she wants so there is no limit
but thanks i'll try that out "
Whatever the number of items entered in listbox, listbox.items.count -1 will count them until the last one.
but thanks i'll try that out "
Whatever the number of items entered in listbox, listbox.items.count -1 will count them until the last one.
Page 1 of 1