9d: intro to mapbasic for the non-programmer - downloads

28
9D: Intro to MapBasic for the non-programmer Jim Regan Senior Consultant Pitney Bowes Software – Global Services

Upload: others

Post on 12-Sep-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 9D: Intro to MapBasic for the non-programmer - Downloads

9D: Intro to MapBasic for the non-programmer

Jim Regan

Senior Consultant

Pitney Bowes Software – Global Services

Page 2: 9D: Intro to MapBasic for the non-programmer - Downloads

Who am I ?

• Jim Regan

• Senior Consultant, Pitney Bowes Software, Global Services

• 14+ years at MapInfo/Pitney Bowes Software

• Training

• Developer Services

• Professional Services

• Global Services

[email protected]

Page 3: 9D: Intro to MapBasic for the non-programmer - Downloads

Agenda

• What is MapBasic

• Who can use MapBasic

• What you can do with MapBasic

• MapBasic in MapInfo Professional

• MapBasic applications

Page 4: 9D: Intro to MapBasic for the non-programmer - Downloads

What Is MapBasic?

• Full-featured programming language with over 300 statements and functions

• Works in conjunction with MapInfo Professional

• MapBasic applications need MapInfo Professional ( or MapInfo Professional runtime) in order to run

• MapBasic programs take advantage of all of MapInfo Professional’s features and geographic data-management capabilities

Page 5: 9D: Intro to MapBasic for the non-programmer - Downloads

Who can use MapBasic

• MapInfo Professional users

• Novice

• Intermediate

• Power

• MapBasic Programmers

Page 6: 9D: Intro to MapBasic for the non-programmer - Downloads

What you can do with MapBasic

• Change the menu and toolbars

• Automate repetitive tasks

• Add functionality

Page 7: 9D: Intro to MapBasic for the non-programmer - Downloads

MapBasic in MapInfo Professional

• SURPRISE!!!!! You have already been using MapBasic by just using MapInfo Professional

• Every time you open a workspace, you are actually running a series of MapBasic commands

• The menus are created through MapBasic commands

• The MapBasic window shows “behind the scenes”commands

Page 8: 9D: Intro to MapBasic for the non-programmer - Downloads

Where Does MapBasic Exist

• MapBasic Window

• Accessed via the Options > Show MapBasic Window menu option in MapInfo Professional

• MapInfo Workspaces

• *.WOR

• MapInfo Menu File

• C:\Program Files\MapInfo\Professional\MAPINFOW.MNU

• MapBasic Applications

• *.MB - MapBasic source code

• *.MBX - Compiled MapBasic executable file

Page 9: 9D: Intro to MapBasic for the non-programmer - Downloads

MapBasic Window

Page 10: 9D: Intro to MapBasic for the non-programmer - Downloads

MapBasic Window

• A Window and A Door

• View Commands

• Run Command(s)

• Type or paste text into the window

• Save Text

Page 11: 9D: Intro to MapBasic for the non-programmer - Downloads

MapInfo Workspaces

Page 12: 9D: Intro to MapBasic for the non-programmer - Downloads

MapInfo Workspace

• Text file

• Series of MapBasic commands to open tables and arrange data views

• Easy to read* (Individual descriptions may vary)

• Useful to learn MapBasic syntax and statements

• Consider copying / pasting MapBasic statements from a workspace into a program or MapBasic window

• Consider modifying a Workspace to perform additional commands when it is loaded

Page 13: 9D: Intro to MapBasic for the non-programmer - Downloads

Workspaces - 9D_MapWorld2008.wor ( 1 of 2 )

!Workspace

!Version 600

!Charset WindowsLatin1

Open Table "Data\gazmaj" As gazmaj Interactive

Open Table "Data\ocean" As ocean Interactive

Open Table "Data\STATES" As STATES Interactive

Open Table "Data\World" As World Interactive

Set Window MapBasic

Position (2.59375,6.22917) Units "in"

Width 7.22917 Units "in" Height 1.5625 Units "in"

Open Window MapBasic

Map From gazmaj,STATES,World,ocean

Position (0.0520833,0.0520833) Units "in"

Width 10.3438 Units "in" Height 6.85417 Units "in"

Set Window FrontWindow() ScrollBars Off Autoscroll On

Set Map

CoordSys Earth Projection 1, 62

Center (-73.46802886,44.1447105)

Zoom 2633.012886 Units "mi"

Preserve Zoom Display Zoom

Distance Units "mi" Area Units "sq mi" XY Units "degree"

Set Map

Layer 1

Display Global

Page 14: 9D: Intro to MapBasic for the non-programmer - Downloads

Workspaces - 9D_MapWorld2008.wor ( 2 of 2 )

Global Pen (1,2,0) Brush (2,16777215,16777215) Symbol (34,16711680,3,"MapInfo Symbols",256,0) Line (1,2,0) Font

("Arial",0,9,0)

Label Line Arrow Position Right Font ("Arial",0,9,0) Pen (1,2,0) With Place_Name

Parallel On Auto Off Overlap Off Duplicates On Offset 2

Visibility On

Layer 2

Display GlobalGlobal Pen (1,2,7368816) Brush (2,16777072,16777215) Symbol (35,0,12) Line (1,2,0) Font ("Arial",0,9,0)

Label Line None Position Center Font ("Arial",0,9,0) Pen (1,2,0)

With State_Name

Parallel On Auto Off Overlap Off Duplicates On Offset 2

Visibility OnLayer 3

Display Global

Global Pen (1,2,9474192) Brush (2,16768112,16777215) Symbol (35,0,12) Line (1,2,0) Font ("Arial",0,9,0)

Label Line None Position Center Font ("Arial",0,9,0) Pen (1,2,0) With Country

Parallel On Auto Off Overlap Off Duplicates On Offset 2

Visibility On

Layer 4

Display GraphicGlobal Pen (1,2,0) Brush (2,16777215,16777215) Symbol (35,0,12) Line (1,2,0) Font ("Arial",0,9,0)

Label Line None Position Center Font ("Arial",0,9,0) Pen (1,2,0)

With Name

Parallel On Auto Off Overlap Off Duplicates On Offset 2

Visibility On

Page 15: 9D: Intro to MapBasic for the non-programmer - Downloads

MapInfo Professional Menu Definition

Page 16: 9D: Intro to MapBasic for the non-programmer - Downloads

MapInfo Menu File

• Series of MapBasic commands to arrange menu structure

• Sort of a MapBasic Program

• C:\Program Files\MapInfo\Professional\MAPINFOW.MNU

BE CAUTIOUS WHEN EDITING THIS FILE!!!!MAKE A BACKUP COPY (or TWO) BEFORE EDITING!!!

PLEASE BE CAREFUL!!!!!!

Page 17: 9D: Intro to MapBasic for the non-programmer - Downloads

Modifying the menu file

• Seriously…..be cautious when modifying this file!!!

Page 18: 9D: Intro to MapBasic for the non-programmer - Downloads

MapInfo Menu File

Create Menu "&File" ID 1 As

"&New Table...\tCtrl+N/W^N"

HelpMsg "Create a new table."

calling 101,

"&Open...\tCtrl+O/W^O"

HelpMsg "Open tables or workspaces."

calling 102,

"Open Web Service" As "Open Web Service",

"Open DB&MS Connection..."

HelpMsg "Connect to a DBMS server."

calling 125,

"(-",

"(&Close Table..."

HelpMsg "Close one or more tables."

calling 103,

Page 19: 9D: Intro to MapBasic for the non-programmer - Downloads

MapBasic Applications

Page 20: 9D: Intro to MapBasic for the non-programmer - Downloads

MapBasic Applications

• File Types

• *.MB – source code

• *.MBX – Compiled code

• Running MapBasic *.MBX programs

• An MBX needs a copy of MiPro to run (or MiPro runtime)

• To Launch• From File Explorer

• Run *.mbx ( file is linked to Mapinfow.exe)

• From within MapInfo Professional

• Tools > Run MapBasic Program menu option in MiPro

• Sources of MapBasic applications

• MapInfo Corporation

• MapInfo Partners

• Shareware

• Users

Page 21: 9D: Intro to MapBasic for the non-programmer - Downloads

Steps for Creating a Simple MapBasic Program

• Create Shell

• Write / “Steal” the Code

• Create Interface

• Run It

Page 22: 9D: Intro to MapBasic for the non-programmer - Downloads

Create Shell

• Every MapBasic program has a minimum amount of code to make a program

• Usually looks like this:

Declare Sub Main

Sub Main

‘ code goes here

End Sub

Page 23: 9D: Intro to MapBasic for the non-programmer - Downloads

Write/Steal The Code

• Use Code from the MapBasic Window, Workspaces

• Step Through Operations

• Save The Code

• Comment The Code

Page 24: 9D: Intro to MapBasic for the non-programmer - Downloads

Compile and Run the Program

• The MapBasic IDE needs to compile the application into a MBX before it can be run with MapInfo Professional

Page 25: 9D: Intro to MapBasic for the non-programmer - Downloads

Create the User Interface

• Determine data that has to be entered

• Determine best method by which to obtain the data

• Consider the user interface flow

Page 26: 9D: Intro to MapBasic for the non-programmer - Downloads

Looping• For… To…Step…Next

Dim how_many As Integer

For how_many=10 to 100 step 10

Note “the next number is:” + how_many

Next

• Do…Until/While…Loop

Do

Loop Until <condition>

• While <condition>

Wend

• Do While <condition>

Loop

Page 27: 9D: Intro to MapBasic for the non-programmer - Downloads

Review

• You have already been using MapBasic by using MapInfo Professional

• Every time you open a workspace, you run a series of MapBasic commands

• You can control the menus and toolbars using MapBasic commands in the MNU file

• You can view, learn, enter, and save MapBasic commands via the MapBasic window

Page 28: 9D: Intro to MapBasic for the non-programmer - Downloads

More Information on MapBasic…

• MapBasic Sample Applications

• Many good examples on how to accomplish specific tasks using MapBasic (C:\Program Files\MapInfo\MapBasic\Samples\)

• Product documentation found on PDF

• MapBasic User’s Guide

• MapBasic Knowledgebase

• http://testdrive.mapinfo.com

• MapInfo Training Classes

• http://www.mapinfo.com/training

• MapInfo User Group

• http://www.mapinfo.com/mipug