Is it possible to get mapbasic to use the current directory for processes?

So rather than the following where WFolder is manually set as the working folder can I get it to just work in the folder where the mbx is?

Include "MapBasic.def"
Include "Menu.def"

Declare Sub Main()
Dim filename, printtext,WFolder as string
Dim rcount,i as Integer

Sub Main()
Close All
'OnError GoTo CaughtEx '// Turn Error handling on
Register Table "D:\Projects\AsCon_data\Output\OceanBreeze_4B_4C\List.txt"  TYPE ASCII Delimiter 9 Titles Charset "WindowsLatin1" Into WFolder+"~MAP0001.TAB"
Open Table WFolder+"~MAP0001.TAB" Hide
Commit Table ~MAP0001 As WFolder+"List.TAB"
Close Table ~MAP0001
Open Table WFolder+"List.TAB"  as List Interactive
Browse * From List

While i<=rcount
    Select * from List where List.RowID=i into RSelection
    Browse * from RSelection
    print RSelection.col1 
    Open Table RSelection.col1 as temptable

' Do some action(s)

    commit table temptable
    close table temptable

CaughtEx:  '// error handling routine
    '// Log error here...
    print Chr$(13)+Chr$(13)+"///////MAIN///////"+Chr$(13)+"FAILED due to:"+Chr$(13)+Error$()+Chr$(13)+"\\\\\\\\\\\\\\\"+Chr$(13)
    Resume Next  '// resume code at line after the one which threw the error
End Sub

To get MBX path you should use command: ApplicationDirectory$(). This command returns string representing your MBX path.

According to MapInfo Reference: "By calling the ApplicationDirectory$() function from within a compiled MapBasic application, you can determine the directory or folder from which the application is running. If no application is running (e.g., if you call the function by typing into the MapBasic window), ApplicationDirectory$() returns a null string."

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.