need help looping

ok i have a program that will check to see if a file exists and if so it will copy to a new location but i need it to only copy once a day incase the computer is left on but i want it to keep running here it is

Code Snippet

PrivateSub Form1_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.Load

Dim FilesAsString

If 9 <My.Computer.Clock.LocalTime.DayThen

Files ="Shaner Lawns " &My.Computer.Clock.LocalTime.Month &"-" &My.Computer.Clock.LocalTime.Day &"-07.qbb"

Else

Files ="Shaner Lawns " &My.Computer.Clock.LocalTime.Month &"-0" &My.Computer.Clock.LocalTime.Day &"-07.qbb"

EndIf

If File.Exists("C:\Users\Mr. Brian Shaner\Documents\" & Files)Then

Dim LocAsString

Loc ="C:\Users\Mr. Brian Shaner\Documents\" & Files

Dim MomAsString

Mom ="\\MOMROOM\SharedDocs\syscombkup1\" & Files

Dim SisAsString

Sis ="\\G_COM\SharedDocs\syscombkup2\" & Files

My.Computer.FileSystem.CopyFile(Loc, Mom,True)

My.Computer.FileSystem.CopyFile(Loc, Sis,True)

EndIf

EndSub

ok i want this part of the code to continueally loop no matter what but to only copy once a day if the file exists

note the filename is created taking the date ie. Shaner Lawns m-dd-yy

[4507 byte] By [Flame.e] at [2008-1-6]
# 1

Just keep track of the last date the code ran and only run it if it's been a full day since the last run. Here's an example:

Code Snippet

Public LastCopy As Date = Now.Subtract(New TimeSpan(1, 0, 0, 0))

Public Sub ProcessFiles()

If Now.Subtract(Me.LastCopy).TotalDays > 1 Then

Dim Files As String

Files = String.Format("Shaner Lawns {0:MM-dd-yy}.qbb", Now)

Dim Loc As String

Loc = "C:\Users\Mr. Brian Shaner\Documents\" & Files

If System.IO.File.Exists(Loc) Then

Dim Mom As String

Mom = "\\MOMROOM\SharedDocs\syscombkup1\" & Files

Dim Sis As String

Sis = "\\G_COM\SharedDocs\syscombkup2\" & Files

My.Computer.FileSystem.CopyFile(Loc, Mom, True)

My.Computer.FileSystem.CopyFile(Loc, Sis, True)

LastCopy = Now

End If

End If

End Sub

Now for the loop, you'd want to keep calling this ProcessFiles() method. You might just use a timer to keep calling it, or run a BackgroundWorker that calls it in a loop until the worker is canceled or the application is closed.

Hope that helps

rkimble at 2007-10-1 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

ok sorry i didnt see this answer till just now but i kinda figured it out with one problem is it consumes like 50 cpu and i want to know if anyone can help me with that otherwise its good

Code Snippet

Imports System

Imports System.IO

Imports System.Text

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim Var As Integer

Var = 0

Dim Day As Integer

Day = My.Computer.Clock.LocalTime.Day

Do

Dim Files As String

If 9 < My.Computer.Clock.LocalTime.Day Then

Files = "Shaner Lawns " & My.Computer.Clock.LocalTime.Month & "-" & My.Computer.Clock.LocalTime.Day & "-07.qbb"

Else

Files = "Shaner Lawns " & My.Computer.Clock.LocalTime.Month & "-0" & My.Computer.Clock.LocalTime.Day & "-07.qbb"

End If

Do Until 1 = Var

If File.Exists("C:\Users\Mr. Brian Shaner\Documents\" & Files) Then

Dim Loc As String

Loc = "C:\Users\Mr. Brian Shaner\Documents\" & Files

Dim Mom As String

Mom = "\\MOMROOM\SharedDocs\syscombkup1\" & Files

Dim Sis As String

Sis = "\\G_COM\SharedDocs\syscombkup2\" & Files

My.Computer.FileSystem.CopyFile(Loc, Mom, True)

My.Computer.FileSystem.CopyFile(Loc, Sis, True)

Var = 1

End If

Loop

If 1 = Var Then

If (Day + 1) = My.Computer.Clock.LocalTime.Day Then

Day = Day + 1

Var = 0

End If

End If

Loop

End Sub

End Class

Flame.e at 2007-10-1 > top of Msdn Tech,Visual Basic,Visual Basic Language...