RE: MI - MapBasic lists

2000-07-13 Thread Crompton, Mark

Hi Tom,

One of the ways I do it, is through Global variables (I know programmers
should not use Globals).  With a global array you can resize it inside on of
the handler routines.  This may not work as written, as I re-hashed some of
my current code to make it easier to read, but the basic concept is the
same.

This is what I do for a ListBox:

1)  Make a selection, put it into a temporary table, pull out the required
column into a Global Array (gaszPickSiteName)

Select SiteName from DCCMatches where SiteName  "" Group by
SiteName Order by SiteName into TT
ReDim gaszPickSiteName(TableInfo(TT, TAB_INFO_NROWS))
For snLoop = 1 to TableInfo(TT, TAB_INFO_NROWS)
Fetch Rec snLoop From TT
gaszPickSiteName(snLoop) = Str$(TT.SiteName)
Next

2)  ListBox Control
Control ListBox
Width 50  Height 70
Position 5, 35
ID PICKSECTORLISTBOX
Calling UpdateSectorListBox

3)  Handler Routine

Sub UpdateListBox()
Dim snReadSelValue, snLoop, snCounter As SmallInt
Dim szSiteName As String

'   *** Only 1 item at once, sorry
'   *** (returns 0 if no items selected).
'   *** Value returned is the same as ROWn from TT
snReadSelValue = ReadControlValue(PICKSECTORLISTBOX)

snCounter = 0
If (snReadSelValue  0) Then
Fetch Rec snReadSelValue from TT
szSiteName = TT.SiteName

For snLoop = 1 to TableInfo(TT, TAB_INFO_NROWS)
Fetch Rec snLoop From TT
If Str$(TT.SiteName)  szSiteName Then
snCounter = snCounter + 1
gaszPickSiteName(snLoop) = Str$(TT.SiteName)
End If
Next

ReDim gaszPickSiteName(snCounter)
Alter Control PICKSECTORLISTBOX Title From Variable
gaszPickSiteName
Close Table TMP
End If
End Sub

Hope that this helps,
Mark

-Original Message-
From: Tom Manson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 13, 2000 9:00 AM
To: 'MapInfo-L'
Subject: MI - MapBasic lists


Mappers,

I'm having a problem with MapBasic. Is it possible to create a drop-down
list within a dialog box of files currently open. From what I gather,
drop-down boxes (popupmenu) seem to be pretty static, and I can't seem to
find a way of making it list files 'on the fly'. If anyone could help me
with the code on this I'd be very appreciative. On a similar line, how can I
list what columns a file has?

Many thanks in advance,


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



Re: MI - MapBasic lists

2000-07-13 Thread Bill Thoen

"Crompton, Mark" wrote:
 
 One of the ways I do it, is through Global variables (I know programmers
 should not use Globals).  With a global array you can resize it inside on of

Not exactly; programmers should not use *uncontrolled* globals.
Even everyone's favorite whipping boy, the lowly-regarded Goto,
has it's place (but 99% of the time that place is the
wastebasket.) Module scope globals are almost required for any
MapBasic dialog beyond the trivial. For those, I just create a
separate module for the dialog, and then use 'dim' to define
globals I need. That way there's little chance that a global
there can foul some other part of the application. 

Defining variables as 'global' instead of 'dim' at the module
level is what I'd call uncontrolled, and should only be done if
you want to live in interesting times. Besides, anyone who
programs in MapBasic already has to compromise his or her sense
of purity to a certain extent. In a language where there are no
function-level static variables and NO private functions
anywhere, you can only be so holy about it. Especially when it
comes to dealing with MapBasic dialog structures. 

Your global array is easily a module-scoped variable, and the use
you make of it is clever, obvious and totally appropriate. I
wouldn't put down the use of globals here.

- Bill Thoen

GISnet, 1401 Walnut St., Suite C, Boulder, CO  80302
tel: 303-786-9961, fax: 303-443-4856
mailto:[EMAIL PROTECTED], http://www.ctmap.com/gisnet


--
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]