|
-
Apr 7th, 2004, 06:12 AM
#1
Thread Starter
Junior Member
How to create an array during runtime?
Hi all,
What I'm trying to do is the following:
I want to open one or more files and store their data in an array - a seperate array for each one of the files.
Now I know how many files there will be, but the problem is that it can be one file this run, but next run it can be 5 files and then 3 adn then 4 and so on and so on. So, I figured I need to make arrays (Strings like Tmp1() Tmp2() etc) in runtime.
How do I do this? I think this can only be done by the Dim statement? (Dim Tmp1() As String)
Please advise.
Thanks in advance!
-
Apr 7th, 2004, 06:57 AM
#2
Fanatic Member
Couldn't you use an array of arrays? That way, you would always have one array that contained each file's associated array (however many are needed). Or you could write your own custom collection and store each files data in this collection.
Last edited by VBCrazyCoder; Apr 7th, 2004 at 07:06 AM.
-
Apr 7th, 2004, 07:01 AM
#3
Thread Starter
Junior Member
Thanks for the quick reply...
How do I create a collection? (Or array)
I only know the way by code -->
Code:
Dim tmpArray1() As String
I wouldn't have a clue how to do that in runtime...
-
Apr 7th, 2004, 07:14 AM
#4
Fanatic Member
You would still have to declare your array, then in a loop when you are iterating your files, you would dynamically reinstantiate an array and add it to the original array (using redim preserve or using an arraylist).
You could do something like:
VB Code:
Dim arrAllFilesData As New ArrayList
Dim arrTempSingleFileData As ArrayList
For intFileCount As Integer = 0 To 100
'Set your file stuff here
'Reinstantiate the array
arrTempSingleFileData = New ArrayList
For intFileLineCount As Integer = 0 To 100
'iterating your file line by line
arrTempSingleFileData.Add("Some File Text Here")
Next
'Add the single file array to the main array
arrAllFilesData.Add(arrTempSingleFileData)
Next
so for each file you would be reusing the arrTempSingleFileData arraylist as many times as you need to.
-
Apr 7th, 2004, 07:19 AM
#5
Thread Starter
Junior Member
Thanks, I think this is the code I was looking for!
Edit: Dang this is goodstuff, this will make my life so much easier... Thanks so much!
Last edited by KoffieMok; Apr 7th, 2004 at 07:26 AM.
*(^.^); c(_)
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
|