Link to home
Start Free TrialLog in
Avatar of Fradojr88
Fradojr88

asked on

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

SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada 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
Avatar of Fradojr88
Fradojr88

ASKER

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 ?
ASKER CERTIFIED SOLUTION
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
That was it its now zipping up the correct file. Thanks again now just some more tweaking!!!
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 ?
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

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