|
-
May 31st, 2004, 05:10 AM
#1
Thread Starter
New Member
OpenFileDialog & Array help
I want to use an open file dialog, and be able to select multiple images and have their full path names loaded in an array of an unspecified size... so far I've got to here, but am stuck at how to proceed.
Can someone help?
VB Code:
Private Sub Menu_Open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Menu_Open.Click
'declares undefined array
Dim Picturelist() As String
Dim fileName As String
Dim i As Integer
ofdPicture.InitialDirectory = "C:\"
ofdPicture.Multiselect = True
ofdPicture.Filter = "Image Files (*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF"
ofdPicture.ShowDialog()
I know I'm meant to use ReDim but how would I "count" the number of individual files that have been selected by the user?
Would I have to use a loop to put the path name into the array? Something like
VB Code:
For i = 1 To Picturelist.GetUpperBound(Picturelist)
ReDim Preserve Picturelist(Picturelist.GetUpperBound + 1)
Picturelist(i) = ofdPicture.FileName
Next i
-
May 31st, 2004, 06:55 AM
#2
Hyperactive Member
Dear friend, you don't have to redim, but simply to assign Filenames (plural, not Filename) to your array, without specifying an index:
Picturelist = ofdPicture.FileNames
That's all!
If,for other situation you need something easy to redim, have a look to arraylist.
Good job
Live long and prosper (Mr. Spock)
-
May 31st, 2004, 07:43 AM
#3
Thread Starter
New Member
Thank you for your help! It set me on the right track..... greatly appreciated!
Now a slight deviation - if I was to want to select more images again using OFD, wouldn't the original list of filenames in the array be overridden?
How would I go about changing this? I would have to use ReDim now, no? To increase the size of the array...
I did this:
VB Code:
If ofdPicture.ShowDialog = DialogResult.OK Then
ReDim Preserve Pictures(i)
For i = 0 To ofdPicture.FileNames.GetUpperBound(0)
Pictures(i) = ofdPicture.FileNames(i)
Next i
End If
Not entirely sure if it was correct though, because I didn't specify the limit to the array?
-
May 31st, 2004, 08:44 AM
#4
Hyperactive Member
I can't test my code, now, so be careful, but i think it should be useful, also if wrong. I think you can understand, anyway, which is the problem in the code you posted.
Excuse my english!
VB Code:
Dim OldFinalPosition as integer=pictures.getlenght(0)
If ofdPicture.ShowDialog = DialogResult.OK Then
ReDim Preserve Pictures(pictures.ofdPicture.FileNames.GetLenght(0)+OldFinalPosition- 1)
For i = 0 To ofdPicture.FileNames.GetUpperBound(0)
Pictures(i+oldfinalposition) = ofdPicture.FileNames(i)
Next i
End If
Let me know if it' s sufficient to help you.
Live long and prosper (Mr. Spock)
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
|