My code (from previous questions here) to generate a list runs but there is no output...

Include "MapBasic.def"

Declare Sub Main

Sub Main
Dim path_to_temp_tables As String
path_to_temp_tables = ""

'Run the Dos Command
Run program "Cmd.exe /c dir """+path_to_temp_tables+"*.tab"" /b /w  > """+path_to_temp_tables+"List.txt"""

End Sub

Also even if I run the cmd manually and get the List.txt file I get a file not found error on running the code

    Include "MapBasic.def"

Declare Sub Main
Declare Sub ReadTextFileToArray(ByVal txtFilePath as String, myArray() as String)

Sub Main()
Dim myArray() as String    '// create an array to store the table paths
Dim tabName, tabPath, txtFile as String
Dim i as Integer

'// test file
txtFile = "List.txt"

'// create your list of paths text file... then:

Call ReadTextFileToArray(txtFile, myArray) '// populate your array with the table paths from the text file

For i = 1 to UBound(myArray)
    If right$(myArray(i), 3) = "tab" then   '// check that this is a tab file path
        tabPath = myArray(i)    '// get path from array
        Open table tabPath      '// open table
        tabName = TableInfo(0, TAB_INFO_NAME)   '// get table name
        Alter table tabName(drop igds_class,igds_color,igds_graph,igds_style,igds_weigh add elevation_text Char(10) order elevation_text,elevation,contour_le,tile_name,contour_type)   '// alter table
        Update tabName Set elevation_text = elevation+"m"
        Pack table tabName  Graphic Data    '// pack table
    End if
Next    '// go to next element in array

End Sub

Sub ReadTextFileToArray(ByVal txtFilePath as String, myArray() as String)

Dim i as Integer

    i = 1

    Open file txtFilePath for input as #1   '// open text file for input (to read) as #1
    Do Until EOF(1)             '// do until the end of file #1 is reached
        Redim myArray(i)        '// resize array to i
        Input #1, myArray(i)    '// read value from text file
        i = i + 1               '// increment i
    Loop                        '// return to Do Until...

End Sub
  • Try to print out the the command to execute before the run program line and copy it into the mapbasic window in mapinfo. – Zoltan Feb 21 '17 at 7:44
  • I just figured out the issue. >>>path_to_temp_tables = "" has to be a full path >>path_to_temp_tables = "c:\somepath" – GeorgeC Feb 22 '17 at 5:13

Your Answer

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

Browse other questions tagged or ask your own question.