Hi Ethan

I got these answers from the list some years ago to nearly the same problem:

This is not my work but it can be found at the MapInfo-L mailing achive.


Suggestion 1:
'**********************************************
As the Dialog statement cannot be executed by the Run Command statement,
this is as close as I can get. It requires you to define a predetermined
maximum number of controls, and then dynamically initializing, enabling,
and showing them.

Include "MapBasic.Def"

Declare Sub Main
Declare Sub DialogHandler
Declare Sub OkButtonHandler

Define MAX_CHECK_BOXES 10
Define MAX_TITLE_LEN 20

Type CheckBoxes
  sTitle As String
  lValue As  Logical
End Type

Dim i As Integer
Dim tCheckBoxes(0) As CheckBoxes

Sub Main

  Dim iRequestedCheckBoxes As Integer

  iRequestedCheckBoxes = 5

  Dialog
    Title "Test Dynamic Check Boxes"
    Control StaticText
      Title "Enter number of check boxes (up to 10):"
    Control EditText
      Value Str$(iRequestedCheckBoxes)
      Into iRequestedCheckBoxes
  Control OKButton
  Control CancelButton

  If CommandInfo(CMD_INFO_DLG_OK) Then
    If iRequestedCheckBoxes > MAX_CHECK_BOXES Then
      iRequestedCheckBoxes = MAX_CHECK_BOXES
    End If

    For i = 1 To iRequestedCheckBoxes
      ReDim tCheckBoxes(i)
      tCheckBoxes(i).sTitle = "Item " + i
      tCheckBoxes(i).lValue = i Mod 2
    Next

    Dialog
      Calling DialogHandler
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 1 Disable Hide
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 2 Disable Hide
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 3 Disable Hide
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 4 Disable Hide
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 5 Disable Hide
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 6 Disable Hide
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 7 Disable Hide
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 8 Disable Hide
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 9 Disable Hide
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 10 Disable Hide
      Control CheckBox Title Space$(MAX_TITLE_LEN) ID 11 Disable Hide
      Control OkButton Calling OkButtonHandler
      Control CancelButton

    If CommandInfo(CMD_INFO_DLG_OK) Then
      For i = 1 To UBound(tCheckBoxes)
        Print "CheckBox " + i + " = " + tCheckBoxes(i).lValue
      Next
    End If
  End If

End Sub

Sub DialogHandler
  Dim i As Integer

  For i = 1 To UBound(tCheckBoxes)
    Alter Control i Title tCheckBoxes(i).sTitle Value tCheckBoxes(i).lValue
Enable Show
  Next
End Sub

Sub OkButtonHandler
  Dim i As Integer

  For i = 1 To UBound(tCheckBoxes)
    tCheckBoxes(i).lValue = ReadControlValue(i)
  Next
End Sub

'End Module

'********************************


Suggestion 2:
'*********************************************

When defining the MB dialog box, you may enter dialog size parameters,
and you can hide controls from within the dialog box.
Combining these, you can do something like:

Global nCount as integer

Sub Xxxx
 Dim dy as integer

nCount = 3  'any number from 1 - 9
dy = 5 + nCount * 10

Dialog
     Title "Dynamic sized dialog box"
     Height dy + 25
     Calling HideTheUnnneccesaryControls
     Control CheckBox Position 5, 5 ID 1 Title "Item 1"
     Control CheckBox Position 5,15 ID 2 Title "Item 2"
     Control CheckBox Position 5,25 ID 3 Title "Item 3"
     Control CheckBox Position 5,35 ID 4 Title "Item 4"
     Control CheckBox Position 5,45 ID 5 Title "Item 5"
     Control CheckBox Position 5,55 ID 6 Title "Item 6"
     Control CheckBox Position 5,65 ID 7 Title "Item 7"
     Control CheckBox Position 5,75 ID 8 Title "Item 8"
     Control CheckBox Position 5,85 ID 9 Title "Item 9"
     Control OkButton Position 5,dy
End Sub

Sub HideTheUnnneccesaryControls
 Dim i as integer
     For i = nCount + 1 To 9
          Alter Control i Hide
     Next
End Sub

Off course it's not completely dynamic, as the number of checkbox'es
are limited (here to 9), but to the user it'll appear dynamic in size.

'************************************************


Regards

Thomas Brix Lyng
Frederikshavn Minicipal Administration
Denmark
_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l

Reply via email to