|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Displaying copied file names in textboxfrom one location to another: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Const FOLDER_FROM As String = "D:\My Documents" ' Folder to copy from Const FOLDER_TO As String = "D:\My Documents\Miscellaneous2" 'Folder to create above folder in Dim newDir As DirectoryInfo = Directory.CreateDirectory(FOLDER_TO & "\" & New DirectoryInfo(FOLDER_FROM).Name) CopyFiles(New DirectoryInfo(FOLDER_FROM), newDir) End Sub Private Sub CopyFiles(ByVal FolderFrom As DirectoryInfo, ByVal FolderTo As DirectoryInfo) Dim Files() As String = Directory.GetFiles(FolderFrom.FullName) Dim SF() As String = Directory.GetDirectories(FolderFrom.FullName) Dim Var As Integer Dim start, finish As Double For Var = Files.GetLowerBound(0) To Files.GetUpperBound(0) File.Copy(Files(Var), FolderTo.FullName & "\" & New FileInfo(Files(Var)).Name) Next For Var = SF.GetLowerBound(0) To SF.GetUpperBound(0) Dim dName As String = New DirectoryInfo(SF(Var)).Name Dim newD As New DirectoryInfo(FolderTo.FullName & "\" & dName) newD.Create() CopyFiles(New DirectoryInfo(FolderFrom.FullName & "\" & dName), newD) Label2.Text = (Files(Var)) Label2.Refresh() Next End Sub My question is why the line Label2.Text=(Files(Var)) does not work. I get the following: An unhandled exception of type 'System.IndexOutOfRangeException' occurred in update.exe Additional information: Index was outside the bounds of the array. TIA Mike Because you are looping throught the SF array and are trying to access
an element in the Files array. The SF array has obviously fewer elements than the Files array. mmalin***@gmail.com wrote: Show quoteHide quote > I have the following code that I borrowed from this NG to copy files > from one location to another: > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Const FOLDER_FROM As String = "D:\My Documents" ' Folder to > copy from > Const FOLDER_TO As String = "D:\My Documents\Miscellaneous2" > 'Folder to create above folder in > Dim newDir As DirectoryInfo = > Directory.CreateDirectory(FOLDER_TO & "\" & New > DirectoryInfo(FOLDER_FROM).Name) > CopyFiles(New DirectoryInfo(FOLDER_FROM), newDir) > End Sub > Private Sub CopyFiles(ByVal FolderFrom As DirectoryInfo, ByVal > FolderTo As DirectoryInfo) > Dim Files() As String = Directory.GetFiles(FolderFrom.FullName) > Dim SF() As String = > Directory.GetDirectories(FolderFrom.FullName) > Dim Var As Integer > Dim start, finish As Double > For Var = Files.GetLowerBound(0) To Files.GetUpperBound(0) > File.Copy(Files(Var), FolderTo.FullName & "\" & New > FileInfo(Files(Var)).Name) > Next > For Var = SF.GetLowerBound(0) To SF.GetUpperBound(0) > Dim dName As String = New DirectoryInfo(SF(Var)).Name > Dim newD As New DirectoryInfo(FolderTo.FullName & "\" & > dName) > newD.Create() > CopyFiles(New DirectoryInfo(FolderFrom.FullName & "\" & > dName), newD) > Label2.Text = (Files(Var)) > Label2.Refresh() > Next > End Sub > > My question is why the line Label2.Text=(Files(Var)) does not work. I > get the following: > > An unhandled exception of type 'System.IndexOutOfRangeException' > occurred in > update.exe > > Additional information: Index was outside the bounds of the array. > > TIA > Mike >
Loading controls with objects versus recordsets
DataTable Loop and String Building TAG Property Is there an easy way to get my Subnet Mask? VB 2005 express database problems inheritance question Ent Library. Substitute data from app.config? DATAGRID PROBLEM MailMessage to send email with both Text and HTML versions... vb.Script to VB.NET 2005 |
|||||||||||||||||||||||