Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem I really can't seem to get my head around, MapInfo crashes when I try to run and if statement.

I have pretty much exactly the same code in another sub to check for other things and that works perfectly fine. It crashes on the zlRow = TableInfo("zerolengths",TAB_INFO_NROWS), I've tried this with zlRow = TableInfo(0,TAB_INFO_NROWS) as there will only be one TAB file open when this rool is running. I just don't know why it works for other subs and queries but not this!!

Sub LenSub

nMID = FrontWindow()

nLayers = MapperInfo(nMID, MAPPER_INFO_LAYERS)

sLayer = LayerInfo(nMID, nLayers, LAYER_INFO_NAME)

Dim sDir as String 

sDir = PathToDirectory$(TableInfo(sLayer,TAB_INFO_TABFILE))

    '###Check for blanks

Dim sLen as string

    Title "Length"
    Control statictext
        Title "Enter length field"
    Control edittext
        Value sLen
        into sLen
    Control OKButton
    Control CancelButton

if commandinfo (CMD_INFO_DLG_OK) then

End Program
End if

Run Command "select * from " & sLayer & " where " & sLen & " < 1 into zerolengths"

Dim zlRow as smallint

zlRow = TableInfo("zerolengths",TAB_INFO_NROWS)

if zlRow > 0 then
    Export Multipolylines Into sDir & "zerolengths.csv" Type "CSV" 
    Delimiter "," 

            Title "Zero lengths"
            Control statictext
                Title "Sections with zero lengths exported into zerolengths.csv"
            Control OKButton
End If

End Sub

Thanks, Alan

share|improve this question

It seems it is actually crashing on this line

Export Multipolylines Into sDir & "zerolengths.csv" Type "CSV

Does the table Multipolylines exist elsewhere in your code? Did you mean to export the zerolengths table you created instead?

share|improve this answer
Yup thanks, still very new to this so I need to be more careful with my pasting! – Alan Carr Apr 25 '13 at 16:06

First, try to generate your analysis with mainfo and save your espacework like (.Wor) (if you have to open a table and apply an SQL query, Do it manually). then open this file with mapBASIC. Compile it and correct the errors; Add these in the begin of your code to commands:

Declare Sub Main
Sub Main


Add at the end:

 end Sub/
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.