MapBasic specific selection code help

913 views
Skip to first unread message

Canuck

unread,
Jul 20, 2012, 8:34:05 AM7/20/12
to mapi...@googlegroups.com

I am building a very simple MapBasic program, but I am stuck on a specific detail of the code for the SQL query part of the code.

What the code does:  Very simple - I have 2 tables.  The first table is just a polyline layer and each polyline has an "ID" and that is it.  
The second table is just a browser where the data for each polyline is stored.  The 2 tables of course have the same corresponding ID's, in a one-to-many rato (1 polyline can have upto 244 records from the browser)

I have a push button setup, so that when you choose this button and then select the polyline you want, it queries the second table, and opens a browser with all of the corresponding data for the selected polyline.

Simple enough.

My issue:

I would like the query to be able to read the ID of the polyline selected, and then put that ID in the select statement Where Condition: 
polyline_ID = polylinedata_ID and polyline_ID = "X X X X" (whatever the selected polyline ID is)

I would also like the selected ID of the polyline to be inserted in the "into Table Named:" part of the SQL Select statement, that way each browser that is generated will have the associated ID, instead of Query 1, then Query 2 etc as other polylines are selected.

So the polyline ID is basically like a wild-card and is read when selected and inserted into the query.  

I think it is simple enough, but I'm having the hardest time figuring it out.

Any help would be appreciated

Much thanks
Ryan



Thomas Bacon

unread,
Jul 20, 2012, 8:49:22 AM7/20/12
to mapi...@googlegroups.com

Hi Ryan,

 

You can get selection information from the SelectionInfo( ) function:

 

Dim sSelName as String

Dim aSelID as Alias

Dim nID as Integer

 

sSelName = SelectionInfo(SEL_INFO_SELNAME)      'Get the name of the selection table

aSelID = sSelName & ".polyline_ID"              'Set an alias to your polyline ID column in the selection table

 

If SelectionInfo(SEL_INFO_NROWS) = 1 then       'Check how many records in selection. If 1 then:

      Fetch first from sSelName                 'Get first record

      nID = aSelID                              'Get ID from selection and store in variable

     

      Select * from DataTable where polylinedata_ID = nID into "OutTable_" & nID    'Select from data table where ID matches

     

Else

      'Greater than or less than 1 polyline selected

End if

 

This assumes that your ID column is an Integer type and that you only want to deal with selections of 1 object. You may need to make some small alterations to get this to fit your data.

 

Hope this helps,

 

Tom Bacon

GIS Engineer | Asset Management South

The Mouchel Group

37-39 Perrymount Road, Haywards Heath, West Sussex RH16 3BN

 

Office: 01444 472330

Direct: 01444 472380


--
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



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. Mouchel Limited, Registered in England at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX Registered No : 1686040

Canuck

unread,
Jul 20, 2012, 8:57:21 AM7/20/12
to mapi...@googlegroups.com
This is great Thanks!

My ID's are not integer, they are character and numeric mix, so the field is Character(20) on both, but I think this will definitely point me in the right direction

I'll look up these functions in the MapBasic help files as well now that I know what to look for and I'm sure this will help me out.  

Again, thanks for your help, and very fast response!

Ryan


On Friday, July 20, 2012 8:49:22 AM UTC-4, Tom Bacon wrote:

Hi Ryan,

 

You can get selection information from the SelectionInfo( ) function:

 

Dim sSelName as String

Dim aSelID as Alias

Dim nID as Integer

 

sSelName = SelectionInfo(SEL_INFO_SELNAME)      'Get the name of the selection table

aSelID = sSelName & ".polyline_ID"              'Set an alias to your polyline ID column in the selection table

 

If SelectionInfo(SEL_INFO_NROWS) = 1 then       'Check how many records in selection. If 1 then:

      Fetch first from sSelName                 'Get first record

      nID = aSelID                              'Get ID from selection and store in variable

     

      Select * from DataTable where polylinedata_ID = nID into "OutTable_" & nID    'Select from data table where ID matches

     

Else

      'Greater than or less than 1 polyline selected

End if

 

This assumes that your ID column is an Integer type and that you only want to deal with selections of 1 object. You may need to make some small alterations to get this to fit your data.

 

Hope this helps,

 

Tom Bacon

GIS Engineer | Asset Management South

The Mouchel Group

37-39 Perrymount Road, Haywards Heath, West Sussex RH16 3BN

 

Office: 01444 472330

Direct: 01444 472380

Thomas Bacon

unread,
Jul 20, 2012, 9:02:08 AM7/20/12
to mapi...@googlegroups.com

You’re welcome. Oh, and don’t forget to add:  Include “MapBasic.def” 

 

at the top of your code (outside of any subprocedures) for the definitions of the SelectionInfo parameters.

 

Regards,

 

Tom Bacon

GIS Engineer | Asset Management South

The Mouchel Group

37-39 Perrymount Road, Haywards Heath, West Sussex RH16 3BN

 

Office: 01444 472330

Direct: 01444 472380

Ryan Richter

unread,
Jul 20, 2012, 9:55:50 AM7/20/12
to mapi...@googlegroups.com
Yes, I have all those MapBasic.def files included that I need.

One last question.

I have a small sub routine I want to implement.  When the button is selected to choose a polyline to get the information, I want to turn OFF the SELECT ability for any other open tables other than the polyline layer that this button will use to get the information (This will prevent them from accidentally selecting from the wrong layer and generating errors).

I cannot know how many other layers a user may have open or the position of my specific polyline layer in the map , so I cannot really just use:

Set Map
Layer 1 Selectable Off
Layer 2 Selectable On (assume this would be my polyline position for this MapInfo session)
Layer 3 Selectable Off
Layer 4 Selectable Off
Layer 5 Selectable Off
etc
etc

The MapBasic help does not provide any info on the right-mouse-click function of "Make Other Layers Non-Selectable"

I want to make the polyline layer selectable, and turn off this ability for ALL open tables, regardless of how many they have open.

Any thoughts?

Again, I really appreciate you taking time from your day to help me with this.  As you can tell, I am a beginner, and I am slowly learning all of these functions, but if it is not in the help files, then I am really stumped.  I want to make this little program as hassle free as possible for people who will be using it.

Thanks
Ryan

--
"Touched by his noodly appendage"
       
        He boiled for our sins.


Thomas Bacon

unread,
Jul 20, 2012, 10:10:39 AM7/20/12
to mapi...@googlegroups.com

Hi Ryan,

 

I would use the following functions (check out the MapBasic reference guide, it’s got some great examples and details all the functions available to you in MapBasic):

 

FrontWindow( )  - Gets the window ID of the front window

WindowInfo(WIN_INFO_TYPE)  - Get the window type (you want it to be WIN_MAPPER otherwise you haven’t got a map window as your front window)

MapperInfo(MAPPER_INFO_LAYERS)  - Get the number of layers in the map window

LayerInfo(LAYER_INFO_NAME)  - Get the name of a layer.

 

If you test the frontwindow ID and it is a Map window, then get the number of layers in the window. Then loop through the layers and set selectable OFF for all those which aren’t the polyline layer. This does assume that you know the name of the polyline layer (remember a table name is limited to 31 characters, so if the filename is longer than this you only want the first 31 characters).

 

Hope this helps,

 

Tom Bacon

GIS Engineer | Asset Management South

The Mouchel Group

37-39 Perrymount Road, Haywards Heath, West Sussex RH16 3BN

 

Office: 01444 472330

Direct: 01444 472380

Thomas Bacon

unread,
Jul 20, 2012, 10:15:15 AM7/20/12
to mapi...@googlegroups.com

In fact you can use SelectionInfo(SEL_INFO_TABLENAME) to get the name of the layer that the selection was based on.

 

 

Tom Bacon

GIS Engineer | Asset Management South

The Mouchel Group

37-39 Perrymount Road, Haywards Heath, West Sussex RH16 3BN

 

Office: 01444 472330

Direct: 01444 472380


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. Mouchel Limited, Registered in England at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX Registered No : 1686040

Ryan Richter

unread,
Jul 20, 2012, 11:13:50 AM7/20/12
to mapi...@googlegroups.com
Thanks again, and thanks for that updated reference file.  I am slowly piecing it all together, my syntax skills are also quite basic,

I don't know if the SelectionInfo will be the way to go, because I want to have all of the layers turned off except for the polyline layer BEFORE they use my tool to make their polyline selection.  I want all the layers to be setup correctly, that way my polyline layer is the only option that my tool can be used to select from.  

I really appreciate the help :)

Thanks
Ryan

Sivert

unread,
Jul 21, 2012, 6:28:49 AM7/21/12
to mapi...@googlegroups.com
In this case I would use the SearchInfo() function!
Then you don't have to make any layers unselectable.
Use SearchPoint() function and then SearchInfo() to
check if you hit the 'right' table, (like the Info-tool).

Sivert
Reply all
Reply to author
Forward
0 new messages