calling handler with parameters

147 views
Skip to first unread message

Kralizec

unread,
Nov 8, 2009, 4:49:16 PM11/8/09
to MapInfo-L
Hello,

I wonder if there is a way to call a subprocedure with parameters by a
button handler.

For example consider the little application below. I am trying to code
something like that.
I want to learn that is it possible. If not is there an other way to
do that.

Many Thanks

declare sub main
declare sub mysub (ByVal str as String)

sub main
dim varbl1 as string
dialog title "MyDialog"
Control PopupMenu Title "-;String 1;String 2" Value 1 ID 1 into
varbl1
Control Button Title "&Button Trial" calling mysub (varbl1)
end sub

sub mysub(ByVal str as String)
note str
end sub

Steve Smith

unread,
Nov 8, 2009, 5:01:08 PM11/8/09
to mapi...@googlegroups.com

I do not think there is a way in MapBasic to pass parameters in dialog code or button pad code as shown in your code sample below. I could be wrong. Using Global variables are probably the simplest MapBasic work around.


Regards

Steve Smith
Australian Bureau of Statistics (ABS)
Post: Locked Bag 10 Belconnen ACT 2616
Location: ABS House, 45 Benjamin Way, Belconnen ACT 2617
Geography / Spatial Data Management and Research
ABS Level 2 South 228 , Wk: (02) 6252-6824
Last ABS day = 3/Dec/09, moving to Deewr.

Inactive hide details for Kralizec ---09/11/2009 08:49:45 AM---Hello, I wonder if there is a way to call a subprocedure with paKralizec ---09/11/2009 08:49:45 AM---Hello, I wonder if there is a way to call a subprocedure with parameters by a


From:

Kralizec <emrah...@gmail.com>

To:

MapInfo-L <mapi...@googlegroups.com>

Date:

09/11/2009 08:49 AM

Subject:

[MI-L] calling handler with parameters

Sent by:

mapi...@googlegroups.com

------------------------------------------------------------------------------------------------

Free publications and statistics available on www.abs.gov.au

 

Gentreau

unread,
Nov 8, 2009, 5:11:33 PM11/8/09
to mapi...@googlegroups.com

That can be made to work, but what you must remember is that varbl1 does not
contain any data until the user closes the Dialog. In order to do what you
are trying to acheive your sub routine would have to call
ReadControlValue(1) which will return the current value of the control.

Hth
Gentreau

Peter Horsbøll Møller

unread,
Nov 9, 2009, 2:12:18 AM11/9/09
to mapi...@googlegroups.com
Why would you want to send parameters to your sub from a button?
 
You can read the current selected value using the ReadControlValue() function.
And if you use a modular array to hold the values of the control you can easily look up the selected value.
 
declare sub main
declare sub mysub (ByVal str as String)
Dim arrValues() As String

sub main
   Dim varbl1 as string
   Redim arrValues(3)
   arrValues(1) = "-"
   arrValues(2) = "String 1"
   arrValues(3) = "String 2"
 
   dialog title "MyDialog"
      Control PopupMenu Title From Variable marrValues
         Value 1 ID 1
         into varbl1
      Control Button Title "&Button Trial"
         calling myButtonHandler
end sub
sub mysub
   Dim nItem As Integer
   nItem = ReadControlValue(1)
   note marrValues(nItem)
end sub
 

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo
 
 
2009/11/8 Steve Smith <steve...@abs.gov.au>
ecblank.gif
graycol.gif

Gentreau

unread,
Nov 9, 2009, 2:58:30 AM11/9/09
to mapi...@googlegroups.com
One reason would be because you might want to update one control based on the value of another control, but only when the user requests it, by clicking on the button.
 
In fact my earlier response was not quite correct, you wont be able to call the Note function while the dialog is active as all MapBasic dialogs are Modal.
However, your sub could do something else, such as change the value of a list control.
 
Gentreau.


From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Peter Horsbøll Møller
Sent: Monday, November 09, 2009 8:12 AM
To: mapi...@googlegroups.com
Subject: [MI-L] Re: calling handler with parameters [SEC=UNCLASSIFIED]

Peter Horsbøll Møller

unread,
Nov 9, 2009, 3:15:07 AM11/9/09
to mapi...@googlegroups.com
Gentreau,
 
I wrote the question while thinking about Tool-, Push- and Tooglebuttons.
When I finally notices what he was trying the do, I forgot the remove the question again.
I do understand why he wants to do it, and my suggestion would be the way to do it - or at least one way to do it.
I did however find some minor errors in the code, so here is the working code.
 
Declare sub main
Declare sub mysub
Dim marrValues() As String
sub main
   Dim varbl1 as string
   Redim marrValues(3)
   marrValues(1) = "-"
   marrValues(2) = "String 1"
   marrValues(3) = "String 2"
   dialog title "MyDialog"
      Control PopupMenu Title From Variable marrValues
         Value 1 ID 1
         into varbl1
      Control Button Title "&Button Trial"
         calling mysub
end sub
sub mysub
   Dim nItem As Integer
   nItem = ReadControlValue(1)
   Note marrValues(nItem)
end sub
 
And you can call the Note statement even though the dialog is modal.
You could even call a subprocedure that would show another dialog on top of the first.
A modal dialog only prevents you from accessing earlier dialogs/MI Pro itself. It does not prevent you from opening other dialogs.

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo
 
 
2009/11/9 Gentreau <goo...@gentreau.com>
ecblank.gif
graycol.gif

Kralizec

unread,
Nov 9, 2009, 3:40:53 PM11/9/09
to MapInfo-L
Thank for all the responses.
My aim is to call the external dll depending on the value of the
popup menu when the button is clicked on the dialog. Using global
variable is quite satisfactory for me.

Because I am not so experienced in the mapbasic coding, these staff
are sometimes difficult for me.
Many many thanks

On Nov 9, 10:15 am, Peter Horsbøll Møller <mapinf...@horsboll-
> >  ------------------------------
> > *From:* mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] *On
> > Behalf Of *Peter Horsbøll Møller
> > *Sent:* Monday, November 09, 2009 8:12 AM
> > *To:* mapi...@googlegroups.com
> > *Subject:* [MI-L] Re: calling handler with parameters [SEC=UNCLASSIFIED]
>
> >   Why would you want to send parameters to your sub from a button?
>
> > You can read the current selected value using the ReadControlValue()
> > function.
> > And if you use a modular array to hold the values of the control you can
> > easily look up the selected value.
>
> > declare sub main
> > declare sub mysub (ByVal str as String)
> > *Dim arrValues() As String*
>
> > sub main
> >    Dim varbl1 as string
> > *   Redim arrValues(3)*
> > *   arrValues(1) = "-"*
> > *   arrValues(2) = "String 1"*
> >  *   arrValues(3) = "String 2"*
>
> >    dialog title "MyDialog"
> >       Control PopupMenu Title *From Variable marrValues*
> >          Value 1 ID 1
> >          into varbl1
> >       Control Button Title "&Button Trial"
> >          calling myButtonHandler
> > end sub
> > sub mysub
> > *   Dim nItem As Integer*
> > *   nItem = ReadControlValue(1)*
> > *   note marrValues(nItem)
> > *end sub
>
> > Peter Horsbøll Møller
> > Pitney Bowes Business Insight - MapInfo
>
> > 2009/11/8 Steve Smith <steve.sm...@abs.gov.au>
>
> >>  I do not think there is a way in MapBasic to pass parameters in dialog
> >> code or button pad code as shown in your code sample below. I could be
> >> wrong. Using Global variables are probably the simplest MapBasic work
> >> around.
>
> >> Regards
>
> >> Steve Smith
> >> Australian Bureau of Statistics (ABS)
> >> Post: Locked Bag 10 Belconnen ACT 2616
> >> Location: ABS House, 45 Benjamin Way, Belconnen ACT 2617
> >> Geography / Spatial Data Management and Research
> >> ABS Level 2 South 228 , Wk: (02) 6252-6824
> >> Last ABS day = 3/Dec/09, moving to Deewr.
>
> >> [image: Inactive hide details for Kralizec ---09/11/2009 08:49:45
> >> AM---Hello, I wonder if there is a way to call a subprocedure with pa]Kralizec
> >> ---09/11/2009 08:49:45 AM---Hello, I wonder if there is a way to call a
> >> subprocedure with parameters by a
>
> >> From:
> >> Kralizec <emrahtu...@gmail.com>
> >> To:
> >> MapInfo-L <mapi...@googlegroups.com>
> >> Date:
> >> 09/11/2009 08:49 AM
> >> Subject:
> >> [MI-L] calling handler with parameters
> >> Sent by:
> >> mapi...@googlegroups.com
> >> ------------------------------
>
> >> Hello,
>
> >> I wonder if there is a way to call a subprocedure with parameters by a
> >> button handler.
>
> >> For example consider the little application below. I am trying to code
> >> something like that.
> >> I want to learn that is it possible. If not is there an other way to
> >> do that.
>
> >> Many Thanks
>
> >> declare sub main
> >> declare sub mysub (ByVal str as String)
>
> >> sub main
> >>        dim varbl1 as string
> >>        dialog title "MyDialog"
> >> Control PopupMenu Title "-;String 1;String 2" Value 1 ID 1 into
> >> varbl1
> >>        Control Button Title "&Button Trial" calling mysub (varbl1)
> >> end sub
>
> >> sub mysub(ByVal str as String)
> >>        note str
> >> end sub
>
>
>
>  ecblank.gif
> < 1KViewDownload
>
>  graycol.gif
> < 1KViewDownload
Reply all
Reply to author
Forward
0 new messages