CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: dynamic array

  1. #1
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    dynamic array

    In a VB form globally

    you can do this
    Dim A(8) as Integer

    Bt you cant do
    Dim A() as integer

    coming up with ambigious..

    How woudl you declare a dynamic array accessible throughtout the form by any Function or Sub that you can redim here and there
    Thanks

  2. #2
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971
    Private damnA() as Long
    ...
    ..

    Sub F1
    i=100
    ReDim damnA(1 to i)

    End sub

    Sub F1
    i=200
    ReDim damnA(1 to i)

    End sub

  3. #3
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    Declare it in a module as

    Public gnArray(0) as integer


    In your form

    Redim gnArray(100)

    or

    Redim Preserve gnArray(200)

  4. #4
    Join Date
    Aug 2001
    Posts
    1,447
    huh? What are you talking about? I do that all the time and have no problem.
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210
    Dim A() as integer
    To REDIM an array anywhere within a Form declare it in the General Declarations section of the form.
    '
    If you wish to access the array from outside the form you can declare it Public or stuff it in a module.
    The sample below works just fine
    Code:
    Option Explicit
    
    Dim A() As Integer
    
    Private Sub Command1_Click()
        ReDim A(100)
    
    End Sub

  6. #6
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971
    Vb does not like dim outside of a procedure unless it is not going to be redimmed.
    I think it has to be Private Dim A() as integer outside of the procedures and inside you can then reDim...


    Thanks anyway

  7. #7
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    Saeed,

    I have to disagree with you. I've always used the same syntax to declare a dynamic array in a form. In fact, I've just tested the code below:
    Code:
    Dim A() As Integer
    
    Private Sub Form_Load()
        ReDim A(10)
    End Sub
    and it worked as expected. Maybe our cases are not the same. Anyhow, what was the error that you received?

    -Cool Bizs

  8. #8
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Thumbs up

    I hate It.
    VB just poured a bucket of ice water on my head...

    It used to happen ..Now its not happening.....
    mmmmm
    surely there is somethhing wrong with Windows or PC or VB...NOT ME

    I used to get a Message that I cant do what I just did , but now it seems to work
    without any problem after putting it back to what you suggested.


    Thanks for your reply and I am glad you disagreed with me

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

Featured