Timer in Mapbasic (sample: call a produce every 10secs)

609 views
Skip to first unread message

pashoang

unread,
May 5, 2009, 11:05:52 PM5/5/09
to MapInfo-L
i'm new in Mapbasic and have a question: Is MB have Timer (like timer
in VB) or have any way to hook timer API for rase an event?
i need a help. thanks !
Best regards!

Peter Horsbøll Møller

unread,
May 6, 2009, 1:52:41 AM5/6/09
to mapi...@googlegroups.com
Lars Nielsen did a timer as an executable a long time ago:
 
This will let you start an executable and tell it when to "wake" you up.
It uses DDE to send "pings" back to MapInfo, so it's not the most modern mechanism.
It does however still work.
 
Otherwise you might be able to achieve this thru .NET.
I must admit that I haven't done this myself.
 

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo

 
2009/5/6 pashoang <pash...@gmail.com>

dhd81

unread,
May 6, 2009, 4:12:09 AM5/6/09
to MapInfo-L
Thank Peter ! So it's quite inconvenient :(
did MapInfo not support that kind of function ?

On May 6, 12:52 pm, Peter Horsbøll Møller <mapinf...@horsboll-
moller.dk> wrote:
> Lars Nielsen did a timer as an executable a long time ago:http://www.directionsmag.com/files/index.php/view/223
>
> This will let you start an executable and tell it when to "wake" you up.
> It uses DDE to send "pings" back to MapInfo, so it's not the most modern
> mechanism.
> It does however still work.
>
> Otherwise you might be able to achieve this thru .NET.
> I must admit that I haven't done this myself.
>
> Peter Horsbøll Møller
> Pitney Bowes Business Insight - MapInfo
>
> 2009/5/6 pashoang <pasho...@gmail.com>

Robert Crossley

unread,
May 6, 2009, 9:46:10 AM5/6/09
to mapi...@googlegroups.com
Another not-too-elegant way would be to use a wait function and put that
into your own subroutine eg, run, then wait, loop

Declare Function GetTickCount Lib "kernel32" () As Integer
Declare Function MsgWaitForMultipleObjects Lib "user32" (ByVal nCount As
Integer, pHandles As Integer, ByVal fWaitAll As Integer, ByVal
dwMilliseconds As Integer, ByVal dwWakeMask As Integer) As Integer



Sub MsgWait(ByVal ms As Integer)
'-----------------------
'Written By: RC
'-----------------------

Dim start As Integer
Dim timeRemaining As Integer
Dim timeNow As Integer
Dim Handles As Integer

'Set up general error handler
ONERROR GOTO ErrorHandler

Print "Waiting " + ms + " milliseconds."

start = GetTickCount()
timeRemaining = ms
Do
If MsgWaitForMultipleObjects(0, Handles, 0, timeRemaining, QS_ALLINPUT)
> 0 Then
End If
timeNow = GetTickCount()
If timeNow - start >= timeRemaining Then
Exit Sub
ElseIf timeNow < start Then
' Handle GetTickCount 49.7 day wrap around
start = timeNow
End If
timeRemaining = timeRemaining - (timeNow - start)
start = timeNow
'DoEvents
Loop
EXIT SUB
ErrorHandler:
CALL ErrorMessage("MsgWait")
END Sub 'ProForma
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.325 / Virus Database: 270.12.18/2096 - Release Date: 05/04/09
17:51:00

dhd81

unread,
May 6, 2009, 10:03:47 AM5/6/09
to MapInfo-L
Thank Robert !
It's really a not-too-elegant way! And if use this Sub in my MB
program, it do the only thing is wait for an event :(
i'm trying user Timer to capture Key Press event. Anyone have other
idea?
Regards!

Spencer Simpson

unread,
May 6, 2009, 1:08:55 PM5/6/09
to mapi...@googlegroups.com
MapBasic only provides limited capabilities for dealing with events. If you
want to go beyond these capabilities, it's probably better to develop the
app the other way around, using Integrated Mapping.

If the only reason you want a timer is to wait for a keypress, there are
probably simpler ways of getting what you want.

What do you want your app to do when the key is pressed? Why a key press?

Is this a command that could be invoked from a menu item? Did you think
about setting the accelerator key when the menu item is created?

________________________________

Spencer

dhd81

unread,
May 6, 2009, 8:23:13 PM5/6/09
to MapInfo-L
Thank Spencer!
Timer event should be use to refresh data, track data change, track
form change (edit text box), track mouse over, key press ...and so on.
Using Integrated Mapping is more complexity and it's hard to get full
function in Mapinfo while MI and MB are all i need.
I used DDE to exchange data between MI and my App but it's not
comfortable and you have to know exactly name of MBX for the topic in
DDE section. Then setup Timer() via DDE is not steady. Is there any
function return app path ( MBX name) in MB ?

Spencer Simpson

unread,
May 7, 2009, 5:19:26 PM5/7/09
to mapi...@googlegroups.com

You're asking MapBasic to do more than it can do. What's worse, DDE events
won't be processed while a dialog is open, since it's modal by definition.

I'm not sure why you think you can't get some MapInfo functionality via
Integrated Mapping, since in that model, everything that can't be done with
Mapinfo.Do (i.e. Run Command) should be done by your client application.


As for finding a particular app via DDE:

First of all request a list sleeping MapBasic applications from MapInfo.

Once you have the list, you can check for your app in a couple of different
ways:

1. Very likely, the filename part of the MBX is fixed, and you hardcode that
value into the DDE client app. Use PathToFilename$ on each MBX path, and
compare to the hardcoded value. The first match is your app.

2. You could create a global string variable (e.g. gsAppFilename, which is
what the tool application sample does), set it in Sub Main, and use a DDE
Peek. Other applications can poke a different value, but it's difficult to
envision this happening other than intentionally.

3. You could add a RemoteQueryHandler to the MBX serving as the DDE server
and see if the remote query string matches a conventional value (e.g.
"AreYouMyVerySpecialMapBasicApplication?"), returning "Yes" if it matches
and something else otherwise. Then, the DDE client would "Peek" for the
identifying query string and if the return value is "Yes", Bob's your uncle.

dhd81

unread,
May 8, 2009, 12:05:13 PM5/8/09
to MapInfo-L
I'm using MB7.0 and don't see any function to request a list sleeping
MapBasic applications from MapInfo. Could you show me please. Thank
Spencer!

Peter Horsbøll Møller

unread,
May 8, 2009, 1:04:58 PM5/8/09
to mapi...@googlegroups.com
This should give you tab separated string of the running applications:
 
Dim i_channel As Integer, sApps As String
i_channel = DDEInitiate("MapInfo", "System")
sApps = DDERequest$(i_channel, "Topics" )
DDETerminate i_channel
 
The string could look like this:
System C:\Program Files\MapInfo\Professional\Tools\LayoutTmplt.MBX C:\Program Files\MapInfo\Professional\Tools\mapwiz.MBX C:\Program Files\MapInfo\Professional\UT\MUT.MBX
 
Note that you are asking for all topics. That includes System and all running MapBasic applications
 
You can find more information on this in the MapBasic User Guide in the chapter:
Inter-Application Communication Using DDE
 
Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo

2009/5/8 dhd81 <pash...@gmail.com>

dhd81

unread,
May 10, 2009, 9:05:32 PM5/10/09
to MapInfo-L
Thank Peter in advance !!!

On May 9, 12:04 am, Peter Horsbøll Møller <mapinf...@horsboll-
moller.dk> wrote:
>  This should give you tab separated string of the running applications:
>
> Dim i_channel As Integer, sApps As String
> i_channel = DDEInitiate("MapInfo", "System")
> sApps = DDERequest$(i_channel, "Topics" )
> DDETerminate i_channel
>
> The string could look like this:
> System C:\Program Files\MapInfo\Professional\Tools\LayoutTmplt.MBX
> C:\Program Files\MapInfo\Professional\Tools\mapwiz.MBX C:\Program
> Files\MapInfo\Professional\UT\MUT.MBX
>
> Note that you are asking for all topics. That includes System and all
> running MapBasic applications
>
> You can find more information on this in the MapBasic User Guide in the
> chapter:
> *Inter-Application Communication Using DDE*
>
> Peter Horsbøll Møller
> Pitney Bowes Business Insight - MapInfo
>
> 2009/5/8 dhd81 <pasho...@gmail.com>
Reply all
Reply to author
Forward
0 new messages