11 Replies - 331 Views - Last Post: 14 May 2014 - 03:06 AM Rate Topic: -----

#1 inumike  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-May 14

Listbox and averages,

Posted 13 May 2014 - 12:57 PM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Listbox and averages,

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8959
  • View blog
  • Posts: 33,585
  • Joined: 12-June 08

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'.
Was This Post Helpful? 0
  • +
  • -

#3 inumike  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-May 14

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)
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8959
  • View blog
  • Posts: 33,585
  • Joined: 12-June 08

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.
Was This Post Helpful? 0
  • +
  • -

#5 inumike  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-May 14

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.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8959
  • View blog
  • Posts: 33,585
  • Joined: 12-June 08

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?
Was This Post Helpful? 0
  • +
  • -

#7 inumike  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-May 14

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
Was This Post Helpful? 0
  • +
  • -

#8 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

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.
Was This Post Helpful? 0
  • +
  • -

#9 inumike  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-May 14

Re: Listbox and averages,

Posted 13 May 2014 - 04:50 PM

Vb.net
Was This Post Helpful? 0
  • +
  • -

#10 Oppemaj  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 73
  • Joined: 15-November 13

Re: Listbox and averages,

Posted 13 May 2014 - 06:06 PM

View Postinumike, 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.
Was This Post Helpful? 0
  • +
  • -

#11 inumike  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-May 14

Re: Listbox and averages,

Posted 13 May 2014 - 06:13 PM

View PostOppemaj, on 13 May 2014 - 06:06 PM, said:

View Postinumike, 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.

Was This Post Helpful? 0
  • +
  • -

#12 Oppemaj  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 73
  • Joined: 15-November 13

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1