Re: Arrays. Beginner's question!



Note that in your original post you are already using a variant:

Dim K(1 to 4)

What Bob (and I) suggest is that instead of using a variant array, you use
a variant variable. You should avoid using variant types whenever possible.
This is one of those cases when a variant type is your friend.

Also note that Bob qualified the variant type by explicitly including "as variant"
in the dim statement, something that I neglected to do. Definitely recommended
doing it Bob's way <g>.

Regards
Saga
--
23, 22, 21, 20, 19, 18...



"Suzy" <not@valid> wrote in message news:474b04a7@xxxxxxxxxxxxxxxxxxxx

"Bob Butler" <noway@xxxxxxxxxxx> wrote in message news:eyaLnJFMIHA.5160@xxxxxxxxxxxxxxxxxxxxxxx
"Suzy" <not@valid> wrote in message news:474b0175$1@xxxxxxxxxxxxxxxxxxxx
Dim K(1 to 4)

...

K=Array(45,65,23,465)

What am I doing wrong please as I get "can't assign" error?

The Array function returns a single variant containing the array and you can't assign that to an
array of variants. Unfortunately VB doesn't have any great way of doing what you are trying to
do. The simplest would be to use:

Dim K As Variant
K=Array(45,65,23,465)

You can then use K(0) through K(3) to get the values

Thanks Bob. So basically I have to use a variant, which people have alawys advised strongly
against?




.



Relevant Pages

  • Re: ReDim not working as expected. Array expert needed.
    ... MsgBox TypeName) ' Type Variant() ... examples of how array dimensions work in VBA. ... Sub ArrayStudies14() ... Dim MyArray As Variant ' Declare nonarray variant. ...
    (microsoft.public.excel.programming)
  • Re: C++ Conversion functions for pointers
    ... I know I can create an array of Variant pointers and assign to these ... >> But the problem I am having is converting an int pointer to a Variant ...
    (alt.comp.lang.learn.c-cpp)
  • Re: ReDim not working as expected. Array expert needed.
    ... "I've seen people use a variant to contain the values ... array in the first place, the damage is done and it's not likely to get ... I next told you not to redim it. ... Dim MyArray As Variant ' Declare nonarray variant. ...
    (microsoft.public.excel.programming)
  • Re: Need Help With Arrays and Passing Arguments
    ... array definition to illustrate without really thinking about it. ... Dim myArray() As Variant ... > Sub CallTest1() ...
    (microsoft.public.word.vba.general)
  • Re: General Min/Max function
    ... Correction to my previous post:> ... >>> Public Function MaxAs Variant) As Variant ... >>> Dim Result As Variant, ... >> These functions may accept an array, but they will not process the array ...
    (microsoft.public.vb.general.discussion)