Unhandled Exception Error

I am getting this error on my application when I run the EXE. But not when I run it in visual studio.

************** Exception Text **************
System.ArgumentException: Argument 'Interval' is not a valid value.
   at Microsoft.VisualBasic.DateAndTime.DateIntervalFromString(String Interval)


Here is my code I think it has something to do with the date.

Imports System.IO.Compression ' Declaring refrences
Imports System.IO ' Declaring refrences
Imports System.Web
Imports System.Net.Mail

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ' Try
        Dim startPath1 As String = "D:\Bootdrv\AlohaQs\DATA\" ' Setting the DATA Folder For Zipping
        Dim startPath2 As String = "D:\Bootdrv\AlohaQs\NEWDATA\" ' Setting the NEWDATA Folder for Zipping
        Dim zipPath1 As String = "D:\Bootdrv\AlohaQs\WILL_DATA.zip" ' Nameing the Backup ZIP
        Dim zipPath2 As String = "D:\Bootdrv\AlohaQs\WILL_NEWDATA.ZIP" 'Nameing the Back up ZIP
        Dim objCurrentDate As Date ' Setting todays Date
        Dim obj2Weeksago As Date ' Decalring 2 weeks ago as date
        Dim objDataFileDate ' Declaring the file directory
        Dim objDateYear As Date ' Declaring the Year & Month
        objCurrentDate = Now
        objDateYear = DateAdd("yyyy" & "m" & "D", -14, objCurrentDate) ' Trying to declare the Date in 20150801 format - 14 days
        obj2Weeksago = DateAdd("d", -14, objCurrentDate) ' - 14 days from todays current date
        objDataFileDate = Directory.GetCreationTime("D:\Bootdrv\AlohaQS\" & objDateYear)  ' Get date and time of directory
        If objDataFileDate <= obj2Weeksago Then
            Dim startPath3 As String = ("D:\Bootdrv\AlohaQS\" & objDateYear)
            Dim zipPath3 As String = ("D:\Bootdrv\AlohaQS\DatedSubsBackup.zip")
            ZipFile.CreateFromDirectory(startPath3, zipPath3)
            ZipFile.CreateFromDirectory(startPath1, zipPath1)
            ZipFile.CreateFromDirectory(startPath2, zipPath2)
            Dim myFTPaddress As String = "ftp://ftpserver" ' ftp server
            Dim myFTPuserName As String = "username" ' ftp username
            Dim myFTPuserPassword As String = "pw" 'ftp password
            Dim myFiles() As String = {"D:\Bootdrv\AlohaQS\WILL_DATA.ZIP", "D:\Bootdrv\AlohaQS\WILL_NEWDATA.ZIP", "D:\Bootdrv\AlohaQS\DatedSubsBackup.ZIP"}  '// files for Uploading
            Dim sTemp As String = Nothing '// used to extract only FileName with Extenstion.
            For Each mySelectedFile As String In myFiles '// loop thru your files.
                sTemp = IO.Path.GetFileName(mySelectedFile) '// get only the file name with extension from Full Path.
                '// upload File to website.
                My.Computer.Network.UploadFile(mySelectedFile, myFTPaddress & sTemp, myFTPuserName, myFTPuserPassword)
            Next
            Dim thisDate As Date
            thisDate = Now
            MessageBox.Show("The upload was successfull!!!")
            My.Computer.FileSystem.WriteAllText("D:\Bootdrv\AlohaQS\TMP\FTPBackupDebout.txt", "thisDateFTP Back Up Completed Successfully", True) 'Writes to the debout that it was successful
            Me.Close()

        Else
            MessageBox.Show("It didnt work Captain, I dont have the power!!!")


        End If

        ' Catch
        'Dim thisDate As Date
        'thisDate = Now
        'MessageBox.Show("There was a error!")
        'My.Computer.FileSystem.WriteAllText("D:\Bootdrv\AlohaQs\TMP\FTPBackupDebout.txt", thisDate & " FTP Back Up was not Successfull", True) ' Write to the debout the upload failed
        'Me.Close()
        'End Try







    End Sub
End Class

Open in new window

Fradojr88Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
debug output        Dim objDateYear As Date ' Declaring the Year & Month
        objCurrentDate = Now
        objDateYear = objCurrentDate
        ' Trying to declare the Date in 20150801 format - 14 days

        obj2Weeksago = objCurrentDate.AddDays(-14) ' - 14 days from todays current date
        objDataFileDate = Directory.GetCreationTime("D:\Bootdrv\AlohaQS\" & objDateYear)  

 ' Trying to declare the Date in 20150801 format - 14 days
Then it is a string not a DATE object. use the .tostring and format options
strDate = obj2Weeksago.ToString("yyyyMMdd")
Fradojr88Author Commented:
Dim startPath1 As String = "D:\Bootdrv\AlohaQs\DATA\" ' Setting the DATA Folder For Zipping
        Dim startPath2 As String = "D:\Bootdrv\AlohaQs\NEWDATA\" ' Setting the NEWDATA Folder for Zipping
        Dim zipPath1 As String = "D:\Bootdrv\AlohaQs\WILL_DATA.zip" ' Nameing the Backup ZIP
        Dim zipPath2 As String = "D:\Bootdrv\AlohaQs\WILL_NEWDATA.ZIP" 'Nameing the Back up ZIP
        Dim objCurrentDate As Date ' Setting todays Date
        Dim obj2Weeksago As Date ' Decalring 2 weeks ago as date
        Dim objDataFileDate ' Declaring the file directory
        Dim objDateYear As Date ' Declaring the Year & Month
        Dim strDate As String
        Dim strDate1 As String
        strDate = obj2Weeksago.ToString("yyyyMMdd")
        strDate1 = objDateYear.ToString("yyyyMMdd")
        objCurrentDate = Now
        objDateYear = objCurrentDate
        obj2Weeksago = objCurrentDate.AddDays(-14) ' - 14 days from todays current date
        objDataFileDate = Directory.GetCreationTime("D:\Bootdrv\AlohaQS\" & strDate1)  ' Get date and time of directory
       

Open in new window


It put it in the correct format but did not find the correct date. it grabbed a 00011001 for the date. Any ideas ?
David Johnson, CD, MVPOwnerCommented:
wrong:
strDate = obj2Weeksago.ToString("yyyyMMdd")
strDate1 = objDateYear.ToString("yyyyMMdd")
objCurrentDate = Now
objDateYear = objCurrentDate
obj2Weeksago = objCurrentDate.AddDays(-14) '

Open in new window


correct:
objCurrentDate = Now
objDateYear = objCurrentDate
obj2Weeksago = objCurrentDate.AddDays(-14) '
strDate = obj2Weeksago.ToString("yyyyMMdd")
strDate1 = objDateYear.ToString("yyyyMMdd")

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Fradojr88Author Commented:
That was it its now zipping up the correct file. Thanks again now just some more tweaking!!!
Fradojr88Author Commented:
Would there be a better way of continuing on from - 14 days to up to -44 Days with out making a line for each one ?
David Johnson, CD, MVPOwnerCommented:
change the signed integer -14 to a variable and use a loop
int days = -14
do while days > -44
objDate = objCurrentDate.AddDays(days) 
strDatex = objDate.ToString("yyyyMMdd")
' more code
days = days -1
loop

Open in new window

Fradojr88Author Commented:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ArgumentOutOfRangeException: The added or subtracted value results in an un-representable DateTime.
Parameter name: value
   at System.DateTime.AddTicks(Int64 value)
   at System.DateTime.Add(Double value, Int32 scale)
   at CDMFtp.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\Frank\Documents\Visual Studio 2013\Projects\CDMFtp\CDMFtp\Form1.vb:line 20
   at System.EventHandler.Invoke(Object sender, EventArgs e)


Getting this now. No compile error as well again
Imports System.IO.Compression ' Declaring refrences
Imports System.IO ' Declaring refrences
Imports System.Web
Imports System.Net.Mail

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim startPath1 As String = "D:\Bootdrv\AlohaQs\DATA\" ' Setting the DATA Folder For Zipping
        Dim startPath2 As String = "D:\Bootdrv\AlohaQs\NEWDATA\" ' Setting the NEWDATA Folder for Zipping
        Dim zipPath1 As String = "D:\Bootdrv\AlohaQs\WILL_DATA.zip" ' Nameing the Backup ZIP
        Dim zipPath2 As String = "D:\Bootdrv\AlohaQs\WILL_NEWDATA.ZIP" 'Nameing the Back up ZIP
        Dim objCurrentDate As Date ' Setting todays Date
        Dim objDataFileDate ' Declaring the file directory
        Dim intDays As Integer
        Dim objDate As Date
        Dim strDatex As String
        Dim myFTPaddress As String = "ftp://" ' ftp server
        Dim myFTPuserName As String = "username" ' ftp username
        Dim myFTPuserPassword As String = "pw" 'ftp password
        intDays = -14
        Do While intDays >= -44
            objDate = objCurrentDate.AddDays(intDays) ' add days up to - 30 days
            strDatex = objDate.ToString("yyyyMMdd") ' format date
            objDataFileDate = Directory.GetCreationTime("D:Bootdrv\AlohaQS\" & strDatex)
            Dim startPath4 As String = ("D:\Bootdrv\AlohaQS\" & strDatex)
            Dim zipPath3 As String = ("D:\Bootdrv\AlohaQS\" & strDatex)
            ZipFile.CreateFromDirectory(startPath4, zipPath3)
            Dim myFiles() As String = {"D:\Bootdrv\AlohaQS\" & strDatex}  '// files for Uploading
            For Each mySelectedFile As String In myFiles '// loop thru your files.
                My.Computer.Network.UploadFile(mySelectedFile, myFTPaddress, myFTPuserName, myFTPuserPassword)
            Next
            MessageBox.Show("The upload was successfull!!!")
            Dim strDebout1 As StreamWriter
            strDebout1 = File.CreateText("D:\Bootdrv\AlohaQS\TMP\FTPBACKUPDebout.txt")
            strDebout1.Write("FTP Back Up Successfull")
            strDebout1.Close()
            intDays = intDays - 1
        Loop
        ZipFile.CreateFromDirectory(startPath1, zipPath1)
        ZipFile.CreateFromDirectory(startPath2, zipPath2)
        Dim myFiles1 As String = ("D:\Bootdrv\Alohaqs\WILL_DATA.ZIP, D:\Bootdrv\Alohaqs\WILL_NEWDATA.ZIP")
        For Each mySelectedFile As String In myFiles1 '// loop thru your files.
            My.Computer.Network.UploadFile(mySelectedFile, myFTPaddress, myFTPuserName, myFTPuserPassword)
        Next
        Dim strDebout As StreamWriter
        strDebout = File.CreateText("D:\Bootdrv\AlohaQS\TMP\FTPBACKUPDebout.txt")
        strDebout.Write("FTP Back Up Successfull")
        strDebout.Close()

    End Sub
End Class

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.