There are 4 error messages with the script below. Can anybody find out how to solve them please? Everything seemed to match up in Notepad++.

The error messages:

[End sub] found without corresponding sub statement.
Found [] while searching for [next].
If without End If.
Sub/Function without End Sub/Function.

The script:

Include "mapbasic.def"
Include "icons.def"

Declare Sub Main
Declare Sub button_prompt

Sub main

Alter ButtonPad "Main"
   Add Separator
   Add PushButton
      Calling button_prompt
      HelpMsg "Use for checking protected riverine species\nCheck for riverine species in Stroud district"
End Sub

Sub button_prompt
Dim strUserGrid as string
Dim strUser100kSq,picname as string
dim strNorthings as string
dim strEastings as string
dim strAppref as string
Dim strRadius as string
Dim intLenUserGrid as integer
Dim intUserEast as integer
Dim intUserNorth as integer
Dim intMapWinId as integer
dim editablelayer, objtype as integer
dim obj_found,i_row_id,i,iii as integer
dim cosname as string
dim s_table As Alias
dim s_row as string

dim appPoint, appBuffer, distBuffer as object
dim numrows, numrows2 as integer
dim fileout, tableout, layername as string
dim dist, x2,y2 as float

dim win_id,layout_win,no_layers as integer
dim width_units as float
dim c_group, c_sci_name, c_eng_name, c_gridref, c_year, c_status, c_location, c_loc_detail as string

dim spCheck as logical
dim strTitle as string

Dim intAppref, aa, intstrChar as integer
Dim strChar, strLegalName as string
Dim i_app_type as integer
Dim int_buffer as float

'Check to see if map window is open
if intmapwinid = 0 then
    Note "Program can only be run in a map window"
    exit sub
end if

if windowinfo(intMapWinId,Win_Info_Type)<>WIN_MAPPER then
    Note "Program can only be run in a map window"
    exit sub
end if

'Delete all from cosmetic layer
delete from windowinfo(frontwindow(),win_info_table)

do case editablelayer

case 0
case else
    set map
    layer 0 editable on
end case

    Title "Planning Check"
        Position 200, 200   width 200 height 200
    Control statictext
        Position 20, 20
        Title "Planning App. Ref:"
    Control EditText
        Position 100, 20
        Into strAppref
    Control StaticText
        Position 20, 40
        Title "Eastings:"
    Control EditText
        Position 100, 40
        Into strEastings
    Control statictext
        Position 20, 60
        Title "Northings:"
    Control EditText
        Position 100, 60
        Into strNorthings
    Control RadioGroup
        Title "&Very large App;Specified Radius(m)"
        Value 2
        Into i_app_type
    Control EditText
        Position 100, 100
        Into strRadius
    Control OKButton
        Position 60, 140
    Control CancelButton


     'Validate input
     if CommandInfo (CMD_INFO_DLG_OK) Then
         intLenUserGrid = Len(strEastings)
         if intLenUserGrid <> 6 then

             note "Eastings need 6 characters"
             exit sub
         end if
         intLenUserGrid = Len(strNorthings)
         if intLenUserGrid <> 6 then
            note "Northings need 6 characters"
             exit sub
         end if

        if intUserEast = 0 or intUserNorth = 0 then
            note "You have not entered a valid grid reference"
            exit sub
        end if
        'Check app ref
        if strAppref="" then
            note "You have not entered an application reference"
            exit sub

            'Remove illegal filename characters
            for aa=1 to intAppref
                if  intstrChar < 48 then 
                elseif intstrChar > 57 and intstrChar < 65 then 
                elseif intstrChar >90 and intstrChar < 97 then
                elseif intstrChar > 122 then
                end if
                strLegalName=strLegalName & strChar

        end if
        if i_app_type = 2 then
            int_buffer = 5
            int_buffer = val(strRadius) / 1000
        end if
        if int_buffer = 0 then
            note "You have not entered a valid radius"
            exit sub
        end if
        exit sub
    end if

    'Set location of output files, and delete old files if necessary
    tableout=getfolderpath$(folder_mydocs) & "\" & strLegalName &      "_planning_application.dbf"
    if FileExists(tableout) then
        kill tableout
    end if

    fileout=getfolderpath$(folder_mydocs) & "\" & strLegalName & "_planning_application_export.xls"
    if FileExists(fileout) then
        kill fileout
    end if

    'Create work table for building up output details
    create table PlanAppCheck
        (A char(60),
         B char(180),
         C char(200),
         D char(40),
         E char(35),
         F char(30),
         G char(250),
         H char(254))
         file tableout
         type dbf

    insert into PlanAppCheck
        (A, D, E)
        values ("Produced using data held at the", "GCER report for planning     application:", strLegalName)
    insert into PlanAppCheck
        (A, D, E)
        values ("Gloucestershire Centre for", "Search area: " +     int_buffer*1000 + "m from:", "Eastings(" + strEastings +"), Northings(" +  strNorthings + ")")
    insert into PlanAppCheck
        values ("Environmental Records")
    insert into PlanAppCheck
        values ("")
    insert into PlanAppCheck
        values ("Taxon Group",
              "Latin Name",
               "Common Name",
               "Grid Reference",
               "Year last recorded",
               "Distance from app point(m)",

    commit table PlanAppCheck

    Set CoordSys Earth Projection 8, 79, "m" , -2, 49, 0.9996012717, 400000,   -100000 Bounds (-6178818.52026, -12100120.7595) (6979076.21676, 1057773.97751)
    Set Map Center (intUserEast,intUserNorth)

    'choose style of buffer object
    set style brush makebrush(51,yellow,-1)
    set style pen makepen(2,2,yellow)

    create point    into variable appPoint(intUserEast,intUserNorth)

    set event processing off

    '******************************************************************************* ************
    'Check for protected species etc within buffer
    select * from stroud_district_riverine_species
        where obj within appBuffer
        into specieslist
        order by Group, Grid, Latin, Year desc


    if numrows=0 then
        insert into PlanAppCheck (A) Values ("No Species Records Selected")
        c_sci_name = ""
        c_gridref = ""
        for i=1 to (numrows)
            select * from specieslist where RowID=i into results

        if results.gridref = c_gridref
        and results.sci_name = c_sci_name then
            'ignore this record as it's effectively a duplicate (for the     purposes of this program)
            if c_sci_name = "" then 
                insert into PlanAppCheck
                    values ("Legally Protected Riverine Species - International")
            end if

            c_group = results.group
           c_sci_name = results.sci_name
            c_eng_name = results.eng_name
            c_gridref = results.gridref
            c_year = results.year
            c_status = results.status
            c_location = results.location
            width_units = 0
            numrows2 = 0

            do until numrows2 > 0
                width_units=width_units + 5
                distBuffer= Buffer(appPoint, 60, width_units, "m")
                select * from results
                    where obj within distBuffer


            insert into PlanAppCheck
                (A, B, C, D, E, F, G, H)
                values (c_taxongroup, 

    drop table results

end if

drop table specieslist
insert into PlanAppCheck
    values ("")
commit table PlanAppCheck


'Export data to file
export PlanAppCheck
    into fileout
    type "dbf"
drop table PlanAppCheck

'Create image file of planning app location

set event processing on

if spCheck=TRUE then
    set event processing off
    map from all2 position (5,5) width 5 height 5

    set map layer 0 editable on

    create point (intUserEast,intUserNorth) symbol (34,red,12)
    create object as buffer
        from cosname
        into table cosname
        width (int_buffer) units "km"
        resolution 60
    set map center (intUserEast,intUserNorth)
    if i_app_type=2 then
        set map zoom 90000 units "cm"
    end if

    set event processing on
    set window win_id 
        position (0,0) Units "cm"
        width 5 Units "cm"
        height 5 Units "cm"
    picname=getfolderpath$(folder_mydocs) & "\" & strLegalName & "_picture.jpg"
    save Window win_id as picname type "JPEG"
        width 9 Units "Cm"
        height 9 units "Cm"
        Copyright "Based on the Ordnance Survey Map. Licence No. 100046783" 

    remove map layer "all2"

end if

'make original layer editable again
set window win_id Max

do case editablelayer

case -1
    set map layer editablelayer editable on
end case

end sub        

You are missing a 'Next' for your For statement:

for i=1 to (numrows)
next  'this one is missing further down in the code!!

And you are missing an 'End If' for one of your If statements:

if results.gridref = c_gridref
and results.sci_name = c_sci_name then
    'ignore this record as it's effectively a duplicate (for the purposes of this program)
    if c_sci_name = "" then
        insert into PlanAppCheck
            values ("Legally Protected Riverine Species - International")
    end if
End If 'This one is missing further down just before the missing Next keyword!!
  • Thank you Peter. It's much appreciated. I did get the tool working but then realised some of the text had to be changed.. Just before I finalised the tool; the work's server went down.. Many Thanks – Rob Curtis Sep 2 '15 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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