Declare Sub Main
Declare Sub MLB
Declare Sub PrintLayoutDefaultSettings
Declare Sub CreateMaps
Declare Sub LayoutPortrait
Declare Sub LayoutLandscape
Declare Sub MLBOKButton
Declare Sub SelectAllFromMLB
Declare Sub HighLightSelectedRegions
Declare Sub PopulateRegionsArray
Declare Sub About
Declare Sub End_Program
'Function to check whether a table is open or not
Declare Function TableIsOpen (ByVal sTabName As String) As Logica
' ///// Class "MBExtensions.MBDateAndTime" /////
' Allows you to retreive information from a MapBasic Date (i.e. YYYYMMDD) or
' DateTime (i.e. YYYYMMDDHHMMSSFFF) string
' Convert the string to it's equivalent long date string representation
' (depends on Control Panel > Regional and Language Options)
Declare Method RegionalLongDate
Class "MBExtensions.MBDateAndTime"
Lib "MBExtensions.dll" (ByVal sDateString as string) As String
The Main procedure contains the menu based code sample which will be updated to a ribbon based interface in due course.
The following variables are assigned as follows:-
sOutputFolder = ApplicationDirectory$() + "Output\"
sTabFile = ApplicationDirectory$() + "Tables\FR_Départements2006.TAB"
sTable = PathToTableName$(sTabFile)
sColA = "Nom_Région"
sColB = "Nom_Département"
sTabFile = ApplicationDirectory$() + "Tables\STATES.TAB" ' "Tables\FR_Départements2006.TAB"
sTable = PathToTableName$(sTabFile)
sColA = "State_Name" '"Nom_Région"
'sColB = "Nom_Département"
The above code allocates sTabFile to the States table and changes the State_Name to sColA. The sColB and information about the French map are disabled as they are only valid for the original code.
If CommandInfo(CMD_INFO_DLG_OK) Then
For l = 1 To Ubound(iRegionsSelectedArray)
sRegion = sRegionsArray(iRegionsSelectedArray(l))
sRegionTitle = "Map of " + sRegionsArray(iRegionsSelectedArray(l))
' "Les départements de la région " + sRegionsArray(iRegionsSelectedArray(l))
Call CreateMaps
Next
End If
Some original code is again commented out. Note that the only change is to the variable sRegionTitle.
'*********************************************************************************************
Sub PrintLayoutDefaultSettings
'*********************************************************************************************
OnError Goto ErrorHandler
sPrintDate = CurDate()
sPrintDate = RegionalLongDate(sPrintDate)
sCopyrightText = Chr$(169) + Chr$(32) + Year(CurDate()) + " - JPS Services"
' " - My wonderful team"
sFont = "Arial"
sAddressArray(1) = "JPS Services" '"My own company name"
sAddressArray(2) = "Southport" '"My own company address"
sAddressArray(3) = "07857 692628" '"My own company phone number"
sAddressArray(4) = "[email protected]" '"My own company email address"
sAddressArray(5) = '"www.jpsservices.org.uk" '"My own company website"
Exit Sub
'---------------------------
ErrorHandler:
Note Error$()
End Sub PrintLayoutDefaultSettings
In the CreateMaps the following code puts a company logo into the printed map. To update it choose an appropriate logo and overwrite the default and create a tab file for your own logo.
Open Table ApplicationDirectory$() + "My_own_company_logo.TAB"
Map From My_own_company_logo
iLogoWindowID = WindowID(FrontWindow())
Further in the code we need make a change as we do not need ColB when iterating through each State chosen in the States table.
Map From RegionSelected
iMapWindowID = WindowID(FrontWindow())
If iOrientation = 1 Then
Set Window FrontWindow() Position (0,0) units "cm" Width 19*fMp units "cm" Height 24.5*fMp units "cm"
ElseIf iOrientation = 2 Then
Set Window FrontWindow() Position (0,0) units "cm" Width 27.7*fMp units "cm" Height 15.8*fMp units "cm"
End If
Set Map Window iMapWindowID Zoom Entire Layer RegionSelected
'sCommand = "Set Map Window " + iMapWindowID + " Layer RegionSelected Label With " + sColB + " Auto Retry On"
sCommand = "Set Map Window " + iMapWindowID + " Layer RegionSelected Label With " + sColA + " Auto Retry On"
As mentioned this program holds the menu based code and some variables are initialised.
Sub MLB
This program creates a dialogue box which includes a MultiListBox box. Hence MLB as the name of the procedure. At the beginning of the code block an explanation is given regarding the ReadControlValue(). The code checks for an open table and whether there are any selections. After this PopulateRegionsArray is called.
Then for each selection the CreateMaps procedure is called.
PrintLayoutDefaultSettings
Here the various settings are used to populate each map.
Sub CreateMaps
This procedure creates the individual maps from, in this example, the States chosen by the user.
LayoutPortrait and LayoutLandscape
These two procedures create either a portrait or landscape layout for the maps depending on the user’s choice.
Sub MLBOK Button
Checks whether a State has been selected. Assigns the ReadControlValues.
Sub SelectAllFromMLB
Selects or deselects all the states.
Sub HighLightSelectedRegions
This procedure highlights any state which is selected by the user.
Sub PopulateRegionsArray
This procedure creates the array containing, in this example, all the States which will populate the MLB MultiListBox.
Sub About
Dialog box explaining the purpose of the program as well as its author.
Sub End_Program
Checks whether you want to close the program
Function TableIsOpen
Checks for whether a table is open or not and returns a logical True or False.
Method RegionalLongDate
The purpose of this method RegionalLongDate is covered within the program code.
Upgrading to the ribbon interface involves creating a definition file, a .mbp project file and modules for each of the functions and procedures. Additionally, we need to add several more folders to our project. One folder is named mb code to contain the modules, another Images for ribbon icons and then one more named Library which is saved within the mb code folder.
When created the set up should look like the following screen shot:-
Here is the PrintLayout.def:-
'** Project
'**
'** Definition file
'**
'** Author: Joseph Short
'** Date: 9th September 2017
'** Version: AppVersion (see below)
'************************************************************************************
Include "MAPBASIC.DEF"
Include "ICONS.DEF"
Include "MENU.DEF"
Include "Enums.def"
Include "Library\RIBBONLib.def"
Include "Library\MAPPERLib.def"
Declare Sub Main
Declare Sub MLB
Declare Sub PrintLayoutDefaultSettings
Declare Sub CreateMaps
Declare Sub LayoutPortrait
Declare Sub LayoutLandscape
Declare Sub MLBOKButton
Declare Sub SelectAllFromMLB
Declare Sub HighLightSelectedRegions
Declare Sub PopulateRegionsArray
Declare Sub About
Declare Sub End_Program
Declare Sub Endhandler
'Function to check whether a table is open or not
Declare Function TableIsOpen (ByVal sTabName As String) As Logical
' ///// Class "MBExtensions.MBDateAndTime" /////
' Allows you to retreive information from a MapBasic Date (i.e. YYYYMMDD) or
' DateTime (i.e. YYYYMMDDHHMMSSFFF) string
' Convert the string to it's equivalent long date string representation
' (depends on Control Panel > Regional and Language Options)
Declare Method RegionalLongDate
Class "MBExtensions.MBDateAndTime"
Lib "MBExtensions.dll" (ByVal sDateString as string) As String
Define AppName "Print Layout Ribbon Sample Code"
'Define AppNameMenu "Print &Layout"
Define AppVersion "0.60
'Defining Dialog Width and Height
'This allows you to specify width and height clauses in terms of characters (i.e., Width 30dW, Height 10dH).
Define dW *4 'Four dialog units equals one character in width
Define dH *8 'Eight dialog units equals one character in height
Define MLBID 1001
Define SelectAllMLBID 1002
Global sTabFile, sTable, sColA, sColB, sRegionsArray(), sAddressArray(5), sPrintDate, sCopyrightText, sFont, sRegion, sRegionTitle, sPrinterName, sDocTitle, sPapersize, sOutputFolder as String
Global iRegionsSelectedArray(), iPaperChoice, iPapersize, iLogoWindowID, iMapWindowID, iLayoutWindowID, iLayoutFontSize1, iLayoutFontSize2, iLayoutFontSize3, iLayoutFontSize4, iOrientation as Integer
Global fZoom, fMp, fPaper1, fPaper2, fPaperWidth, fPaperHeight, fHorizontalDistance, fVerticalDistance, fPos1, fPos2 As Float
Next we need to create the ribbon interface module. Here is the code for RibbonPrintLayoutInterface.mb to update the menu based version of PrintLayout.
'************************************************************************************
'** Project
'**
'** Module Sub Main
'**
'** Author: Joseph Short
'** Date: 9th September 2017
'** Version: AppVersion (see below)
'************************************************************************************
Include "PrintLayout.def"
Sub Main
sOutputFolder = ApplicationDirectory$() + "Output\"
sTabFile = ApplicationDirectory$() + "Tables\STATES.TAB" '"Tables\FR_Départements2006.TAB"
sTable = PathToTableName$(sTabFile)
sColA = "State_Name" '"Nom_Région"
'sColB = "Nom_Département"
Dim nCtrlIdx as Integer
Dim sTabName, sGroupName, marrModProgramsNames(), marrModProgramsImages() as Strin
' Check for the existence of the TAB named tabRibbonPrintLayoutApp
sTabName = "tabRibbonPrintLayoutApp"
If NOT RBNTabExists(sTabName) Then
nCtrlIdx = RBNAddTab(sTabName,"Ribbon Print Layout App","F")
If nCtrlIdx = 0 Then
Note "An error occurred whilst adding a new tab called + '" + sTabName + "' to the ribbon"
Exit Sub
End If
End If
sGroupName = "grpRibbonPrintLayoutApp"
If NOT RBNTabGroupExists(sTabName,sGroupName) Then
nCtrlIdx = RBNTabAddGroup(sGroupName, "Ribbon Print Layout",sTabName)
If nCtrlIdx = 0 Then
Exit Sub
End If
End If
ReDim marrModProgramsNames(1)
ReDim marrModProgramsImages(1)
marrModProgramsNames(1) = "Ribbon Print Layout Example"
marrModProgramsImages(1) = ApplicationDirectory$() + "\Images\Output.png"
nCtrlIdx = RBNGroupAddButton("RibbonPrintLayout", marrModProgramsNames(1),"",sTabName,sGroupName)
If nCtrlIdx > 0 Then
' Create and set the button tooltip
Call RBNControlSetToolTipIdx(nCtrlIdx,"Ribbon Print Layout App","Start module '" + marrModProgramsNames(1)+ "'","")
' Set the button icon
Call RBNControlSetIconsIdx(nCtrlIdx,CONTROL_SIZE_LARGE,"",marrModProgramsImages(1))
' Set Custom MapBasic handle to the button
Call RBNControlSetCustomMBXHandlerIdx(nCtrlIdx,"MLB")
End If
ReDim marrModProgramsNames(2)
ReDim marrModProgramsImages(2)
marrModProgramsNames(2) = "About example"
marrModProgramsImages(2) = ApplicationDirectory$() + "\Images\Info.png"
nCtrlIdx = RBNGroupAddButton("Aboutexample", marrModProgramsNames(2),"",sTabName,sGroupName)
If nCtrlIdx > 0 Then
' Create and set the button tooltip
Call RBNControlSetToolTipIdx(nCtrlIdx,"Ribbon Print Layout Example App","Start module '" + marrModProgramsNames(2)+ "'","")
' Set the button icon
Call RBNControlSetIconsIdx(nCtrlIdx,CONTROL_SIZE_LARGE,"",marrModProgramsImages(2))
' Set Custom MapBasic handle to the button
Call RBNControlSetCustomMBXHandlerIdx(nCtrlIdx,"About")
End If
Call RBNNotificationShow("Ribbon Print Layout Sample Code App", "Launching....", Notify_Info, 4000)
End Sub Main
Sub Endhandler
'Ask the RibbonHandler to tidy up before the app ends
Call RBNEndHandler
End Sub Endhandler
'** Project
'**
'** Module Sub Main
'**
'** Author: Joseph Short
'** Date: 9th September 2017
'** Version: AppVersion
'*******************************************************************************
Include "PrintLayout.def"
'*********************************************************************************************
Sub About
'*********************************************************************************************
Dialog
Title "About " + AppName + " (Version " + AppVersion + ")"
Control StaticText title "This application provides an example of how to use" Position 3dW, 1dH
Control StaticText title "the Ribbon interface in an automated map creation MapBasic application" Position 3dW, 2dH
Control StaticText title Chr$(169) + " 2017 - JPS Services with acknowledgement to Egge-Jan Pollé" Position 35dW, 6dH
Control OKButton Title "&Exit" Calling End_Program
Control CancelButton
End Sub About
Application=..\RibbonPrintLayout.mbx
Module=Library\ARRAYLib.mbo
Module=Library\DEBUGLib.mbo
Module=Library\ERRORLib.mbo
Module=Library\RIBBONLib.mbo
Module=RibbonPrintLayoutInterface.mbo
Module=About.mbo
Module=CreateMaps.mbo
Module=HighlightSelectedRegions.mbo
Module=LayoutLandscape.mbo
Module=LayoutPortrait.mbo
Module=MLB.mbo
Module=MLBOKButton.mbo
Module=PopulateRegionsArray.mbo
Module=PrintLayoutDefaultSettings.mbo
Module=SelectAllFromMLB.mbo
Module=End_Program.mbo
Module=TableIsOpen.mbo
Here is a screenshot of the program:-
In the next blog we will go to next stage which involves adding modules which will enable the user to create maps from either a single table or a workspace of their own choice. Additionally a module will be created for a dialogue box to update company details as required rather than having to modify code.