[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB.Net Loops, Simple Coding

Posted on 2007-04-03
2
Medium Priority
?
224 Views
Last Modified: 2010-04-23
Hi,

Couple of things i need to do:

I have a source location c:\
Within here i have files a.tif, b.tif, c.tif
I want to move them to a target location (which i know how to do) but i want them to a_1.tif, b_1.tif, c_1.tif
However, if a_1.tif exists already in the target i want to create a_2.tif etc. This loop i want to be endless
How would i code this

Also at the moment i am testing the code with a button click in the form. If i wanted to make this run automatically do i create an exe. Does this exe when run open the form as i want it to run in the background?

Finally i want to check my source folder every "x" seconds. How is this possible? I presume you can set the .exe to look in the source folder every "x" secs but i don't know how to do it.
0
Comment
Question by:doctech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Expert Comment

by:ElrondCT
ID: 18843117
To see if a file exists, use

    System.IO.File.Exists("myfile")

You could loop until you get an unused name with something like:

        Dim intVersion As Integer = 1
        While System.IO.File.Exists("a_" & intVersion.ToString & ".tif")
            intVersion += 1
        End While

To have something run every x seconds, create a Timer control for your form and specify the length of time (in milliseconds, i.e., 5 seconds is entered as 5000) between when it should fire in its Interval property (be sure to set the Enabled property to True, as it's set to False by default). The program will need to be running continuously in the background. In the Timer Tick event handler, you put the code that should run when the appropriate time has elapsed.

If you want to create a program that runs only in background and doesn't display a form, you need to create a "Windows service." Describing that in detail is beyond the scope of what I can get into here. Information is available in the online help for Visual Studio, and I'm sure there's more at msdn.microsoft.com, though you might find it more productive to get a programming textbook that would walk you through such things in more detail.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 150 total points
ID: 18844633
You don't necessarily need a Windows Service though.  You could just use a regular WinForms project but start from Sub Main so no Form is displayed.  Use the ApplicationContext() class to give your app a message pump.

Something like...

Module Module1

    Public Sub Main()
        Application.Run(New MyContext)
    End Sub

    Public Class MyContext
        Inherits ApplicationContext

        Private WithEvents tmr As New System.Windows.Forms.Timer

        Public Sub New()
            tmr.Interval = 15000 ' every 15 seconds
            tmr.Start()
        End Sub

        Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
            tmr.Stop()

            ' do something in here...
            Debug.Print("Tick: " & DateTime.Now.ToString)

            tmr.Start()
        End Sub

    End Class

End Module

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question