Results 1 to 3 of 3

Thread: Automatically adding to an Array

  1. #1

    Thread Starter
    Member cramtheman's Avatar
    Join Date
    Dec 2000
    Posts
    43

    Smile

    I would like it so that every time a cmd button is pushed, whatever is in the textbox is automatically added to the array, in to the next available spot. Does anyone know how this would be done?

    Thanks
    cram
    [email protected]
    _ _ _ _ _ _ _ _ _ _ _ _ _ _
    Things to Ponder

    |Man who stands on toilet,
    Is high On pot|
    |Baseball Wrong,
    Man with four balls cannot walk|

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    This should work....

    Code:
    Option Explicit
    
    Dim sArray() As String ' declare dynamic array
    
    Private Sub Command1_Click()
    On Error Resume Next ' call to UBound raises error number 9 if it has not been dimensioned yet
     Dim iCt As Integer
     
     If Not Trim(Text1.Text) = "" Then ' assure user input something
     
        iCt = UBound(sArray) + 1 ' get new number of array elements
     
        ReDim Preserve sArray(iCt) ' Change the dimensions of the array
     
        sArray(iCt) = Text1.Text ' add current text to the array
        
     End If
     
    End Sub
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

    Thread Starter
    Member cramtheman's Avatar
    Join Date
    Dec 2000
    Posts
    43

    Question

    Can you tell me why, when I do this, It complains to me, array already dimensioned?

    Thanks
    cram
    [email protected]
    _ _ _ _ _ _ _ _ _ _ _ _ _ _
    Things to Ponder

    |Man who stands on toilet,
    Is high On pot|
    |Baseball Wrong,
    Man with four balls cannot walk|

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