Results 1 to 6 of 6

Thread: Arrays

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482

    Question

    Hey, is there a way to make an array that you can ADD more, or DELETE some.

    like
    dim TheMax as integer
    global Array(1 to TheMax)

    or something, so where
    i can add MORE arrays to it, or DELETE arrays

    so

    Array(40) ' Delete it
    so u can only have Array(39) or lower

    or add one so u can have up to Array(41)

    And such


    I have a normal array right now.. but i can't add any more, or delete any.
    I want flexibility

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Use a dynamic array, you declare it without specifying dimensions:
    Code:
    Public Array()
    'then you redimension it with redim
    Redim Array(1 to 40)
    Redim Preserve Array(1 to 39)'you can redim it later but you have to use preserve to keep the dimensions.
    'you can only preserve the last dimension in a multidimensioned array.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    I get the first thing,

    But I got confused on the REDIM and PRESERVE.

    I am putting the array in a module, and ANY FORM can use it.

    so i would ahve to
    redim and preserve ALL of the arrays? 1 to 39, 1 to 38, 1 to 37?

    Eh confused..

    and Redim would just CHANGE the array so u can't use over the MAX ..

    and preserve would just keep the shape? so i could go like
    if the original was 50
    Redim Preserve Array(1 to 40)

    and it would keep 1 to 40 that i could USE?

  4. #4
    Guest

    Unhappy Answer

    I DON'T KNOW...

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    You're right progeix.

    Damn anonymoshe what are you doing, go bother someone else on another forum (better yet, go bother your cat ), no seriously, what are you up to?
    What does it help to say you don't have the answer? It's not asked to you huh?

    John, please have a look at this.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    Hi! progeix, Since you add and delete an array item frequently. I think can try to use the Dictionary Object. Becuase this object provide some feature that make our life easy when we wish to manipulate a group of data that not in the database format.

    Code:
    Option Explicit
    Private dict As Dictionary
    
    Private Sub Form_Load()
    'Create Dictionary Object for faster searching performance
    'For the Dictionary Object, you need to reference to
    'Microsoft Scripting Library (scrrun.dll)
    Set dict = New Dictionary
    dict.CompareMode = TextCompare
    End Sub
    
    Private Sub Command1_Click()
    Dim i As Integer
    For i = 0 To 10
        ADD_ITEM "k" & i, "Item " & i
    Next
    End Sub
    
    Private Sub Command2_Click()
    'Remove Item by Key
    REMOVE_ITEM "k3"
    End Sub
    
    Private Sub Command3_Click()
    Dim itm As String
    'Serach by Key
    itm = SEARCH_ITEM("k8")
    If itm <> "" Then
        MsgBox "Item found - " & itm
    Else
        MsgBox "Item Not Found"
    End If
    End Sub
    
    Private Function SEARCH_ITEM(ByVal strSeekKey As String) As String
    If strSeekKey <> "" Then
        If dict.Exists(strSeekKey) Then
            SEARCH_ITEM = dict.Item(strSeekKey)
        Else
            SEARCH_ITEM = ""
        End If
    End If
    End Function
    
    Private Sub ADD_ITEM(ByVal strKey As String, ByVal strItem As String)
    dict.Add strKey, strItem
    End Sub
    
    Private Sub REMOVE_ITEM(ByVal strKey As String)
    dict.Remove strKey
    End Sub

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