Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > two dimensional array questions
 

two dimensional array questions

Hello:

I am working with a 2 dimensional array of strings.

It seems that you cannot use redim preserve to change the left element of a 2 dimensional array.  Does that mean I have to declare the array with the actual size, i.e. myarray(1000,1)?  If so, is there a way to trim off the unused elements at the end of my procedure?

If I do this declaration (with the total size of the array), what is the function to show the actual number of rows that have values in them.  It seems that .getupperbound (0) does not give the number of rows being used but the declared size.  Thus I cannot use it.

I need to use an array, not an arraylist.  Also, I presume I cannot bind my 2 dim. array to a listbox.

Thanks for any help.

smHaig

smhaig  Tuesday, January 03, 2006 4:37 AM

What I would suggest, if you really need to use an array is to create a data structure that holds the two elements you want to filter with, and have a single dimension array of that element.

Alternatively, you could "cheat" and declare your array to be arr(1,1000) - but that might make your code confusing to read.

Alex Moura  Tuesday, January 03, 2006 9:17 PM

why don't you make it a single array of string arrays?

why are you forced to use an array? is this a school project? or a directive from a superior? if the latter. . . try and get him fired before he makes another foolish decision.

Blair Allen Stark  Tuesday, January 03, 2006 6:47 AM

Well, this is a directive from a superior.  I have to get an array of files in a particular directory filtered by ext and date.   I have done that but he wants to see the dates for himself and then he needs to use the array to delete the files at various machines.  I think this can be done with all the new 2005 features but this is what he wants. I guess he could do a screen print of the 2 dimensions and then erase with the first dimension in a batch file. 

Anyway, you are suggesting that I have an array of string arrays and these will be 2 elements long? And the array length would be the number of files?  (it has been a while since i have been in school and have not used such a thing since then).

In the meantime.  It does not seem I can even use copy or copyto with a 2 dim array, so must go thru a loop if I want to trim the array to remove the unused cells. 

 

Thanks

smhaig  Tuesday, January 03, 2006 8:14 PM

What I would suggest, if you really need to use an array is to create a data structure that holds the two elements you want to filter with, and have a single dimension array of that element.

Alternatively, you could "cheat" and declare your array to be arr(1,1000) - but that might make your code confusing to read.

Alex Moura  Tuesday, January 03, 2006 9:17 PM

your boss is making this much tougher than it has to be:

Private Function GetList(ByVal path As String, ByVal ext As String, _
    ByVal mindate As DateTime, ByVal maxDate As DateTime) _
    As BindingList(Of System.IO.FileInfo)
  Dim result As New BindingList(Of System.IO.FileInfo)()
  For Each s As String In System.IO.Directory.GetFiles( _
   path, "*." & ext, System.IO.SearchOption.AllDirectories)
    Dim fi As New System.IO.FileInfo(s)
    If (fi.CreationTime >= mindate) And _
  (fi.CreationTime <= maxDate) Then
      result.Add(fi)
    End If
  Next
  Return result
End Function

check out this app. . . http://www.obj-tec.com/MSDNForums/BindingFileInfoVB.zip

Blair Allen Stark  Wednesday, January 04, 2006 1:53 AM

You can use google to search for other answers

Custom Search

More Threads

• Application crashes when downloading a file that doesnt exist or when the server is busy
• fill book marks in an office word template without using the Visual Studio tools for Microsoft office?
• LINQ Sum function on Null rows
• Create 64bit Applications
• using insert statement in a for each ...next
• Only 3 Decimal Places in Textbox
• onkeypress event
• VB LINQ to SQL question "NOT IN"
• C# Fixed statement to VB.NET
• Mdi Parent / Child