CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2000
    Location
    Bangalore,India
    Posts
    776

    passing array of double to a function by reference

    Hi all
    i need some help from VB programers. My requirement is how can i pass an array of double to a function by reference. please give the function defination syntax and function calling syntax with an array example.

    All suggestions/answers will be rated.
    regards
    santanu

    Be sure to rate answers if it helped, to encourage them.

  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: passing array of double to a function by reference

    This code will pass an array X to funtion FillArray, and the function will fill it with values. After that, the value are printed to the debug window just to show the code is actually working.

    private Sub Command1_Click()

    ' create an array with 10 elements
    Dim X() as Long
    ReDim X(10)

    ' call the function
    FillArray X

    ' show content of array in debug window
    Dim T as Integer
    for T = 0 to 9
    Debug.print T & ": " & X(T)
    next T

    End Sub

    private Function FillArray(ArrToFill() as Long)

    ' fill the array
    Dim T as Integer
    for T = 0 to 9
    ArrToFill(T) = T * 1000
    next T

    End Function




    Tom Cannaerts
    [email protected]
    Moderator on http://www.vbcodelibrary.co.uk/board

    A bottomless pit, I'm sure it came with the place, who would dig one on purpose?
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Mar 2000
    Location
    Bangalore,India
    Posts
    776

    Re: passing array of double to a function by reference

    Hi Tom
    thanx a lot for ur quick answre, it helped me a lot to understand Vb calling . here is my actual problem. hope u can help me to solve this problem. I m a VC programmer and just new to VB.

    I have created a standard dll in in C. one of the function exported from the DLL is having a FUNCTION PROTOTYPE LIKE THIS:
    int GetData(int xIN, double dataArray[]);

    i m trying to write some sample code to call this function from dll from CV, Vb etc. From VC i could succed, but struggling a lot to make it work from VB, just very new to VB. here is what i m doing from VB:
    i have declared the function prototype in VB like this:
    Declare Function GetData& Lib "mylib.dll" (ByVal x1&,x7#)

    is it correct???

    while calling i m calling as :
    Dim dataAry(100) as double
    dim status as integer

    status = GetData(0, wfmAry)

    i m getting the compilation error: ByRef argument type mismatch.

    thanx in advance, its bit urgent.....

    Regards
    skpradhan


    Be sure to rate answers if it helped, to encourage them.

  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: passing array of double to a function by reference

    I'm not sure about the declareation of the function, because I have absolutely no experiance with that. What I do know is that in many cases (not all) when passing an array to a (API) function, those declared using Declare ... Lib ..., you must pass the first element of the array. So it would look someting like status = GetData(0, wfmAry(0)).

    As said before, not really into this stuff, so could be wrong

    Tom Cannaerts
    [email protected]
    Moderator on http://www.vbcodelibrary.co.uk/board

    A bottomless pit, I'm sure it came with the place, who would dig one on purpose?
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured