Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Array Problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Resolved [RESOLVED] [2005] Array Problem

    Hi,
    I have the following definition

    Code:
    Dim nMembers As Int32()
    
    ReDim nMembers(6)
    nMembers(1) = oStd.Geometry.AddBeam(nNodes(1), nNodes(2))
    nMembers(2) = oStd.Geometry.AddBeam(nNodes(2), nNodes(3))
    nMembers(3) = oStd.Geometry.AddBeam(nNodes(3), nNodes(4))
    
    nMembers(4) = oStd.Geometry.AddBeam(nNodes(4), nNodes(5))
    nMembers(5) = oStd.Geometry.AddBeam(nNodes(5), nNodes(6))
    nMembers(6) = oStd.Geometry.AddBeam(nNodes(6), nNodes(7))
    
    Dim omembList As Object
    omembList = nMembers
    
    oStd.Design.AssignDesignParameter(refBrief, "FYLD", "345000", omembList)
    The Code

    Code:
    oStd.Design.AssignDesignParameter(refBrief, "FYLD", "345000", omembList)
    gives me the following output

    FYLD 345000 MEMB 0 TO 6
    Where as desired output is

    FYLD 345000 MEMB 1 TO 6
    it should be MEMB 1 to 6 instead of MEMB 0 to 6

    Will be thankful for any feedback
    Last edited by surya; May 10th, 2007 at 02:22 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Array Problem

    .NET arrays are zero-based. By doing this:
    vb Code:
    1. ReDim nMembers(6)
    You are creating an array with 7 elements at indexes 0 to 6. If you want an array with 6 elements then you would have to do this:
    vb Code:
    1. ReDim nMembers(5)
    and set the elements at indexes 0 to 5. You would, of course, have to allow for the offset when creating your output.

    If the fact that you need to specify the upper bound rather than the length when creating an array confuses you then I suggest that you make a habit of creating arrays using the length - 1, e.g.
    vb Code:
    1. ReDim nMembers(6 - 1)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Array Problem

    Hello jmcilhinney,

    Many thanks for your prompt response.
    Is there a way to set the index of an array to start with 1 instead of 0.

    thanks

  4. #4
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] Array Problem

    Is there a way to set the index of an array to start with 1 instead of 0.
    I think that it is not good, If you want to avoid the zero position then simple do not use it and put a blank value there.
    But it is not good programming.
    Last edited by shakti5385; May 10th, 2007 at 03:03 AM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Array Problem

    Hello Shakti,
    You are probably right!

    I remember setting the index to 1 in VB6.0, just wondering if there is some way of achieving the same in VB.Net

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Array Problem

    There is one way but I wouldn't recommend it because you end up with an Array object rather than a typed array:
    vb Code:
    1. Dim arr As Array = Array.CreateInstance(GetType(Integer), _
    2.                                         New Integer() {6}, _
    3.                                         New Integer() {1})
    Unless you're unable to change the implementation of this AssignDesignParameter method then I suggest that you code "properly" and use zero-based arrays and account for the fact whenever using indexes.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Array Problem

    I will change my code to 0 index and revert back shortly..

    thanks again...

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Array Problem

    Ok, Was able to set the index to 0 and recode.
    Many for your valuable inputs...

Posting Permissions

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



Click Here to Expand Forum to Full Width