14 Replies - 2111 Views - Last Post: 27 April 2011 - 09:50 PM Rate Topic: -----

#1 Prophet of Code  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-April 11

Adding NumericUpDown Control Data to An Array

Posted 25 April 2011 - 06:01 PM

What syntax do you use to add decimal data held in a NumericUpDown control, and add it to a one dimensional array?
Is there a keyword to sum all the items in the array into one number(For averaging purposes)?

Dim heightarray As String()

        ReDim Preserve heightarray(0 To UBound(heightarray) + 1)
        heightarray(UBound(heightarray)) = heightNumericUpDown.Value


Is This A Good Question/Topic? 0
  • +

Replies To: Adding NumericUpDown Control Data to An Array

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: Adding NumericUpDown Control Data to An Array

Posted 25 April 2011 - 06:06 PM

Using a List(Of T) will expose some great extension functions for you:
Dim heightList As New List(Of Double)

heightList.Add(heightNumericUpDown.Value)

heightList.Sum
heightList.Average
heightList.Min
heightList.Max

This post has been edited by hawkvalley1: 25 April 2011 - 06:08 PM

Was This Post Helpful? 1
  • +
  • -

#3 Prophet of Code  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-April 11

Re: Adding NumericUpDown Control Data to An Array

Posted 25 April 2011 - 08:43 PM

Interesting! So this List(of T) is a type of array then?
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: Adding NumericUpDown Control Data to An Array

Posted 25 April 2011 - 09:09 PM

A type specific collection, but you can think of it as an array. It has more functionality though.
Was This Post Helpful? 0
  • +
  • -

#5 Prophet of Code  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-April 11

Re: Adding NumericUpDown Control Data to An Array

Posted 26 April 2011 - 08:08 AM

Well that is extremely helpful on a personal level! But this is for a class and the book isn't covering arrays the way id like it too. I tried a few sites for breakdowns but most of them just confused me. For this particular problem i NEED to use a one dimensional array. My main issue is Understanding the syntax.

What goes in the parenthesis? The number of arrays you intend to have? OR Is this the ID to access particular data in the initializer list?

What is a Initializer list? How can i add new elements from a Numeric Up Down?
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: Adding NumericUpDown Control Data to An Array

Posted 26 April 2011 - 08:45 AM

Class level variables:
Private size_of_array As Integer = 0
Private heightarray As String() = {}

The code to add a new value:
'add new value - in a sub routine
Redim Preserve heightarray(size_of_array)
heightarray(size_of_array) = heightNumericUpDown.Value.ToString
size_of_array += 1

Was This Post Helpful? 1
  • +
  • -

#7 Prophet of Code  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-April 11

Re: Adding NumericUpDown Control Data to An Array

Posted 26 April 2011 - 09:05 AM

View Posthawkvalley1, on 26 April 2011 - 08:45 AM, said:

Class level variables:
Private size_of_array As Integer = 0
Private heightarray As String() = {}

The code to add a new value:
'add new value - in a sub routine
Redim Preserve heightarray(size_of_array)
heightarray(size_of_array) = heightNumericUpDown.Value.ToString
size_of_array += 1


So i dont have to mess with the initializer list unless i wanna set predefined variables?
Was This Post Helpful? 0
  • +
  • -

#8 Prophet of Code  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-April 11

Re: Adding NumericUpDown Control Data to An Array

Posted 26 April 2011 - 09:26 AM

Oh so you assign arrays the same way i assign all other variables. What about summing the data inside of an array?
Was This Post Helpful? 0
  • +
  • -

#9 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: Adding NumericUpDown Control Data to An Array

Posted 26 April 2011 - 10:07 AM

For that you need a loop from 0 to the array.count -1 and convert the string to integer or double while adding them to a variable that will hold the total.
Was This Post Helpful? 0
  • +
  • -

#10 demausdauth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 638
  • Joined: 03-February 10

Re: Adding NumericUpDown Control Data to An Array

Posted 26 April 2011 - 11:03 AM

Thinking of a list, you were. :)
 
array.length -1 


Was This Post Helpful? 1
  • +
  • -

#11 Prophet of Code  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-April 11

Re: Adding NumericUpDown Control Data to An Array

Posted 26 April 2011 - 05:22 PM

Once i got this all to work i understand how these work alot better now.
Was This Post Helpful? 0
  • +
  • -

#12 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: Adding NumericUpDown Control Data to An Array

Posted 26 April 2011 - 06:37 PM

I see - so none of my posts were helpful :sad2:
Was This Post Helpful? 3
  • +
  • -

#13 Elda  Icon User is offline

  • D.I.C Regular

Reputation: 31
  • View blog
  • Posts: 314
  • Joined: 30-December 10

Re: Adding NumericUpDown Control Data to An Array

Posted 26 April 2011 - 09:53 PM

View Posthawkvalley1, on 27 April 2011 - 09:37 AM, said:

I see - so none of my posts were helpful :sad2:


You're helpful enough hawk... :)

This post has been edited by Elda: 27 April 2011 - 01:24 AM

Was This Post Helpful? 2
  • +
  • -

#14 Prophet of Code  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-April 11

Re: Adding NumericUpDown Control Data to An Array

Posted 27 April 2011 - 12:21 PM

Yes very helpful :D sorry forgot to hit the helpful button -.-
Was This Post Helpful? 0
  • +
  • -

#15 Elda  Icon User is offline

  • D.I.C Regular

Reputation: 31
  • View blog
  • Posts: 314
  • Joined: 30-December 10

Re: Adding NumericUpDown Control Data to An Array

Posted 27 April 2011 - 09:50 PM

Always give credit to those who helped your prob.... :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1