473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Displaying copied file names in textbox

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

Apr 30 '06 #1
1 1397
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.

mm*******@gmail.com wrote:
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

Apr 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Fronky | last post by:
Hope someone can help. I am still learning, so no laughing please. I am displaying records from a database using Response.Write(""); instead of the usual datagrid method. I am doing it this way...
11
by: Steve Hoyer | last post by:
I am trying to deploy my first asp.net app to our webserver (2K server, IIS 5) My start page comes up and you can get to the subsequent pages that are tied into our sql server (2K). Each page...
3
by: duncan | last post by:
I have a text box on a web form here is the HTML for it :- <asp:textbox id="winPts" style="LEFT: 170px; POSITION: absolute; TOP: 80px" runat="server" Width="24px" maxlength="2"></asp:textbox> ...
4
by: Nina | last post by:
Hi everyone, I try to a display a .txt file in window's textbox or rich textbox. The text file has contents line by line aligned perfectly when using NotePad to view and print it. But when I...
20
by: Tim Reynolds | last post by:
Team, I am developing a web service. In testing in on my enw PC, I am expecting to see exceptions thrown appear on my browser. Instead I am getting an HTTP 500 Internal Server Error page and I am...
15
by: Kevin Hanken | last post by:
Hi, Pretty much a newbie to aspnet and xp -- I am using XP Pro, Service Pack 2. I installed IIS, set up a virtual directory, created an aspx file and pasted in a little code from the w3schools...
1
by: Anghared | last post by:
I used to study VB in college but it's been a while. Ironically I've forgotten most of it just as I've found the perfect opportunity to utilize it. I want the application to read lines of text...
11
by: pardesiya | last post by:
Friends, I am having trouble displaying Japanese text within a textbox (or anywhere else) in an aspx page with .net 2.0 framework. Initial default text in Japanese displays perfectly but when I...
38
by: ted | last post by:
I have an old link that was widely distributed. I would now like to put a link on that old page that will go to a new page without displaying anything.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.