Function SelTabInMap( )

Purpose
Returns the name of the table selected among all the tables displayed in a mapper
 
Author Date of code (original) Updated on Date of page (original) Updated on
J.Paris
03Mar01

03Mar01

 
Restrictions on use
This module is distributed under the terms of the Lesser GNU General Public License. Restrictions on the use of this work in a commercial application or derivative work is described in the Lesser GNU General Public License page at: http://www.fsf.org/copyleft/lesser.html
 
Description
The program passes to the function the id of a mapper window. The user chooses a table among all those present in the mapper.
 
External resources
 
Declare statement of sub_function. Include in your program. Copy/Paste if needed.
declare function seltabinmap(byval winid as integer) as string
 
Returned value(s) (function only)
Name of selected table as a string
 
Other required declare statement(s). Include in your program. Copy/Paste if needed.
If not already required by program: include "mapbasic.def"
 
MapBasic Code. Copy/Paste if needed.
function seltabinmap(byval winid as integer) as string

' Returns as a string the name of the table selected among those
' displayed in the mapper specified by its window id "winid"
 
dim listtab as string
dim nlay,i,indtab,iplace,jplace as smallint

if str$(windowinfo(winid,win_info_type))<>"1"then
' following note could be commented out
   note "Window is not a mapper"
   exit sub
end if

seltabinmap=""
nlay=mapperinfo(winid,mapper_info_layers)
for i=1 to nlay
   listtab=listtab+layerinfo(winid,i,layer_info_name)+";"
next

dialog title "Tables in Mapper"
   control statictext title "Select a table then OK"   position 13,5
   control statictext title "or CANCEL"    position 28,15
   control listbox title from variable listtab value 1 into indtab
   control okbutton
   control cancelbutton

if not commandinfo(cmd_info_dlg_ok) then exit sub end if
jplace=1
for i=1 to indtab   
   iplace=jplace+1
   jplace=instr(iplace,listtab,";")
next     
if indtab=1 then iplace=1 end if

seltabinmap=mid$(listtab,iplace,jplace-iplace)

end function
 
Availability for download
Tables.zip
 
Example
include "mapbasic.def"
dim atable as string
dim iwin as integer

if numwindows()=0 then        
   note "No windows open"
   exit sub
end if        

iwin=frontwindow()

atable=seltabinmap(iwin)     

if atable ="" then
   print "No table was selected"
else
   print atable
end if
 
Comments
 
See also