Results 1 to 6 of 6

Thread: ReDim Array Qusetion "EASY"

  1. #1

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Indianapolis, Indana, USA
    Posts
    40

    ReDim Array Qusetion "EASY"

    I have a series of buttons and an array"array()"
    Each button has a corrisponding "Name" associated with it.
    When each Button is clicked I need it to add one row to my array and Fill that row with the corrisponding Name, yet keep all previouse names in the array.

    I Know this code will cause some kind of out of bound error due to trying to add to an array that is full but I dont know how to get arround it.

    Dim array( ) As String

    Dim i As Integer

    cmdAddSteve_Click( )
    i = UBOUND(array( )) + 1
    array(i ) = “Steve”
    End Sub

    cmdAddJohn_Click( )
    i = UBOUND(array()) + 1
    array(i ) = “John”
    End Sub

    cmdAddSusan_Click( )
    i = UBOUND(array()) + 1
    array(i ) = “John”
    End Sub
    Last edited by Alakazam; Nov 15th, 2001 at 02:55 PM.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Redim Preserve array(i+1)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Indianapolis, Indana, USA
    Posts
    40
    You mean like this?

    Dim IC( ) As String
    Dim i As Integer

    cmdAddSteve_Click( )
    i = UBOUND(IC( )) + 1
    Redim Preserve array(i+1)
    IC(i ) = “Steve”
    End Sub

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    i = UBOUND(IC( )) + 1
    Redim Preserve array(i+1)
    IC(i ) = “Steve”

    array was just a "fake" name....your array name is IC()
    so use IC

    do it like this...


    I = Ubound(IC) + 1
    Redim Preserve IC(i)
    IC(i) = "Steve"

    ok?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Indianapolis, Indana, USA
    Posts
    40

    This Does Not Work

    Dim IC() As String
    Dim i As Integer, ii As Integer
    Private Sub Command1_Click(Index As Integer)
    i = UBound(IC) + 1 'Subscript out of range
    ReDim Preserve IC(i)
    IC(i) = "Steve"

    End Sub

    Private Sub Command2_Click()
    i = UBound(IC) + 1
    ReDim Preserve IC(i)
    IC(i) = "Jane"
    End Sub

    Private Sub Command3_Click()
    'Check to see values of IC() array
    For ii = 0 To UBound(IC)
    Print IC(ii)
    Next ii
    End Sub

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Try adding this code:

    VB Code:
    1. Private Sub Form_Load()
    2.    ReDim IC(0)
    3. End Sub
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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