Results 1 to 6 of 6
  1. #1
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Array Syntax Help (Office 97 and >)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Loungers

    I know you can have a hard coded array, something like:

    myArray = ("Monday","Tuesday","Wednesday","Thursday", ...)

    and then you can choose what item to pick from based on the index. So for example:

    myDay = InputBox("Give me a number from 1 to 7", "Pick Day")
    DayPicked = myArray(myDay)

    so if myDay = 2 DayPicked will be Tuesday in the example above, or is it zero based, so that would make it Wednesday?

    Thanks for any help.

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

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

    Re: Array Syntax Help (Office 97 and >)

    Wassim,

    It would probably have taken you less time to try it out than to post a question in the Lounge. Arrays are zero-based unless you declare them differently, or put Option Base 1 at the top of the module. So in your example, myDay = 2 would result in "WednesDay" by default.

  3. #3
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Array Syntax Help (Office 97 and >)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Hans

    But I did. I tried many forms and I always got the same result:

    Expected: End of Statement.

    Its either that I am so dumb these days, I can't think straight, or I need new glasses because I can't see it.

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

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

    Re: Array Syntax Help (Office 97 and >)

    Your original question was whether you would get "Tuesday" or "Wednesday", not about error messages. You still don't mention on which line the error occurs.

    If you want to create a fixed array, you do it like this:

    Dim myArray As Variant
    myArray = Array("Monday", "Tuesday", "Wednesday", "Thursday", "Thank God it's Friday", "Saturday", "Sunday")

    This is a zero-based array by default, so myArray(2) is "Wednesday".

    Alternatively:

    Dim myArray(1 To 7) As String
    myArray(1) = "Monday"
    ...
    myArray(7) = "Sunday"

    The latter example creates a one-based array, so myArray(2) is "Tuesday".

  5. #5
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Array Syntax Help (Office 97 and >)

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> Hans

    Sorry for the confusion. I thought that the subject of the message said it all.

    I see I needed the keyword Array, and I thought that simply DIMing it would do.

    Sorry, I see I need new glasses.

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Array Syntax Help (Office 97 and >)

    Do NOT use anything other than a lower bound of 0.
    At some point, you may need to port your code to VB .NET, especially when Office becomes fully .NET-ized.

    All arrays in .NET have a lower bound of 0.

Posting Permissions

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