alias for tables in mapbasic querying

522 views
Skip to first unread message

B

unread,
Nov 10, 2009, 1:38:30 AM11/10/09
to MapInfo-L
i am writing some mapbasic code and i am experiencing some issues -
hopefully somewhere can provide advice on solving it.

by using the 'FileSaveAsDLG' command to prompt a user to name a table
and its location to save it to i am able to assign this to a alias
name, so regardless of what the user names their table i can recall
the alias name and use it later in the code.

i get the user to add in a polygon to this table they created and then
call the first record and find its MBR value (code shown below where
xmax etc are variables as well) aliastable is the table the user
creates but because of the filesaveasdlg command i aliased it with a
new name

xmax=objectgeography(aliastable.obj, OBJ_GEO_MAXX)
xmin=objectgeography(aliastable.obj, OBJ_GEO_MINX)
ymax=objectgeography(aliastable.obj, OBJ_GEO_MAXY)
ymin=objectgeography(aliastable.obj, OBJ_GEO_MINY)

when i attempt to run this i get the following error

Found(.) while searching for()) which occurs on the first line shown
here

I am confident i am not approaching this in the most efficient way and
my best guess is the code can not have a obj related function attached
to an alias??? not sure any advice is welcomed.

cheers
b

Peter Horsbøll Møller

unread,
Nov 10, 2009, 3:14:19 AM11/10/09
to mapi...@googlegroups.com
B,

You need to use an Alias variable to hold both the table and column name.
This could be a way to do it:

'..msTab is a string variable declared outside
'..your subs and functions at the top of the module

Dim msTab As String

Sub OpenTableToUse
  sTabFile = FileOpenDlg("", "", "TAB", "Please select table...")

  msTab = PathToTableName$(sTabFile)

  Open Table sTabFile
End Sub

'...somewhere else in you code

Sub GetMBRFromObj
  Dim aObj As Alias

  '..here you set the alias variable to point at a certain table/column combination
  aObj = msTab + ".obj"


  Fetch First From msTab
  xmax=objectgeography(aObj, OBJ_GEO_MAXX)
  xmin=objectgeography(aObj, OBJ_GEO_MINX)
  ymax=objectgeography(aObj, OBJ_GEO_MAXY)
  ymin=objectgeography(aObj, OBJ_GEO_MINY)
End Sub

I hope you can see the idea behind this

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo


2009/11/10 B <roadru...@gmail.com>

B

unread,
Nov 12, 2009, 11:02:57 PM11/12/09
to MapInfo-L
peter,

i added in the two lines

Dim aObj As Alias
aObj = surveyarea + ".obj"

as suggested but it has issues when trying to read the surveyarea
table (code of the sub in question shown below)

sub surveypoints
Dim aObj As Alias
aObj = surveyarea + ".obj"
fetch first from surveyarea (error occurs on this line saying "table
surveyarea not found" this is a gloabl variable i assigned a table to
in the previous sub)
xmax=objectgeography(aObj, OBJ_GEO_MAXX)
xmin=objectgeography(aObj, OBJ_GEO_MINX)
ymax=objectgeography(aObj, OBJ_GEO_MAXY)
ymin=objectgeography(aObj, OBJ_GEO_MINY)
dialog
title "Survey Points"
control statictext
title "Enter number of survey points"
control edittext
into pointdata
control OKButton
if CommandInfo (CMD_INFO_DLG_OK)then
call surveydata
End If
end sub


Peter Horsbøll Møller

unread,
Nov 13, 2009, 2:21:48 AM11/13/09
to mapi...@googlegroups.com
Is the table open?
Maybe you should consider prefixing your variables as "surveyarea" could be the real name of the table.
 
For modular string variables I would recommend that you prefix them with "ms" and as this is a table you could ad "Tab" to that. So the name of the variable could be changed to "msTabSurveyArea".
 
Just a suggestion, but that makes it easier to read the code later. 
 

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo

 
2009/11/13 B <roadru...@gmail.com>
Reply all
Reply to author
Forward
0 new messages