Results 1 to 10 of 10

Thread: Array question

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Posts
    6

    Post

    I might just be dumb, but is there any way to Dim an array using a variable? IE. Dim Array(1 To UBoud, 1 To 3) As String

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

    Post

    No, but you can Redim it if you need to.

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

  3. #3
    New Member
    Join Date
    Oct 1999
    Location
    Birmingham, Al, United States
    Posts
    10

    Post

    I wrote a program where I wanted a varying number of elements without having to keep updating code. I did something like this:

    FileCount = FileCount + 1
    ReDim Preserve NumFiles(FileCount)

    Then I added my new element:

    NumFiles(FileCount) = file$

    This may be what you want to do.

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Posts
    6

    Post

    Hey, thanks guys. :-)


    Now what are the odds that I can keep this variable that I'm constantly ReDim-ing Global the whole time?

  5. #5
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    Declare it as Static!

    Phil

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Posts
    6

    Post

    Thanks, Phil. :-)

    Sorry for askin' all the dumb questions, I haven't had VB for long and I'm still trying to do most of my coding QB style. Most of it works, though.

  7. #7
    Lively Member
    Join Date
    Apr 1999
    Location
    India
    Posts
    73

    Post

    hello friends
    You can declare an array like this
    dim sarray(ubound) as string
    u need to declare "ubound" as constant
    Thanx Manish

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Posts
    6

    Post

    Another question for you guys 'cause I'm dumb... Well, OK. It's the same question again.

    The Static thing isn't working. Not the way I want it to. From what I've read now that I looked it up, Static claims that it still only works in one Sub but that it endures repeated calls. I need to be able to repeatedly ReDim the array, but I need it to be legitimately Global so that I can share it with many different Subs. Is Static really right and I'm just not doing it right or is there some other way?

  9. #9
    Lively Member
    Join Date
    Apr 1999
    Location
    India
    Posts
    73

    Post

    hi
    what i understand is u want a constant value and want to redim an array on the basis of the constant value. Am i right?? u can use constant declare it in a form or in a BAS according to yr need and u can use it. as per the scope.
    Thanx Manish

  10. #10
    New Member
    Join Date
    Oct 1999
    Location
    Birmingham, Al, United States
    Posts
    10

    Post

    Hey, I just read your recent question. I had the Global MyArray() as string in the declaration and set the array to zero before the loop by putting ReDim MyArray(0) before the loop began. Also, you can declare the variable you are resetting the MyArray length to as Global as well. Well, I hope that this will shed more light on your question. Sorry, I should have put this stuff in there too. Let me know if I can be of more help.

    clint_22@yahoo.com

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