Results 1 to 6 of 6

Thread: Problem passing arrays from a basic module to a sub in a form

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2010
    Location
    North St Paul, Minnesota
    Posts
    38

    Problem passing arrays from a basic module to a sub in a form

    I am trying to pass two arrays from a sub in a VB6 basic module to a sub in the code section of a form that contains an MSChart control. Each array repesents a line and contains two columns for the X and Y points.

    In the code section of the form that is to receive the arrays, I tried something like this:

    Code:
    Sub MakeDRchart(ChartPointsAc(), ChartPointsRe())
        Dim NfixedK as Long
        NFixedK = ubound(ChartPointsAc,1)
        For J = i To NfixedK 
            Debug.Print J, ChartPointsAc(J,1)
        Next
    End Sub
    In the basic module where the arrays are created and sent from, I tried something like this:

    Code:
    Dim ChartPointsAc() As Double
      Dim ChartPointsRe() As Double
      ReDim ChartPointsAc(1 To nfixedk)
      ReDim ChartPointsRe(1 To nfixedk)
      Call MakeDRchart(ChartPointsAc(), ChartPointsRe())
    How can I make this work?

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,156

    Re: Problem passing arrays from a basic module to a sub in a form

    Try changing this

    Sub MakeDRchart(ChartPointsAc(), ChartPointsRe())

    to this

    Sub MakeDRchart(ChartPointsAc() As Double, ChartPointsRe() As Double)

    cheers,
    </wqw>

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2010
    Location
    North St Paul, Minnesota
    Posts
    38

    Re: Problem passing arrays from a basic module to a sub in a form

    Quote Originally Posted by wqweto View Post
    Try chaning this

    Sub MakeDRchart(ChartPointsAc(), ChartPointsRe())

    to this

    Sub MakeDRchart(ChartPointsAc() As Double, ChartPointsRe() As Double)

    cheers,
    </wqw>

    Thanks, I did that. Now I receive an error at:
    Code:
    Call MakeDRchart(ChartPointsAc(), ChartPointsRe())
    This is the error:
    Code:
    CompileError: 
    Type mismatch: array or user-defined type expected

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,156

    Re: Problem passing arrays from a basic module to a sub in a form

    Try Call MakeDRchart(ChartPointsAc, ChartPointsRe) with no extra parens after the arguments.

    Where did you get this syntax from? How did you come up with so many parentheses?

    cheers,
    </wqw>

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2010
    Location
    North St Paul, Minnesota
    Posts
    38

    Re: Problem passing arrays from a basic module to a sub in a form

    Quote Originally Posted by wqweto View Post
    Try Call MakeDRchart(ChartPointsAc, ChartPointsRe) with no extra parens after the arguments.

    Thanks. This is what is working as far.
    Code:
        Dim ChartPointsAc() As Double
        Dim ChartPointsRe() As Double
        ReDim ChartPointsAc(1 To 2, 1 To 2)
        ReDim ChartPointsRe(1 To 2, 1 To 2)
             ChartPointsAc(1, 1) = 1
             ChartPointsAc(2, 1) = 2
             ChartPointsAc(1, 2) = 3
             ChartPointsAc(2, 2) = 4
        Call MakeDRchart(ChartPointsAc, ChartPointsRe)

    Code:
    Sub MakeDRchart(ChartPointsAc() As Double, ChartPointsRe() As Double)
        Dim J As Integer
        Dim K As Integer
        K = UBound(ChartPointsAc, 1)
        For J = 1 To K
            Debug.Print J, ChartPointsAc(J, 1)
            Debug.Print J, ChartPointsAc(J, 2)
        Next
    End Sub
    Where did you get this syntax from? How did you come up with so many parentheses?

    cheers,
    </wqw>
    I don't know. Maybe I saw it on social media.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Problem passing arrays from a basic module to a sub in a form

    Name:  Copy Paste Cowboy.png
Views: 121
Size:  2.3 KB

    Yeeeee hah!

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