Solved

Triggering an Event that runs a program

Posted on 2002-05-13
6
184 Views
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.
DJ

0
Comment
Question by:johnstde
6 Comments
 

Expert Comment

by:hakre
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.
0
 
LVL 43

Accepted Solution

by:
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: http://support.microsoft.com/default.aspx?scid=http://msdn.microsoft.com/library/techart/msdn_ntsrvocx.htm

You should also use code such as this:

Private Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &H4
Private Const FILE_NOTIFY_CHANGE_DIR_NAME = &H2
Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
Private Const FILE_NOTIFY_CHANGE_SIZE = &H8
Private Const FILE_NOTIFY_CHANGE_LAST_WRITE = &H10
Private Const FILE_NOTIFY_CHANGE_SECURITY = &H100
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
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    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.
0
 

Author Comment

by:johnstde
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.

Dj
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Expert Comment

by:kcleary
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

kcleary
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7009728
Hearing...
0
 
LVL 43

Expert Comment

by:TimCottee
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.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 39
VB6 Compile Compatibility Issue 4 102
Help me. 3 54
Formula problem with Excel attachment 6 26
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 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