Results 1 to 5 of 5

Thread: How to modify a table in a sub

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    21

    How to modify a table in a sub

    Hi

    I am trying to sort a table of doubles in a sub which I can call from anywhere in my program. That's what I am doing now:
    _____________
    Main program (for example)

    for i = 1 to 10
    array(i) = rnd
    next i

    Sort array()
    ____________

    Private Sub Sort(table() as double)

    .... procedure to sort a table...
    ___________

    when I look closer, in the sub Sort, the elements in table() are all equal to 0 instead of the elements in array().

    What is wrong ?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,794

    Re: How to modify a table in a sub

    Why do you call an array a table ?
    those are 2 diferent things...

    Anyways... are you sure you declared the array properly ?
    Like:
    VB Code:
    1. Dim Array(10) As Double

    Also... arrays start at index 0, not 1

  3. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: How to modify a table in a sub

    Also... arrays start at index 0, not 1
    Not if you declare them to start at 1....
    VB Code:
    1. Dim Array(1 To 10) As Double
    The problem may also be in the Sort procedure. Can you post that code?
    Alternatively, here's a genric sort routine.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,794

    Re: How to modify a table in a sub

    Quote Originally Posted by DKenny
    Not if you declare them to start at 1....
    VB Code:
    1. Dim Array(1 To 10) As Double
    I know that much,
    It is not recommended to dim the array like this Array(1 To 10) because it's slower.

    I just did not want to complicate things since he seems to be new with VB

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: How to modify a table in a sub

    I agree its slower, but I also think its safer for beginners.
    Anyway, I still think the issue is probably in his sort procedure.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

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