Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Polling with VB. Possible? Good idea?

Status
Not open for further replies.

MarcLodge

Programmer
Feb 26, 2002
1,886
GB
Hi,
At the site where I am working the users have many windows open at once and minimized. One of these windows is a mainframe session that is used for messages - a bit like MS Messenger but written for a M/F before MSG was born. When one user sends a message to another, a notification appears in the mainframe window, row 24 column 6 saying 'Alert received' or similar.

Somebody at the site, many years ago, wrote an app (in Delphi I believe) that interrogated the session using windows APIs and the like so that when the notification is received, a message pops up.

We are in the process of moving to Vista and the new mainframe emulation software is not as open as old one and the existing app cannot be used or amended.

Is there any way that this type of thing could be achieved in VBA? What I would like to do is have a script running on that session all the time, that looks at the specific row/column and pops up a message box when it finds a message have been received.

So far I've got the following, which works, but does not poll.
Code:
Sub Alert()
'
' Alert macro
' Macro created 10/06/2009 by Marc.Lodge
'
Dim AlertNotify As String
Dim DisplayMsg As String

DisplayMsg = "Y"
AlertNotify = Session.GetDisplayText(24, 4, 6)

If AlertNotify = "alerts" Then
  If DisplayMsg = "Y" Then
     DisplayMsg = "N"
     MsgBox "You have received a message"
  End If
End If

If AlertNotify1 = "      " Then
   DisplayMsg = "N"
End If

End Sub

I hasten to add that I am not a VB developer and hardly know the language at all, other than that what I have picked up through looking at other peoples' scripts. I apologise in advance if this is a ludicrous thing to be attempting to do.

Marc
 



Hi,

Not knowing what emulator you are using, I cannot make a specific suggestion.

But in general, you must FIRST, assuming that your emulator has VBA-like language and objects, CREATE an application object for the emulator, using the CreateObject method and then a Session and Screen object.

Then it's just a matter of polling the screen in a loop to get the area you're looking for. You might also need to SEND some keystroke, like ENTER or some function key to GET the latest value. Your code might look something like this (Attachmate!Extra)
Code:
function StartPolling(sPrevAlertNotify as String)
    Dim oSystem AS Object, oSess AS Object, oScrn AS Object
    
    Set oSystem = CreateObject("Extra.System")
    
    Set oSess = oSystem.Sessions.Open("C:\Program Files\E!PC\Sessions\Mainframe.edp")

    With oSess
        .Visible = True
        .WindowState = xNORMAL
    End With

    Set oScrn = oSess.Screen
 
    Do 
      DoEvents 
      AlertNotify = Trim(oScrn.GetDisplayText(24, 4, 6))
    Loop Until AlertNotify <> PrevAlertNotify

    StartPolling = AlertNotify

    Set oScrn = Nothing
    Set oSess = Nothing
    Set oSystem = Nothing
Real rough. You would call this to start the polling process. Might also want a timer to terminate the loop or some other emergency method.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip,
Many thanks for your reply. The emulator I WAS using was attachmate, but for Vista the site is using AttachmateWRQ Reflections 14.0.2.

The VB script in my first post works but does not poll. Do I need to incorporate that into your script, or do I just go with yours?

Many thanks again for your reply.

Marc
 
Hi Skip,
I've taken your function and am calling it from a sub, but when it gets to the create object statement it errors saying "ActiveX component can't create object or return reference to this object (Error 429)". The help screen says that the object's class be registered n the registry and any associated DLLs be available.

I'm now completely out of my depth!

Is it easy to find out what an object's class is???

I've tried viewing the objects for "ThisSession" which exists in the VB editor, but I can't see anything labelled class that I can use.

Marc
 

I've taken your function and am calling it from a sub, but when it gets to the create object statement it errors ...
I thought that you already had the object assigned. If you declare YOUR object as a module variable, rather than a procedure variable, then that object can be refereced in an procedure in the module, so you would not need to CreateObject in the function, just USE it (of course, CHANGING the ovject variable to the one you have already defined).

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Can't speak for Attachmate as I use a different emulator. But I'd be surprised if it doesn't have some kind of event callback you can register for - so you should be able to run a macro that registers a callback that runs when the screen changes. You could examine the screen in the callback routine and pop up an alert window if a new message arrives. This would certainly be cleaner than a polling scheme.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Steve, Skip,
Progress of a sort. I rang Attachmate as they support Reflections and the very helpful support gentleman told me that if I go to Setup-->Events there's a list of events of which one of them is "When a string appears on the screen" and this gives you the ability to run a macro (or other predefined actions).

I changed the macro to just put out a message box and this works fine.

But...... (you knew there was a but coming)......

Unless I'm actually in the window, I don't get the message box. What I want to be able to do is pop up the message box over and above everything else similar to what Outlook does.

I've tried messing about with the ActiveWindow to no avail. I apologise once again for my lack of knowledge, I'm a real newbie in VBA.

Marc
 



Are you running this IN Extra or in some other applicaion? I run all my Attachmate applications from Excel (my prejudice) and do not need the emulator active or even visible.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip,
At the site, we have desktop files that are clicked on in order to run the emulator. In Extra they used to be .EDP files and in Reflections they are some other file extension that I can't remember. These files live on each user's desktop and it is from there that they execute them.

Traditionally they have at least two of these sessions open, plus Outlook, Communicator, Yahoo messenger, net meeting, a variety of spreadsheets and numerous other apps. Many of the users have two or more monitors, although some make do with just one, minimizing and maximizing as they see fit.

What I would like to do is change the Reflections app so that if it is minimized and a message comes in to that minimized app, causing the display to change, a pop up box appears over the top of all screens, with the focus being on that box. I feel that I'm almost there, but it's just that last bit that I can't get working.

Marc
 



Hi,

Unfortunately, I do not believe that is possible. You have no control over other Window applications unless, it seems, you were able to create objects for each, and that is something that I have never done.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip,

OK, that's an answer I can live with and stop following this path. Many thanks for your help and advice.

Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top