Results 1 to 3 of 3

Thread: Changing the Copy File Format

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2015
    Posts
    42

    Question Changing the Copy File Format

    Hey,
    So right now I have this code working correctly (at bottom). I have it so when a File is selected in listbox1 and button1 is pressed it will copy the file and place a underscore before it (Example: "_ File.mov")

    I would like to change it up a bit and change it so that I can have textbox2 be a location that the user can put what they want in front of the file after it is copied. (Example: File.mov, user puts in textbox: 77, would copy to 77File.mov)

    Now I have tried changing the code to:
    Code:
     Dim CopyFormat = "C:\Server Media\LIVE\" + textbox2.text
    'or
     Dim CopyFormat = "C:\Server Media\LIVE\" + "textbox2.text"
    'or
     Dim CopyFormat = "C:\Server Media\LIVE\" + (textbox2.text)
    Error I keep getting: "Object reference not set to an instance of an object." I'm guessing it just needs to be written a different way?

    Full Code for this section:
    Code:
        Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        Dim MediaLocation = "C:\Server Media\LIVE\"
        Dim CopyFormat = "C:\Server Media\LIVE\" + "_ "
            Try
                For Each o As Object In ListBox1.SelectedItems
                    My.Computer.FileSystem.CopyFile(MediaLocation & o.ToString, CopyFormat & o.ToString)
                Next
            Catch ex As Exception
                MsgBox("Clip already exists", MsgBoxStyle.Critical, "Error")
            End Try
    End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Changing the Copy File Format

    NullReferenceExceptions are fairly easy to diagnose. When it's thrown, the first thing to do is to test each reference on the offending line and determine which one is Nothing. You then work backwards to where you expected a value to be assigned to that reference.

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2015
    Posts
    42

    Re: Changing the Copy File Format

    I got it to work!
    Here is the answer:
    Code:
            Try
                For Each o As Object In ListBox1.SelectedItems
                    My.Computer.FileSystem.CopyFile(MediaLocation & o.ToString, CopyFormat + Label8.Text & o.ToString)
                Next
            Catch ex As Exception
                MsgBox("Clip already exists", MsgBoxStyle.Critical, "Error")
            End Try
    I changed it so that you enter into textbox2 press save and it updates into label8 and then I added label8 to the code.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width