Announcement

Collapse
No announcement yet.

variant array byref ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • variant array byref ?

    This is what i want to use and due that this is a method macro's for workaround are not suitable.
    Code:
    Method ToArray( ByRef vArray() As Variant ) As Long
    
        Redim vArray( 0 to 100 )
    
        vArray( 0 ) = 123
    
    End Method
    In fact the variant will be populated with a safearray obtained via Excel.

    I get this error:

    PowerBASIC for Windows
    PB/Win Version 9.01
    Copyright (c) 1996-2009 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    (311:041): Scalar variable expected
    hellobasic

  • #2
    If your param is one array, then it's "byref varray AS VARIANT" and vArray has been assigned an array, as in ..
    Code:
     vArray =      foo()  [AS datatype]
    BUt if you want to pass an array of variants (different) and the compiler will not accept, yout can try...
    Code:
     
    Method Foo  ( vArray() AS VARIANTAPI)
    .. after doing whatever you have to do to set that up.

    One safearray param = "varname [no parens] AS VARIANT "

    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Method ToArray( ByRef vArray() As Variant ) As Long
      You can't pass arrays to a method this way. COM knows nothing about PB descriptor arrays. Pass a pointer instead or a safe array.
      Forum: http://www.jose.it-berater.org/smfforum/index.php

      Comment


      • #4
        It was a thought.

        So I guess it's just pass the safearray "as variant" (not a PB array of variants) and deal with it in your code.
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Originally posted by Michael Mattias View Post
          It was a thought.

          So I guess it's just pass the safearray "as variant" (not a PB array of variants) and deal with it in your code.
          Yes, i already did that, but it's not that ideal.
          It's a solution though.
          I wonder why passing an array is that problematic.
          hellobasic

          Comment


          • #6
            >I wonder why passing an array is that problematic

            Simple.

            Only a PowerBASIC-created client could possibly pass a "PB Array", so your class would be unusable by the 14,653,904 programmers who use anything but PB.

            MCM
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              I keep forgetting
              hellobasic

              Comment


              • #8
                There are functions to convert safearrays into PB arrays, if a PB array is that with which you wish to work in your 'method code.'

                And I cannot imagine any "Win/32 development product supporting an object-oriented model which cannot pass a safearray parameter to a Component Object Model method."
                Michael Mattias
                Tal Systems Inc. (retired)
                Racine WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  > if a PB array is that with which you wish to work in your 'method code.'

                  I obtain data from Excel, not setting it.
                  I just wanted to return a PB variant array and not a variant having a safearray.

                  Case solved..
                  hellobasic

                  Comment


                  • #10
                    > just wanted to return a PB variant array and not a variant having a safearray.

                    FWIW, Sql/Server via ADO returns a safearray as a variant if the column type is 'nvarchar' ...... so you'd probably want to know how to handle that anyway.

                    Here's how I did it, YMMV: Generic 'ADO' Connection and Query Tester (CC 5+/Win 9+) 11-02-08

                    MCM
                    Michael Mattias
                    Tal Systems Inc. (retired)
                    Racine WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment

                    Working...
                    X