Calling modules

354 views
Skip to first unread message

Gabe

unread,
Nov 21, 2008, 2:05:27 PM11/21/08
to MapInfo-L
This should be a simple question, but I'm a bit of a beginner and i
can't seem to find any actual code examples of linking modules
together. In the MB User Guide, it touches on how to put modules
together, but I'm still having trouble. If someone can help me out,
or point me to a link with a good example, I would appreciate it.

I have made a menu bar, and instead of just calling a sub within the
program, I wanted to call code from a module for each of my options.
My problem is that I don't know how to call a procedure from outside
the program and still be able to compile to an .mbx instead of
an .mbo. I realize that I'll need to link the files with a Project
file, and probably use a .def file, but I'm not sure how to do it.
When I created a project file, and tried to link it, I got an error
telling me that I was "Missing main Sub" in my menu.mbx

The code for my menu bar, and first option are below.

Include "mapbasic.def"
Include "my_modules.def"

Declare Sub Main
Declare Sub Setup
Declare Sub DataCreation
Declare Sub Validate


Sub Main


Create Menu "Whatever Tool" As
"&Project Setup" Calling Setup,
"(-",
"&Data Creation" Calling DataCreation,
"(-",
"&Validate" Calling Validate,


Alter menu bar add "Whatever Tool"


End Sub

''''''''''''''''''''''''
Sub Setup

End Sub

''''''''''''''''''
Sub DataCreation

End Sub
''''''''''''''''
Sub Validate

End Sub

''''''''''''''''''''''''''''

Below is the code I would like to call for the setup option

Include "mapbasic.def"


Declare Sub GetAccessfile
Declare Sub GetRelayfile
Declare Sub GetUndefinedfile
Declare Sub GetAccessBufFile
Declare Sub Reset_Sub
Declare Sub Setup

Dim AccessPointFile as string
Dim RelayPointFile as string
Dim UndefinedPointFile as string
Dim AccessBuffers as string

Sub Setup

Dim s_title As String 'the title of the map


Dialog
Title "Setup"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Control StaticText
Title "Access Points:"
Position 5, 10


Control Button
Title "&Browse"
Calling GetAccessfile
Position 225, 8


Control EditText
Value AccessPointFile
ID 1
Position 65, 8 Width 150

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Control StaticText
Title "Relay Points:"
Position 5, 30

Control Button
Title "&Browse"
Calling GetRelayfile
Position 225, 28

Control EditText
Value RelayPointFile
Into s_title
ID 2
Position 65, 28 Width 150

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Control StaticText
Title "Undefined Points:"
Position 5, 50

Control Button
Title "&Browse"
Calling GetUndefinedfile
Position 225, 48

Control EditText
Value UndefinedPointFile
Into s_title
ID 3
Position 65, 48 Width 150

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Control StaticText
Title "Access Buffers:"
Position 5, 70

Control Button
Title "&Browse"
Calling GetAccessBufFile
Position 225, 68

Control EditText
Value RelayPointFile
Into s_title
ID 4
Position 65, 68 Width 150

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


Control OKButton
Position 65, 185


Control CancelButton
Position 120, 185


If CommandInfo(CMD_INFO_DLG_OK) Then

' ... then the user clicked OK.

Else
' ... then the user clicked Cancel.

End If

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub GetAccessfile

AccessPointFile = FileOpenDlg("","","TAB","Open Table")

If AccessPointFile <> "" then
Alter Control 1 value AccessPointFile
End if

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub GetRelayfile

RelayPointFile = FileOpenDlg("","","TAB","Open Table")

If RelayPointFile <> "" then
Alter Control 2 value RelayPointFile
End if

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub GetUndefinedfile

UndefinedPointFile = FileOpenDlg("","","TAB","Open Table")

If UndefinedPointFile <> "" then
Alter Control 3 value UndefinedPointFile
End if


End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub GetAccessBufFile

AccessBuffers = FileOpenDlg("","","TAB","Open Table")

If AccessBuffers <> "" then
Alter Control 4 value AccessBuffers
End if


End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub Reset_Sub

Alter Control 1 value ""
Alter Control 2 value ""
Alter Control 3 value ""

End Sub



Any Direction would help. Thanks

CB

unread,
Nov 21, 2008, 3:12:54 PM11/21/08
to MapInfo-L
You can use MapBasic project files (.mbp) to bring various source
files (.mb) into one .mbx.
A project file looks like this:
[Link]
Application=TheApp.mbx
Module=Main.mbo
Module=MenuHandlers.mbo

In order for a MapBasic file to compile to a .mbo and not straight to
a .mbx, the .mb file must refer to a function or subroutine in another
module.
To bring it all together:
' File: Main.mb
Declare Sub Main
Include "MenuHandlers.def ' This contains the declarations of all
the functions and subroutines in MenuHandler.mb
Sub Main
' Do Stuff
End Sub
' File end

' File: MenuHandlers.mb
Include "MenuHandlers.def"
' subs and funcs
' File end

In MapBasic, you would open each mb file and build it (Project-
>Compile Current File).
Then, open a project file (.mbp): Project->Select Project File.
Finally, link it all together: Project->Link Current Project.

I hope this helps. Feel free to write with more questions.

Charles Bates
Pitney Bowes Business Insight

(I have created a set of utilities that write nmake-compatible
makefiles to allow you to use nnake to build your MapBasic project.
The advantage of using nmake is in getting some dependency checking,
which is not available in MapBasic. Contact me if you would like more
information.)

Gabe

unread,
Nov 21, 2008, 5:01:58 PM11/21/08
to MapInfo-L

Charles,

Thanks for the reply. I don't know if i'm close, or if I'm way off.
Below is what I have. I don't know how to compile my main .mb to
an .mbx when I'm calling a procedure that isn't in the .mb. I guess I
need clarification on the "Do Stuff" part of your above reply.



Also, when I try to "Link Current Project" , I get an error that says
"Missing main sub in .My_application.mbx". I assume that has something
to do with the fact that I don't have an .mbx file.

Let me know if I'm way off.

*******************************************
'My Project file (my.mbp)

[Link]
Application=My_application.mbx
Module=menu_test.mbo
Module=setup_test.mbo
Module=my_modules.mbo

************************************************************
'My Main Application (should be My_application.mbx but compiles
to .mbo)

Include "mapbasic.def"

Declare Sub Main

Include "my_modules.def"

Sub Main


Call Menu


End Sub

************************************************************
'My declarations file (my_modules.mbo - compiles to my_modules.def)

''''First Module Subs'''
Declare Sub Menu


'''Second Module subs''''''''
Declare Sub Setup
Declare Sub GetAccessfile
Declare Sub GetRelayfile
Declare Sub GetUndefinedfile
Declare Sub GetAccessBufFile
Declare Sub Reset_Sub


***********************************************************
'My first module (menu_test.mbo)

Include "mapbasic.def"
Include "my_modules.def"



Sub Menu


Create Menu "Whatever Tool" As
"&Project Setup" Calling Setup,
"(-",
"&Data Creation" Calling DataCreation,
"(-",
"E&xit TextBox" Calling Bye

Alter menu bar add "Whatever Tool"


End Sub

****************************************************************
'My second Module (setup_test.mbo)

Include "mapbasic.def"
Include "my_modules.def"

CB

unread,
Nov 21, 2008, 8:36:04 PM11/21/08
to MapInfo-L
I think your misunderstanding is right here:
"I don't know how to compile my main .mb to
an .mbx when I'm calling a procedure that isn't in the .mb."

When building an mbx from multiple mb files, all mb files compile to
mbo files; that is, the mbx is not produced from any one mb file. It
is the project file (mbp) and using Project->Link Current Project that
produces the mbx.

I have sent you a zip file with your project broken down in to a set
of files that builds as a MapBasic project.

Hope that helps....

Charles Bates
Pitney Bowes Business Insight


CB

unread,
Nov 21, 2008, 8:45:54 PM11/21/08
to MapInfo-L
Contact me with a valid email address if you would like me to send you
a project that builds, based on what you have posted here.

Gabe

unread,
Nov 24, 2008, 11:12:40 AM11/24/08
to MapInfo-L
Charles,

Thanks a lot. I seem to have it working. I didn't realize that when I
hit, "Link Current Project" from the .mbp that it would create
the .mbx I specified in the .mbp, linking all the .mbos.

Chris Stinemetz

unread,
Dec 16, 2016, 11:18:39 AM12/16/16
to MapInfo-L, gabem...@gmail.com
This approach isn't working for me. Unfortunately my Main.mb is still producing a *.MBX file. This is what i have:

carrierIQ.mbp file:

[Link]
Application = carrierIQ.mbx
Module = Main.mbo
Module = carrierIQ.mbo

carrierIQ.def file:

Declare Sub Buttons
Declare Sub About 

carrierIQ.mb file:

Include "carrierIQ.def"
Include "mapbasic.def"
Include "icons.def"


'****************************************************************************
'
' Sub procedure: Buttons
'
' Buttons creates all the selectable buttons under LEGACY tab  
'****************************************************************************
Sub Buttons()
'do something
End Sub

Main.mb file:

Declare Sub Main
Include "carrierIQ.def"

Sub Main()

End Sub

I know this is an old thread so any help is appreciated!

Chris

Peter Horsbøll Møller

unread,
Dec 16, 2016, 11:35:29 AM12/16/16
to mapi...@googlegroups.com

Hi Chris

 

That’s because your Main module doesn’t use any functions/procedures from the carrierIQ module.

 

Try changing the Main procedure to this:

Sub Main()

   Call Buttons

End Sub

 

And recompile it

 

Peter Horsbøll Møller

Pitney Bowes

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

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.




Chris Stinemetz

unread,
Dec 16, 2016, 4:55:57 PM12/16/16
to mapi...@googlegroups.com
That worked. Thanks!

To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

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

---
You received this message because you are subscribed to a topic in the Google Groups "MapInfo-L" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapinfo-l/1wq-_l0PCI4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapinfo-l+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages