?
Solved

VBScript and event handling under WSH

Posted on 2009-04-24
6
Medium Priority
?
1,020 Views
Last Modified: 2012-05-06
hi,

I would like to write a VBScript program using WSH that waits for incoming calls and then processes them as they come in.  I found the ActiveX controls that can deal with the telephony side of the application, but since it's a completely event driven application, what does the main part of the VBScript do while waiting for a call to come in and trigger an event?  I imagine that if there was a way to ping/query for an incoming call, then I could write a while  loop that sleeps for one second and then pings, although that seems so wasteful and inefficient.  But I don't think I have that functionality anyway, which raises the question of how do I get VBScript to twiddle  its thumbs (while waiting for an event to be triggered) until a call  comes in?  and if I do discover a function that can tell me if a call is coming in,  is the while loop I described above the best way to handle that?

Thanks,

Eyal Yaari
0
Comment
Question by:eyalyaari
6 Comments
 
LVL 8

Expert Comment

by:deadite
ID: 24229905
The main part of your script will just be an infinite loop that waits for a trigger before taking any other action.  For Example:

Do
  'Add your Event Trigger here probably in an If statement or Select Case
Loop
0
 

Author Comment

by:eyalyaari
ID: 24234509

I tried running a tight loop like that and it used up 25 to 30% of my CPU. Is there a way to put it in sleep commands or something to that effect which won't eat up so much computer resources?  what would  happen if I put in a sleep command in the body of the loop, would it miss the events that happened during that time or would the events get queued up?  is there a kind of "sit idle and listen" method?

Secondly, I don't have a property or method that can access the event trigger.  for example, while I am given the event, X_OnIncomingCall, I am not given any property or method that can tell me if there is any incoming call.

Also, if I had a long "if" statement inside the loop that was checking for the event trigger and then triggering the corresponding subroutine, then aren't I copying the functionality of events in the first place?  I wouldn't need to use the built-in event handler since I would be doing the exact same thing manually, right?  Or have I missed the point...

Thanks,

Eyal
0
 
LVL 10

Expert Comment

by:GlobaLevel
ID: 24234517
you could use task manager to kick off the job at a particular time..infinite loop will likely cause the CPU to over process...if you know when the trigger will launch then the task manger can scehedule to run the script right after a trigger launches...
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.

 

Author Comment

by:eyalyaari
ID: 24236181
unfortunately, since the application is processing incoming phone calls it needs to be running all the time :-(

Maybe this can't be done in VBScript?  Would I have the same problem if it was done in regular Visual Basic?

Eyal Yaari
0
 
LVL 76

Accepted Solution

by:
David Lee earned 1000 total points
ID: 24250858
Hi, Eyal.

VBScript isnt typically a good platform for this kind of application.  VB or another high-level language is what youd want.  VBA and VB are substantially similar, so it might be possible to do this in Outlook.  Not sure thats a good choice though.  It might have a significant impact on Outlooks performance.  Its the difference between an executable and a script.  Scripts are by their very nature designed to run a series of commands and then end.  Programs are event driven and run until explicitly terminated.  If a program doesnt have anything to do, then it listens for events.  When an event comes in, then it executes code based on the event that occurred and resumes listening for events (unless the last event told the program to end).  As an example, think about Microsoft Word.  You launch Word and it appears on screen.  Until you start typing or make a menu selection Word is listening for events that pertain to it.  When you start typing, each key stroke generates an event telling Word to read the keyboard fires.  Word fetches the keystroke from the buffer and displays it in the document.  Make a menu selection and you generate another event causing Word to display the menu you clicked on.  Moving the mouse around inside the program generates mouse movement events which in turn tells Word to move the pointer, check to see where it is, display a different pointer depending on where the pointer is in the document, etc.  You dont have to write a loop for that to occur.  The event listener is implicit in every Windows program.  Scripts dont have an event listener.  There may be ways to emulate that in a scripting language, but I doubt that it can be done well.  Scripting languages and the interpreters that run them arent built with that capability in mind.  VBA has the ability to listen for events too.  Thats done by declaring a variable as WithEvents and then writing an event procedure for the event(s) you want to trap.  I dont think that listening for the events would be too much of a burden on Outlook, Im concerned about how Outlooks performance will be affected by the code necessary to process those events.  Naturally if you write this in Outlook, then Outlook will have to be running for the code to be able to listen for an incoming call or dial a number.  If Outlook is normally running all the time, then thats probably not an issue.
0
 

Author Closing Comment

by:eyalyaari
ID: 31574220
excellent, that makes sense. I'll try it in Outlook VBA. Thanks.

Eyal Yaari
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!

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

807 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