Bill,
(hope i did understand correctly)
use a global variable giBtn instead of iBtn to keep the value and rewrite
the function Door as follows; it should return 1, 2 or 3 unless Cancel is
the first user operation (because of value 0 into )
sub Door
giBtn=1 + int(Rnd(1)*3)
dialog remove
alter control ID_BTN value str$(giBtn)
end sub
btw, the following section is useless, or ?
if CommandInfo (CMD_INFO_DLG_OK) then
LadyOrTiger = iBtn
exit function
end if
Pierre
> -----Original Message-----
> From: Bill Thoen [SMTP:[EMAIL PROTECTED]]
> Sent: Saturday, April 15, 2000 2:21 AM
> To: MapInfo-L
> Subject: MI Custom buttons and the Lady, Tiger or Balrog problem.
>
> Here's a little adventure for MapBasic people. This is a little
> game based on the classic Lady or the Tiger choice (with a Balrog
> thrown in for evil grins). But it's not just a game as it
> illustrates a problem I'm having with custom buttons and Dialog
> Remove.
>
> I have three buttons in a dialog, and each one sets the same
> (hiddeen) value in the dialog. When any of the three are pressed,
> I want the dialog dismissed and the calling function to receive a
> value based on what button was pressed. The button labeled "Door
> #1" works because it is really an OKbutton. The calling function
> for the other two is exactly the same as the one for the
> OKbutton, but it doesn't work for them. It seems that a
> CancelButton or Dialog Remove result it blowign away all the
> dialog values before you get a chance to pass them back to the
> caller. What I want to know is how do I get a custom button sub
> to dismiss a dialog without triggering a "CancelButton" event?
>
> A virtual Sultan's treasure to whomever solves this!
> TIA,
> - Bill Thoen
>
> include "mapbasic.def"
>
> define ID_BTN 1
> define RESULTS_NOTHING 0
> define RESULTS_LADY 1
> define RESULTS_TIGER 2
> define RESULTS_BALROG 3
>
> declare sub main
> declare function LadyOrTiger() as smallint
> declare sub Door
>
> sub main
> randomize
> do while TRUE
> do case LadyOrTiger()
> case RESULTS_NOTHING
> 'This should never happen, but it does.
> note "The Magic Failed... nothing happens"
> case RESULTS_LADY
> note "You get the Lady!"
> case RESULTS_TIGER
> note "Tiger gets you!"
> case RESULTS_BALROG
> note "Surprise!!! It's the Balrog for you!"
> end case
> if not Ask ("Try again?", "Yes", "No") then
> exit do
> end if
> loop
> end sub
>
> function LadyOrTiger () as smallint
> dim iBtn as smallint
>
> dialog title "Dilemma Adventurer"
> control statictext position 4,4
> title "The odds are against you mortal! Choose a door."
> control popupmenu
> position 4, 100
> title "Lady;Tiger;Balrog"
> value 0 into iBtn
> ID ID_BTN hide
> control OKbutton title "Door #1"
> position 16,14
> width 40 height 60
> calling Door
> control button title "Door #2"
> position 62,14
> width 40 height 60
> calling Door
> control button title "Door #3"
> position 108,14
> width 40 height 60
> calling Door
>
> if CommandInfo (CMD_INFO_DLG_OK) then
> LadyOrTiger = iBtn
> exit function
> end if
>
> 'Blast and Damme! CancelButton or Dialog Remove
> 'cause the value of dialog values to be lost!!!
> 'iBtn is ALWAYS 1, 2, or 3, but somehow it's 0 here!
> LadyOrTiger = iBtn
> end function
>
> sub Door
> dialog remove
> alter control ID_BTN value str$(1 + int(Rnd(1)*3))
> end sub
> ----------------------------------------------------------------------
> To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
> "unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]
----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]