Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Outputting an array from a function (Office XP)

    I want to write a function which reads a single integer and outputs an array of integers (actually a list - one dimensional but of variable length). How do I declare it?
    <img src=/w3timages/blueline.gif width=33% height=2>
    Function OutputArray(x As Integer) As <span style="background-color: #FFFF00; color: #000000; font-weight: bold">??????</span hi>
    ...
    End Function
    <img src=/w3timages/blueline.gif width=33% height=2>
    <img src=/w3timages/blackline.gif width=33% height=2> <img src=/w3timages/blackline.gif width=33% height=2>
    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17>
    My intuition says it should be something like this...
    <img src=/w3timages/blueline.gif width=33% height=2>
    Function OutputArray(x As Integer)() As Integer
    ...
    End Function
    <img src=/w3timages/blueline.gif width=33% height=2>
    ... but that's a definite <img src=/S/nope.gif border=0 alt=nope width=15 height=15>, apparently. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Outputting an array from a function (Office XP)

    You can use

    Function OutputArray(x As Integer) As Integer()

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Outputting an array from a function (Office XP)

    Another way would be to create a procedure with an array argument. Since arguments are By Reference unless otherwise specified, you can modify the array argument.

    Sub OutputArray(x As Integer, MyArray() As Integer)
    ...
    End Sub

    Call like this:

    Dim MyArr() As Integer
    OutputArray 10, MyArr

  4. #4
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Outputting an array from a function (Office XP

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> Thanks, Hans, for both answers. I knew there had to be a simple way of doing it!


    <img src=/S/ranton.gif border=0 alt=ranton width=66 height=37> But could I find it in Microsoft's help files or on MSDN? <img src=/S/rantoff.gif border=0 alt=rantoff width=66 height=37>
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •