Consulting

Results 1 to 9 of 9

Thread: Dimension x number of arrays based on user input

  1. #1

    Dimension x number of arrays based on user input

    I am writing a code that needs an array for each Element of the problem to be solved. The number of elements will be put by the user.

    I need VBA to define a new array for each element from 1 to the number of elements. I am trying something like this:

    [VBA]

    Sub Assemble()

    Dim i As Integer, j As Integer
    Dim nElements As Integer, nNodes As Integer

    For i = 1 To 3
    Dim Ki(5) As Double
    Next i

    End Sub


    [/VBA]

    I would like this to define 3 arrays named K1, K2, K3 each of which has an Ubound of 5.

    Excel is just defining 1 array called Ki 3 times when I use the above.

    How can I do this right?

    Thanks!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub Assemble()
    Dim K, tmp
    Dim i As Integer, j As Integer
    Dim nElements As Integer, nNodes As Integer

    ReDim K(1 To 3)
    ReDim tmp(1 To 5)
    For i = 1 To 3
    K(i) = tmp
    Next i

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    [vba]

    Sub Assemble()
    Dim K, tmp
    Dim i As Integer, j As Integer
    Dim nElements As Integer, nNodes As Integer

    ReDim K(1 To 3)
    ReDim tmp(1 To 5)
    For i = 1 To 3
    K(i) = tmp
    Next i

    End Sub
    [/vba]
    So what exactly does this do xld? Is it an array full of arrays? Nasty!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yes it is, and it is elegant not nasty.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Quote Originally Posted by xld
    Yes it is, and it is elegant not nasty.
    Yes of course. I meant nasty in the most elegant way. Like when the kids say "damn that Benz was nasty."

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I know what you meant I was just playing back.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Why not a doulbe dimension array?
    reDim K(1 to 3,1 to number entered in textbox)?
    K(1)(2) is not as easy (IMHO) as K(1,2)

    just thinking with my fingers

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Tommy
    Why not a doulbe dimension array?
    reDim K(1 to 3,1 to number entered in textbox)?
    You can't have different sized arrays then, everything is the same.

    Quote Originally Posted by Tommy
    K(1)(2) is not as easy (IMHO) as K(1,2)

    just thinking with my fingers
    You are obviously not a JavaScript man
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I had to work with ex K()()(,)() somehow or other they were filling it with reg expressions and I just got a bad taste in my mouth I guess.

    JavaScript I haven't taken the time to figure out VBScript!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •