Solved

Defining a bidimensional array

Posted on 2006-11-13
7
1,082 Views
Last Modified: 2008-01-09
How can i define a bidimensional array that i dont know how many rows or columns will have?
0
Comment
Question by:acvieira
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 17930489
What you are trying to accomplish?

--Nauman.
0
 

Author Comment

by:acvieira
ID: 17930561
I Receive files in a folder the name of file = date e.g 12-05-2006.txt
the algorithm breaks each date part into an array and then I need each part to go into a bidirectional array but i am getting errors when I tty to insert the data.

Please find enclosed the code I am talking about.

thanx for all your help.



------------------------------------
<%

Dim fileDate
Dim oldestFile
Dim fileName
Dim filesArray()
'Dim inFileArray()
Dim counter

Set folderFS = Server.CreateObject("Scripting.FileSystemObject")
folderPath = Request.ServerVariables("APPL_PHYSICAL_PATH") & "txts"

Set objFolder = folderFS.GetFolder(folderPath)
Set objFiles = objFolder.Files

counter = 0
For Each objFile In objFiles
      'fileDate = objFile.DateCreated
      fileName = objFile
        inFileArray = Split(fileName,"-")
      'response.write(inFileArray )
      filesArray(counter,0) = inFileArray
      filesArray(counter,1) = inFileArray(1)
      filesArray(counter,2) = inFileArray(2)
      filesArray(counter,3) = inFileArray(3)      
      'response.write("ficheiro " + counter + " dia: " + filesArray(counter,0) + "; mês: " + filesArray(counter,1) + "; ano: " + filesArray(counter,2))
      'response.write("'response.write("o ficheiro " & fileName & " Foi criado em " & fileDate & "<br />")
      counter = counter + 1
Next

%>
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 17930651
After splitting, the first element of array is always 0 i.e. inFileArray(0), inFileArray(1), inFileArray(2). What I wanted to know why you have to use the bidimensional array.

--Nauman.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:ethoths
ID: 17930742
Use and arraylist of arraylists.

        Dim parent As New ArrayList
        Dim child1 As New ArrayList
        parent.Add(child1)
        Dim child2 As New ArrayList
        parent.Add(child2)


Unlike an array, you can dynamically resize an ArrayList. If you want to get clever you could also consider using generics.

0
 

Author Comment

by:acvieira
ID: 17930810
This :

    filesArray(counter,0) = inFileArray

should be:

    filesArray(counter,0) = inFileArray(0)

It was an error pasting . . .

I have a folder full of files with the naming described above e.g. : 01-10-2006.txt. I'm using this pattern so I can find which file is the most recent or old etc according to it's name and not it's creation date. For that I was trying to use the script above, which still doesn't have the comparison method.
The reason why I am resorting to the bi-dimensional array is so that every file can have it's name splitted and i can make a comparison afterwards, by using the X of the array (array(x,y)) to define which file and the Y's to define day, month, year and file extension. This last part is the one that I'm having trouble with ( Not the comparisson but the creation of the bi-dimensional array).

Thanx for all your help
0
 
LVL 4

Expert Comment

by:satish_nagdev
ID: 17930836
hi,
i assume you are using .NET, here is what i tried

Dim fil As New FileInfo("C:\\2006-20-10.txt")
dim filename as string =fil.Name()
 Dim strs As String() = fil.Name().Split("-")
        Response.Write(strs(0) + vbCrLf)
        Response.Write(strs(1) + vbCrLf)
        Response.Write(strs(2) + vbCrLf)

hope it helps

regards,
satish
0
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 500 total points
ID: 17931016
The following work fine. I am assuming you can manage the most recent date from the list:

Dim files As String
        Dim filesArr As String()
        Dim filePartArr(0, 3) As String
        Dim counter As Int32 = 0
        files = "12-05-2006.txt,13-05-2006.txt,14-05-2006.txt"
        filesArr = files.Split(",")
        ReDim filePartArr(filesArr.Length, 3)
        For Each file As String In filesArr

            Dim filePart As String()
            filePart = file.Split("-")
            filePartArr(counter, 0) = filePart(0)
            filePartArr(counter, 1) = filePart(1)
            filePartArr(counter, 2) = filePart(2).Replace(".txt", "")
            counter = counter + 1

        Next

        For i As Int32 = 0 To counter - 1
            Response.Write("Day: " & filePartArr(i, 0) & ", Month: " & filePartArr(i, 1) & ", Year: " & filePartArr(i, 2) & "<br>")
        Next

--Nauman.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question