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?


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
  • Perfect! Thank you, for further reference, crashes still occurred and I've worked out with a wait time of 5 seconds approx 40 sheets could be printed before a crash. Increasing the time to 7.5 seconds led me to printing the last 50 without issue – Alan Carr Oct 26 '15 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.