TransWikia.com

'Slowing down'/wait MapBasic

Geographic Information Systems Asked by Alan Carr on December 19, 2020

I have written a script to go through each layer in MapInfo (from 1 to 168), turn layer 1 on, style it, label it, print, turn layer off, then the same for layer 2,3,4 etc. The printing works, however I think it’s going a bit too fast for MapInfo/the printer and will crash every 25-30 pages, to fix this I am removing my printed layers and tweaking my variables.

I’ve had a google and from what I can see there is no wait function in MapBasic, is there something else I can do? E.g having it perform a pointless task just to kill a bit of time between pages so the printer does not get overloaded?

2 Answers

You could use the WinAPI function Sleep to let you application rest for a given number of milliseconds:

Here's the MapBasic declaration:

Declare Sub WAPISleep Lib "kernel32.dll" Alias "Sleep"
    ( ByVal dwMilliseconds As Integer
    )

And you basically just call it from your application when you want the app to wait a while:

Call WAPISleep(2000)  'take a 2 secs nap before continuing

Correct answer by Peter Horsbøll Møller on December 19, 2020

I've just had a similar problem. I wrote code in the MapBasic window to create and populate a layout, export it as a PNG and repeat with more layouts. The code worked when I executed each line individually but the exported PNG's were blank when the code was executed all in one go, so it obviously needed some delays to be forced. I tried using Peter's method but I couldn't get it to work (but thank you all the same, Peter) so I wrote a much more primitive method which I'm sharing in case it's useful to anyone else who needs this thread. Where I needed a delay in my code I simply inserted the following line:
note "Click OK"
Yes, it means that the user has to click "OK" for every iteration but for less than 50 pages it's a solution that is suficient for what I need.

Answered by Reg Halstead on December 19, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP