|
-
Dec 3rd, 2000, 04:18 PM
#1
Thread Starter
Hyperactive Member
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
-
Dec 3rd, 2000, 04:27 PM
#2
transcendental analytic
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.
-
Dec 3rd, 2000, 04:42 PM
#3
Thread Starter
Hyperactive Member
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?
-
Dec 3rd, 2000, 04:46 PM
#4
Answer
-
Dec 3rd, 2000, 05:29 PM
#5
Frenzied Member
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.
-
Dec 3rd, 2000, 09:59 PM
#6
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|