Results 1 to 8 of 8

Thread: Declaring arrays using variables

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 1999
    Posts
    12

    Post

    In one of my programs, I have to declare a variable as follow :
    Dim Variable(Param1, Param2)

    But everytime I run my program, I get an error warning me that I must use a constant when declaring an array.
    Is there any way around this ?

  2. #2
    Junior Member
    Join Date
    Jul 1999
    Posts
    16

    Post

    I think you have to Dim an array using constants or fixed values. To size it using variables use ReDim e.g.

    Function x
    Dim arrValues(0,0) as integer
    Dim x as integer
    Dim y as integer
    x=10
    y=15
    ReDim [with preserve] arrValues(x,y)
    End

    I've not tried this to check it works, but have a go...

    JP

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Do This
    Code:
    Dim Param1 As Integer
    Dim Param2 As Integer
    Dim Variable() As Integer
    
    Param1 = 1
    Param2 = 2
    ReDim Variable(Param1, Param2)
    ------------------
    Marty

  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    have you tried:

    dim Variable()

    redim Variable(param1, param2)?


  5. #5
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    funny, when I posted no one had replied yet. Looking at the times, we probably all responded at the same time. All with basically the same answer. Ok, maybe it's not that funny but it's friday ok. :-)

  6. #6
    Lively Member
    Join Date
    Jan 2000
    Posts
    123

    Post

    Ok, a very similar question! I thaught REDIMing was very slow? Would it not be easier to just dim a variable that would be oversized to handle the variable instead of rediming it?

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Rediming may or may not be slow, but allocating a large array takes up memory. Take your pick.

    ------------------
    Marty

    [This message has been edited by MartinLiss (edited 01-15-2000).]

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 1999
    Posts
    12

    Post

    Thanks a lot.

Posting Permissions

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



Click Here to Expand Forum to Full Width