Timers

I have a program that creates an ini file and then uses that file to automatically generate the PDF file to the determined filename and location.  It works great!  The problem is, I need to delete the ini file when complete.

In VB, the file delete is happening prior to the PDF file generation, because file functions happen faster, I assume.  I've looked into timer controls, but since this is all in a module I have no form to put them on.

The code below mioght work, except that the system has no idea what sleep does.  Apparently, this is not a predefined command.

Any thoughts on this matter would be greatly appreciated.


Partial code...

    oPM.SubmitPrint    
    Delay (30)
    Kill "c:\pdf995\res\pdf995.ini"


Public Sub Delay(pdblSeconds As Double)
    Const OneSecond As Double = 1# / (1440# * 60#)
    Dim dblWaitUntil As Date
    Do Until Now > dblWaitUntil
        Sleep (100)
    Loop
   
End Sub
sanders720Asked:
Who is Participating?
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.

GrahamSkanRetiredCommented:
There's no reason why you shouldn't have a form with a timer control on it. It doesn't have to be made visible, just loaded.

Sleep is implemented in a windows API:
Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
0
sanders720Author Commented:
But the code does not even run from a form!  I have a button in Autodesk Inventor to PDFPlot.  It uses native VB6.  Where should the public declare go?  I put it in the header at the top of all the different functions, but the file was still deleted and there was no 30 second delay.
0
GrahamSkanRetiredCommented:
I don't know anything about 'Autodesk Inventor to PDFPlot', but if you have a VB6 application, but you can declare a DLL functions (including Windows API call) in the declarations section of the code module.

In any VB6 application, you can add a form that is never made visible. If it has controls, such as a timer control you can programatically or otherwise, set their properties to say, Form1.Timer1.Interval = 100 and Form1.Timer1.Enabled = True.
In Form1.Timer1.Timer_Event() procedure, you can have a 'Call delete_Pdf' procedure.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

RogueSolutionsCommented:
Your Do Loop isn't testing against anything (dblWaitUntil isn't set).

You want something like ...

Public Sub Delay(pdblSeconds As Double)

    Const OneSecond As Double = 1# / (1440# * 60#)      'Not sure what this is here for ?

    Dim dblWaitUntil As Date

    dblWaitUntil = Now + pdblSeconds

    Do Until Now > dblWaitUntil
        Sleep (100)
    Loop
   
End Sub
0
RogueSolutionsCommented:
Oops, adding seconds to now is treated as days.

The "dblWaitUntil = ..." should have been ...

    dblWaitUntil = DateAdd("s", pdblSeconds, Now)
0

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
jpontaniCommented:
Dim WithEvents myTimer As New Timer

Private Sub Main(ByVal sender As Object, ByVal e As System.EventArgs)
        myTimer.Interval = 30000
        myTimer.Enabled = True
        AddHandler myTimer.Tick, AddressOf killFile
        myTimer.Start()
End Sub

Sub killFile(ByVal sender As Object, ByVal e As System.EventArgs) Handles myTimer.Tick

End Sub

That creates a timer event with a handler that fires the killFile when 30000 milliseconds (30 seconds) passes.
0
BrianGEFF719Commented:
jpontani: you are giving code for .NET the user i belive is asking for Visual Basic code not .NET code.
0
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 Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.