umanaged code - array error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick Sullivan

    #1

    umanaged code - array error

    dim s_err as stringbuilder
    dim xx(6) as double
    dim ret_flag as integer

    ' This is a function to call an unmanaged C-style library function.
    ' The lib function fills an array of 6 doubles or error string.

    Declare Auto Function calc Lib "calc32.dll " Alias "calc32.dll "( ByRef xx()
    As Double, ByVal serr As System.Text.Str ingBuilder) As Integer

    ' Using the unmanaged function:

    ret_flag = swe_calc(tjd_et , planet, iflag, xx(6), serr)

    If I take out the 6 in the above line, I get error "number of indices is
    less than the number of dimensions in the indexed array."

    If I put it in, or put a zero in, like xx(0) or xx(6), I get the error
    "value of type double cannot be converted to '1 dimensional array of
    double'"

    What is wrong here? TIA



    --

    Patrick Sullivan, AA-BA, BA-IT


  • Patrick Sullivan

    #2
    oops, this is correct code

    dim s_err as stringbuilder
    dim xx(6) as double
    dim ret_flag as integer

    ' This is a function to call an unmanaged C-style library function.
    ' The lib function fills an array of 6 doubles or error string.

    Declare Auto Function calc Lib "calc32.dll " Alias "calc32.dll "( ByRef xx()
    As Double, ByVal serr As System.Text.Str ingBuilder) As Integer

    ' Using the unmanaged function:

    ret_flag = swe_calc(xx(6), serr)

    If I take out the 6 in the above line, I get error "number of indices is
    less than the number of dimensions in the indexed array."

    If I put it in, or put a zero in, like xx(0) or xx(6), I get the error
    "value of type double cannot be converted to '1 dimensional array of
    double'"

    What is wrong here? TIA




    Comment

    • Larry Lard

      #3
      Re: oops, this is correct code


      Patrick Sullivan wrote:[color=blue]
      > dim s_err as stringbuilder
      > dim xx(6) as double
      > dim ret_flag as integer
      >
      > ' This is a function to call an unmanaged C-style library function.
      > ' The lib function fills an array of 6 doubles or error string.
      >
      > Declare Auto Function calc Lib "calc32.dll " Alias "calc32.dll "( ByRef xx()
      > As Double, ByVal serr As System.Text.Str ingBuilder) As Integer
      >
      > ' Using the unmanaged function:
      >
      > ret_flag = swe_calc(xx(6), serr)[/color]

      Copy-and-pasting code is a much more reliable way of showing us your
      code. Note that the Declare calls the function 'calc' but you call it
      as 'swe_calc'. If we have to guess what you mean, it will take us
      longer to help you.
      [color=blue]
      >
      > If I take out the 6 in the above line, I get error "number of indices is
      > less than the number of dimensions in the indexed array."
      >
      > If I put it in, or put a zero in, like xx(0) or xx(6), I get the error
      > "value of type double cannot be converted to '1 dimensional array of
      > double'"[/color]

      Try

      ret_flag = calc(xx, serr)

      The function wants an array: it is xx - not xx(0) or xx(6) or xx() -
      that is an array.

      Also, xx should be initialised to an empty array before calling the
      DLL, otherwise there will be nowehere to put the results:

      xx = New Double(6) {}

      Also also, all I have fixed is the syntax: I don't know enough about
      calling unmanaged code to be able to say that this will definitely do
      what you want.

      --
      Larry Lard
      Replies to group please

      Comment

      • Patrick Sullivan

        #4
        Re: oops, this is correct code

        Thanks Larry. You figured out what I wanted to know, I think. Interop is
        kind of confusing. It took me quite a while to get the s_err to pass
        compiling.

        --

        Patrick Sullivan, AA-BA, BA-IT

        "Larry Lard" <larrylard@hotm ail.com> wrote in message
        news:1147101511 .983180.21800@g 10g2000cwb.goog legroups.com...[color=blue]
        >
        > Patrick Sullivan wrote:[color=green]
        > > dim s_err as stringbuilder
        > > dim xx(6) as double
        > > dim ret_flag as integer
        > >
        > > ' This is a function to call an unmanaged C-style library function.
        > > ' The lib function fills an array of 6 doubles or error string.
        > >
        > > Declare Auto Function calc Lib "calc32.dll " Alias "calc32.dll "( ByRef[/color][/color]
        xx()[color=blue][color=green]
        > > As Double, ByVal serr As System.Text.Str ingBuilder) As Integer
        > >
        > > ' Using the unmanaged function:
        > >
        > > ret_flag = swe_calc(xx(6), serr)[/color]
        >
        > Copy-and-pasting code is a much more reliable way of showing us your
        > code. Note that the Declare calls the function 'calc' but you call it
        > as 'swe_calc'. If we have to guess what you mean, it will take us
        > longer to help you.
        >[color=green]
        > >
        > > If I take out the 6 in the above line, I get error "number of indices is
        > > less than the number of dimensions in the indexed array."
        > >
        > > If I put it in, or put a zero in, like xx(0) or xx(6), I get the error
        > > "value of type double cannot be converted to '1 dimensional array of
        > > double'"[/color]
        >
        > Try
        >
        > ret_flag = calc(xx, serr)
        >
        > The function wants an array: it is xx - not xx(0) or xx(6) or xx() -
        > that is an array.
        >
        > Also, xx should be initialised to an empty array before calling the
        > DLL, otherwise there will be nowehere to put the results:
        >
        > xx = New Double(6) {}
        >
        > Also also, all I have fixed is the syntax: I don't know enough about
        > calling unmanaged code to be able to say that this will definitely do
        > what you want.
        >
        > --
        > Larry Lard
        > Replies to group please
        >[/color]


        Comment

        • Göran Andersson

          #5
          Re: oops, this is correct code

          You are declaring an array of 7 doubles. To declare an array of 6
          doubles, you have to do like this:

          dim xx(5) as double

          Patrick Sullivan wrote:[color=blue]
          > dim s_err as stringbuilder
          > dim xx(6) as double
          > dim ret_flag as integer
          >
          > ' This is a function to call an unmanaged C-style library function.
          > ' The lib function fills an array of 6 doubles or error string.
          >
          > Declare Auto Function calc Lib "calc32.dll " Alias "calc32.dll "( ByRef xx()
          > As Double, ByVal serr As System.Text.Str ingBuilder) As Integer
          >
          > ' Using the unmanaged function:
          >
          > ret_flag = swe_calc(xx(6), serr)
          >
          > If I take out the 6 in the above line, I get error "number of indices is
          > less than the number of dimensions in the indexed array."
          >
          > If I put it in, or put a zero in, like xx(0) or xx(6), I get the error
          > "value of type double cannot be converted to '1 dimensional array of
          > double'"
          >
          > What is wrong here? TIA
          >[/color]

          Comment

          Working...