Load array with NumericUpDown values

brianmac

Member
Joined
Jul 21, 2011
Messages
7
Programming Experience
Beginner
I have a form with 84 NumericUpDown controls. How can I load each value into an array. E.G. Aryhours(1) = NumericUpDown1, AryHours(2) = NumericUpDown2.....

thanks for any help!
Brian
 
you can get the items from the forms control collection and add it to an collection/array/list/etc...

here's a quick example

    Private numbers As New List(Of Decimal)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each item As Control In Me.Controls
            If TypeOf item Is NumericUpDown Then
                Dim numGet As NumericUpDown = DirectCast(item, NumericUpDown)
                numbers.Add(numGet.Value)
            End If
        Next
    End Sub
 
Dim numbers = Me.Controls.OfType(Of NumericUpDown)().Select(Function(nud) nud.Value).ToArray()
 
Thanks for the replies! I did it the hard way, but am going to try your solutions...
Did this in a Loop;

Arrhours(x) = (Me.Controls.Item("NumericUpDown" & x + 1)).Text
Thank again,
Brian
 
Back
Top