Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Variable into Dim Statement (XP)

    Is it possible to pass a variable into a DIM Statement? An example would be:

    Dim oFile(1 to 5) as String Where 5 would be the variable and an integer

    or stated another way

    oVar = 5
    Dim oFile(1 to oVar) as String

    Thanks,
    John

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

    Re: Passing Variable into Dim Statement (XP)

    You first have to declare the variable as a dynamic array:

    Dim oFile() As String
    Dim oVar As Integer

    Then assign the array size using ReDim:

    oVar = 5
    ReDim oFile(1 To oVar)

    If you later want to resize the array while keeping the already assigned array elements, use ReDim Preserve:

    oVar = 8
    ReDim Preserve oFile(1 To oVar)

    oFile(1) to oFile(5) will keep their values, oFile(6) to oFile(8) will be blank.

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Variable into Dim Statement (XP)

    Thank you Sir.

    Regards,
    John

Posting Permissions

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