Link to home
Start Free TrialLog in
Avatar of MaxDes101
MaxDes101

asked on

Error: String Cannot Be Of Zero Length

I have a program that should copy files based on listbox selection. Due to the entire path being in listbox I was trying to strip the path out for another variable. My code is below.

What is causing the error:

String Cannot be of zero length. Parameter Name: OldValue
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Me.ProgressBar1.Maximum = 6
        Me.ProgressBar1.Minimum = 0
        Me.ProgressBar1.Value = 0

        Dim sourceRoot As String = SearchLocation.Text
        Dim destinationRoot As String = Review.Text

        Dim FilePath As String
        Dim newfile As String



        newfile = ListBox9.SelectedItem.ToString().Replace(SearchLocation.Text, Review.Text)


        If System.IO.File.Exists(ListBox9.SelectedItem) Then System.IO.File.Copy(ListBox9.SelectedItem, newfile)

        ProgressBar1.Value = +6

    End Sub

Open in new window

Avatar of MaxDes101
MaxDes101

ASKER

For reference the review and search location text is populated by a checkmark being checked... with a path as in c:\ or J:\
ASKER CERTIFIED SOLUTION
Avatar of lazyberezovsky
lazyberezovsky
Flag of Belarus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial