acvieira
asked on
Defining a bidimensional array
How can i define a bidimensional array that i dont know how many rows or columns will have?
ASKER
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("Scrip ting.FileS ystemObjec t")
folderPath = Request.ServerVariables("A PPL_PHYSIC AL_PATH") & "txts"
Set objFolder = folderFS.GetFolder(folderP ath)
Set objFiles = objFolder.Files
counter = 0
For Each objFile In objFiles
'fileDate = objFile.DateCreated
fileName = objFile
inFileArray = Split(fileName,"-")
'response.write(inFileArra y )
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
%>
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("Scrip
folderPath = Request.ServerVariables("A
Set objFolder = folderFS.GetFolder(folderP
Set objFiles = objFolder.Files
counter = 0
For Each objFile In objFiles
'fileDate = objFile.DateCreated
fileName = objFile
inFileArray = Split(fileName,"-")
'response.write(inFileArra
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
counter = counter + 1
Next
%>
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.
--Nauman.
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.
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.
ASKER
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
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
hi,
i assume you are using .NET, here is what i tried
Dim fil As New FileInfo("C:\\2006-20-10.t xt")
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
i assume you are using .NET, here is what i tried
Dim fil As New FileInfo("C:\\2006-20-10.t
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
--Nauman.