Personal tools
You are here: Home CodeGenerators
FrontPage >> MapInfoRoadmap >> MapBasicDevelopment >>

CodeGenerators

Document Actions
last edited 4 months ago by effayufa

A code generator is an application that writes code for you. Its main advantage is that it saves you time, and the resulting code is (or should be) bug-free. Not only does it save you time in typing, but it can also help you write code for things you don't remember how to do (like creating a thematic map.)

Two code generating tools for the MapBasic Editor are WorkspaceFiles and the MapBasicWindow?. When you save a workspace, all the MapBasic code needed to recreate the current map views, layer styles, window layouts, etc. are written to the workspace. A workspace file is nearly 100% MapBasic code. You can incorporate it all in your program to set up the initial environment, or you can cut and paste the parts you want into your program. Alternatively, you can open the MapBasic window in MapInfo, and as you perform actions through the menus, most of the steps are recorded in the MapBasic window in the form of ready-to-use MapBasic code.

If you use a good editor (like UltraEdit) you can also set up a predefined template to write commonly used sections of code for you. One such use is to create a template for building the framework for a new application. This would write a skeleton for the Main() function (with a working menu interface), the About() and Exit() subroutines and would set up a few common defined constants. The UltraEdit templates also allow the use of certain variables, so you can include comments with date, time and file name values.

One operation that fairly screams out for a code generator is creating dialog boxes. Building these with the MapBasic Editor is so tedious that it can put even a lert to sleep. One rather good solution to this is DiaBuilder 2000, an application written in Delphi by TreyPatillo.

You can also write code generators in MapBasic to generate MapBasic code. This goes beyond templates in that you can use variables as you like, or use MapInfo tables as input. For example, suppose you often needed code to create tables if they don't exist, or code to insert or update records. All you would need to do is create a table interactively with MapInfo and then feed that to your code generator. It would then create a function to create this table, and build the appropriate lines to insert or up update a record to this table. If you use a consistent convention for NamingVariables, it could even use the table data types to create declarations appropriate for variables that would be used in an insert or update SQL statement.

subtopics:


comments:

need help for mapbasic code --effayufa, Mon, 07 Jul 2008 20:24:10 -0500 reply
hi, can anyone help me to generate a code for my problem?i've try so many time to solve the problem but it doesn't work..my situation is i have 4 tables that include lot number..this 4 tables got the same table structure..i want find one of the lot number by key in the number but i don't know which table are locate this lot number..so how the code should be?i generate the code below but it doesn't work..when i compile it's successful but when i run the application this "variable or field no_lot not define" error appeared..please help me..i need it as soon as possible..if anybody can help me, please send the code to my e-mail..thanks..(whiztech_effa@yahoo.co.uk)

Sub KlangNL?

Dim i As Integer Dim k As String Create buttonpad "" as pushbutton icon mi_icon_misc_22 Calling KlangNL? HelpMsg? "Tekan Butang Ini Untuk Ke Menu USB\n Menu USB" Alter ButtonPad? "" Fixed Show Width 2

Dialog Title " NOMBOR LOT " Position 05, 100 Width 120 Height 90 Control StaticText? Title "Sila Pilih Nama Mukim:" Position 14, 15 Control PopUpMenu? Title " Kapar; Klang; Menu Sebelum; Menu Utama; Keluar;" Value 6 Width 90 Value i Into i Id 1 Position 14, 25 Control StaticText? Title "Sila Taipkan Nombor Lot:" Position 14, 45 Control EditText? Position 14, 55 Width 90 Value "1234" Into k Control OKButton? ID 2 Enable Control CancelButton? If commandinfo (cmd_info_dlg_ok) then If i = 1 then Close All Run Application "D:\USB_JPS\WORKSPACE\WORKSPACE_KLANG.WOR" If no_lot = k then SELECT * from lot_tanah_kapar WHERE no_lot = k and nama_mukim = "Kapar" into Kapar BROWSE * from Kapar Title " LOT KAWASAN " ElseIf? no_lot = k then SELECT * from lot_tanah_kapar_k2 WHERE no_lot = k and nama_mukim = "Kapar" into Kapar BROWSE * from Kapar Title " LOT KAWASAN " ElseIf? no_lot = k then SELECT * from lot_tanah_kapar_k3 WHERE no_lot = k and nama_mukim = "Kapar" into Kapar BROWSE * from Kapar Title " LOT KAWASAN " ElseIf? no_lot = k then SELECT * from lot_tanah_kapar_k4 WHERE no_lot = k and nama_mukim = "Kapar" into Kapar BROWSE * from Kapar Title " LOT KAWASAN " If lot_tanah_kapar_k4.no_lot<> k then Note "Maaf. Nombor Lot Tersebut Tiada Dalam Senarai!" call KlangNL? 'Else End If End If

Set Window FrontWindow?() Run menu command M_ANALYZE_FIND_SELECTION 'Run menu command M_WINDOW_TILE

Elseif i = 2 then Close All Run Application "D:\USB_JPS\WORKSPACE\WORKSPACE_KLANG.WOR" SELECT * from lot_tanah_klang WHERE no_lot = k and nama_mukim = "Klang" into Klang BROWSE * from Klang Run menu command M_ANALYZE_FIND_SELECTION Run menu command M_WINDOW_TILE Set window frontwindow () Title " LOT KAWASAN " If lot_tanah_klang.no_lot<> k then Note "Maaf. Nombor Lot Tersebut Tiada Dalam Senarai!" call KlangNL? 'Else End If

Elseif i = 3 Then Call KlangLT? Elseif i = 4 Then Call Menu Elseif i = 5 Then Call ConfirmBye? End If End If

End Sub

« December 2008 »
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
 

Powered by Plone, the Open Source Content Management System

This site conforms to the following standards: