Closing all map and table windows with MapBasic!

678 views
Skip to first unread message

Alan Carr

unread,
Apr 2, 2014, 9:38:54 AM4/2/14
to mapi...@googlegroups.com
Short but sweet, I couldn't find this in the MB_REF, is there a way I can close all open table and map windows using MapBasic?

Cheers,
Alan 

Alan Carr

unread,
Apr 2, 2014, 9:44:23 AM4/2/14
to mapi...@googlegroups.com
Just made a loop using NumWindows(), so now I just need to know if there's a quicker way?

Thomas Bacon

unread,
Apr 2, 2014, 9:45:46 AM4/2/14
to mapi...@googlegroups.com

Hi Alan,

 

You can either:

 

1)      Include menu.def at the top of your code and use: Run Menu Command M_FILE_CLOSE_ALL

2)      Loop through all open tables and close them:

 

Dim i as Integer

For i = NumTables() to 1 Step -1

              Close Table TableInfo(i,TAB_INFO_NAME)

Next

 

Regards

 

Tom Bacon

GIS Engineer, Mouchel

T 01444 472380 │ E thomas...@mouchel.com W www.mouchel.com

Our values: innovation │ excellence │ integrity │ responsibility

--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



 

Mouchel Limited (Mouchel) is registered in England and Wales with registered number 01686040 at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX.  The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. No contracts may be concluded on behalf of Mouchel by means of email communications. Mouchel reserves the right to monitor and intercept emails sent and received on our network. 

Alan Carr

unread,
Apr 2, 2014, 9:47:45 AM4/2/14
to mapi...@googlegroups.com
Hi Tom,

I just want to close windows, not the tables themselves


On Wednesday, April 2, 2014 2:38:54 PM UTC+1, Alan Carr wrote:

Thomas Bacon

unread,
Apr 2, 2014, 9:48:01 AM4/2/14
to mapi...@googlegroups.com

Sorry, just realised you meant windows, not tables. I think your method of looping through the windows using NumWindows() to get the count is the only way, there is no menu shortcut.

 

Tom Bacon

GIS Engineer, Mouchel

T 01444 472380 │ E thomas...@mouchel.com W www.mouchel.com

Our values: innovation │ excellence │ integrity │ responsibility

 

Alan Carr

unread,
Apr 2, 2014, 9:53:52 AM4/2/14
to mapi...@googlegroups.com
Just tried the loop and it didn't work! I think it's because MapInfo has a weird way of numbering! 

I think for now I'll just close all the tables, re-open the ones I need then add both to the same map with a Map From statement

Thomas Bacon

unread,
Apr 2, 2014, 9:57:25 AM4/2/14
to mapi...@googlegroups.com

Alan, you need to work backwards from the last to the first:

For i = NumWindows() to 1 Step -1

 Error! Filename not specified.

Mouchel Limited (Mouchel) is registered in England and Wales with registered number 01686040 at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX.  The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. No contracts may be concluded on behalf of Mouchel by means of email communications. Mouchel reserves the right to monitor and intercept emails sent and received on our network. 

--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Thomas Bacon

unread,
Apr 2, 2014, 10:03:28 AM4/2/14
to mapi...@googlegroups.com

To expand on that, if you do it incrementally in the ‘forward’ direction then each time you close a table the window indices shift to fill the gap. So if you close the window at index 1 then index 2 shifts down to fill index 1, index 3 moves to 2, etc… So to avoid this, you start at the top and that way the indices never shift. Hope that makes sense.

Greg

unread,
Apr 2, 2014, 10:35:45 AM4/2/14
to mapi...@googlegroups.com
Window IDs don't necessarily go 1,2,3.  You should use somehting like this (untested):
 

for x=1 to NumWindows()

close window windowinfo(x, WIN_INFO_WINDOWID)

next

 
Greg
Message has been deleted

James Moloney

unread,
Apr 2, 2014, 6:54:32 PM4/2/14
to mapi...@googlegroups.com
Hi Alan,
 
This will do what you are after. I have included print statements to explain what is going on
 
Hope this helps
 
Cheers
 
James
 
 
Include "Mapbasic.def"
 
Declare Sub Main
 
Sub Main
 
   Print "Number of Open Windows is " & NumWindows()
 
   Do While NumWindows() > 0
 
      Print "Closing Window " & NumWindows() & " with WinID as " & WindowInfo(NumWindows(), WIN_INFO_WINDOWID) & " Type " & WindowInfo(NumWindows(), WIN_INFO_TYPE)
 
      Close Window WindowInfo(NumWindows(), WIN_INFO_WINDOWID)
 
   Loop
 
End Sub
Reply all
Reply to author
Forward
0 new messages