Triggering an Event that runs a program

Posted on 2002-05-13
Last Modified: 2010-05-02
We have a program running on an old UNIX box, written in Tickle, that FTPs files to a NT directory. Another program (VB) picks up the files, converts their format, moves them to another directory,etc...

Rather than have a service that runs every few minutes,  I would like to have the VB program waiting, idly, for a message from the sending program, who will then do the converts, etc..

The data is ultimately stored in a SQL_Database. The originating program could (maybe) write to a field in the SQL database that would trigger the event. The VB program could be coded and set up on NT to wait for a specific instruction from the Tickle program. Of course it will have to cross platforms from old UNIX to NT.

Any help is appreciated.

Question by:johnstde

Expert Comment

ID: 7007352
a) Use your file system
b) Use a Win32 Message / DDE

a) Just let the Tickle program create a file. The VB app will watch for this file in a loop. If it's created, VB will start processing. After doing all tasks, it will delete the file and the tickle program then knows, it can continue to work.

b) Let the tickle program, when ported to win32, send a message to your vb app which, in a subclassed routine, can pickup the message and start a working task. You could use DDE for this either.
LVL 43

Accepted Solution

TimCottee earned 300 total points
ID: 7008284
hakre, you are new to this site so may not be aware of the guidelines. Please re-read these at the bottom of this page. Your "answer" which does not 100% solve this problem should have been posted as a comment as it now places this question in the "locked" section which will not allow it the attention it deserves. If you continue to post answers inappropriately your account may be referred to customer services for possibly penalty.

johnstde: I would suggest that you reject this proposed answer at this time to allow more experts the opportunity to comment. If you feel that hakre in the end has offered the best solution you may choose the accept comment as answer button to award him/her the points at any time after you have rejected this proposed answer.

Anyway hakre is probably on the right lines. Basically I would use the file system to handle this with a few api calls. Add in a touch of an NT service (NTSRV.OCX) get it here:

You should also use code such as this:

Private Const FILE_NOTIFY_CHANGE_ALL = &H4 Or &H2 Or &H1 Or &H8 Or &H10 Or &H100
Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
Private Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function FindNextChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function ResetEvent Lib "kernel32" (ByVal hEvent As Long) As Long
Private Sub Form_Load()
    'KPD-Team 2000
    Dim Ret As Long
    'Set the notification hook
    Ret = FindFirstChangeNotification("C:\", &HFFFFFFFF, FILE_NOTIFY_CHANGE_ALL)
    'Wait until the event is triggered
    WaitForSingleObject Ret, &HFFFFFFFF
    MsgBox "Event Triggered for the first time"
    'Reactivate our hook
    FindNextChangeNotification Ret
    'Wait until the event is triggered
    WaitForSingleObject Ret, &HFFFFFFFF
    MsgBox "Event Triggered for the second time"
    'Remove our hook
    FindCloseChangeNotification Ret
End Sub

To watch a specified folder (your ftp target folder) for new files being added. You can then run your conversion and output code and VB will then sit idle as a service until the next notification.

Author Comment

ID: 7008656
Following above suggestion, I am rejecting the answer for now so I can spend some time looking at the options offered. Good ideas guys! Thanks for the link and details Tim.

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails


Expert Comment

ID: 7008945
I've worked with something like this in the past, and both Harke and TimCottee have the right idea.  One possible option/enhancement would be to have another 'listener' process sit in front of your main VB program (the one that 'picks up the files, converts their format, moves them to another directory,etc...').

This helps mainly if your main VB app is rather large and you don't want to have it constantly residing in memory.  Your 'listener' would instantiate the main program any time it received data or saw that the file was out there, and pass the data along.

Good luck

LVL 16

Expert Comment

ID: 7009728
LVL 43

Expert Comment

ID: 7010486
True kcleary but of course this could be the service process and you could either use an activex dll/exe or just shell out to a standard exe for the conversion process when necessary.

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now