Hi Lawson,

You stumbled over the not-so-obvious chronologicality of events when dealing with 
dialog boxes in MB. It took me quite a while to
master it, but this is the sequence in which things occur:

1. The dialog box is rendered with the static initial values when the "Dialog" 
statement is encountered
2. The optional initialization routine is run (Calling directly under the Dialog 
statement, before the first Control)

The dialog box now runs until it's flagged for removal. Flagging occurs when the user 
presses either OKButton or the CancelButton,
or some handler issues a Dialog Remove statement. Note that a handler routine 
connected to the OK/Cancel buttons may de-flag the
removal by issuing Dialog Preserve.

While the dialog runs, the triggered handler routines (whwn the user changes some 
settings) are the only events that occur. These
handler routines interact with the dialog box only thru ReadControlValue function 
calls and Alter Control statements.

If the OK/Cancel handler routines doesn't de-flag the shutdown, or any handler routine 
issues a Dialog Remove, the dialog shutdown
process is initiated. After shut down is initiated, the Into variables are assigned 
their values. I.e., these variables are local to
the routine in which the dialog is created, and more importantly, cannot be used while 
the dialog is displayed, only after it's shut
down.

In your case, Quarterselect is not assigned a value when output in the OKhandler 
routine, hence the "0Q" output. It's only assigned
its value AFTER the OkHandler routine finishes, i.e. when the shut down is initiated.

HTH

Best regards/Med venlig hilsen
Lars V. Nielsen
GisPro, Denmark
http://www.gispro.dk/
http://www.gispro.biz/

----- Original Message ----- 
From: "Lawson Key" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 12, 2004 11:58 PM
Subject: MI-L Problem reading returned values from dialog controls


Despite my 3+ years experience with MapInfo, I've barely scratched the surface of 
MapBasic (this is my first post).  I want to
create a simple dialog with popup menus, but I'm having trouble with the returned 
values from the popup menus.  I've used
ReadControlValue() to check the values, which are returned as 0,1,2 or 3, not the 
string values in the menu itself.  Converting
these values into the intended string values is proving harder than I thought.  
Whenever I put the variable through a logical test
to set a different variable to the desired value, it treats it as though the value is 
0.

Here's the code for the dialog, which prompts a user to select a Year and a Quarter.

Dim Yearselect as smallint
Dim Quarterselect as smallint

Dialog
Control GroupBox
ID 1
Title "Select Year and Quarter of Data"
Position 5, 0 Width 153 Height 30
Control PopupMenu
ID 2
Title "02;03;04;05"
Position 35, 12
Into Yearselect
Control PopupMenu
ID 3
Title "1Q;2Q;3Q;4Q"
Position 100, 12
Into Quarterselect
Control OKButton
Calling OKhandler
Control CancelButton


Here's the code for the part where I'm trying to establish string values representing 
the last two digits of the year selected, and
the selected quarter in the format "#Q". I'm sure there is probably a better way to do 
this.

Dim Quarter as string
Dim Year as string

Sub OKhandler
Print "Value of Yearselect is.." + ReadControlValue(2)
Print "Value of Quarterselect is.." + ReadControlValue(3)

Quarter = str$(Quarterselect) + "Q"

If Yearselect = 0 then
year = "02"
Elseif Yearselect = 1 then
year = "03"
Elseif Yearselect = 2 then
year = "04"
Elseif Yearselect = 3 then
year = "05"
End If

Print "You have selected the year" + Year
Print "You have selected the quarter" + Quarter
End Sub

The initial print statements in this sub show that the control does return a value, 
but the final print statements show the Year as
"02" and the quarter as "0Q", regardless of what I select from the menu.

Lawson Key
CenturyTel
318.340.5335

---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10852



---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10854

Reply via email to