SelOpenTab()

Purpose
Helps choosing one among all the open tables
 
Author Date of code (original) Updated on Date of page (original) Updated on
Jacques Paris
jakes.paris@sympatico.ca
11Feb2001

18Feb2001

 
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
Opens a requester displaying all open tables (choice offered between mappable only and all of them) and returns the name of the selected table. If only one "potential" table exists, its name is returned without requester.
 
External resources

 
Declare statement of sub_function. Include in your program. Copy/Paste if needed.
declare function SelOpenTab (
   byval mappabl 'logical value TRUE=mappable maps only
   ) as string

 
Returned value(s) (function only)
    ""        (blank) no file selected
    string    selected file name
 
Other required declare statement(s). Include in your program. Copy/Paste if needed.
 
MapBasic Code. Copy/Paste if needed.
include "mapbasic.def"

function SelOpenTab(byval mappabl as logical) as string

dim TableNames(0) as string
dim i, result, NumberOfTables, TableIndex as smallint

' *************** get the name of an open Table
NumberOfTables = 0
SelOpenTab=""

if NumTables()>0 then
   if mappabl then
      for i=1 to NumTables()
         if TableInfo(i,TAB_INFO_MAPPABLE) then
         NumberOfTables = NumberOfTables+1   
         ReDim TableNames(NumberOfTables)
         TableNames(NumberOfTables) = TableInfo(i,TAB_INFO_NAME)
         end if
       next  
       if NumberOfTables=0 then
          Note "No mappable table found!"
          SelOpenTab=""
          exit sub
       end if
     else    
       for i=1 to NumTables()
          NumberOfTables = NumberOfTables+1   
         ReDim TableNames(NumberOfTables)
         TableNames(NumberOfTables) = TableInfo(i,TAB_INFO_NAME)
         next
     end if
   else   
       Note "No tables open!"  
       SelOpenTab=""
       exit sub
end if
              
if NumberOfTables=1 then SelOpenTab=TableNames(1) exit sub end if
TableIndex = 1

 Dialog Title "Choose a table"
  Control ListBox Title from variable TableNames
    Value TableIndex Into TableIndex
  Control OKButton
  Control CancelButton
 if not CommandInfo(CMD_INFO_DLG_OK) then Exit Sub end if

SelOpenTab=TableNames(TableIndex)

end function
 
Availability for download
Tables.zip
 
Example
include "mapbasic.def"
declare sub main
declare function TabNeedPack(tabname as string) as smallint
declare function SelOpenTab(byval mappabl as logical) as string
'=====================================================

sub main

dim nametab as string
dim result as smallint
dim mapp as logical

mapp=ask("Select only among mappable tables?","Yes","No")

nametab=SelOpenTab(mapp)     
if nametab="" then exit sub end if

result=TabNeedPack(nametab)

do case result
   case 1
   note nametab + " does not require packing"
      case 2
     note nametab + " contains records without object"
     case 3
     note nametab + " requires packing (there are deleted records)"
     case 4
     note nametab + " requires packing (there are deleted records)" +chr$(10)+ " and contains records without object"  
     case else
     note"Some trouble was encountered dealing with "+nametab
end case

end sub
 
Comments
This example calls also on the TabNeedPack() function
 
See also