Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

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
0
sanders720
Asked:
sanders720
1 Solution
 
GrahamSkanCommented:
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
 
GrahamSkanCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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

Featured Post

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now