0

I'm creating a tool in MapBasic that identifies the PCI clash in 4G I need help:

  1. How do I add database data into MapBasic?
  2. How can I calculate mod values and colour the output in MapInfo based on these calculations?
  • Seems like two questions. I would recommend that you ask one at a time if they in any way are linked. Start with the database. In that case it would be good a bit about what you already have: do you have a MapInfo table with spatial data? Do you need to link attribute information to this table? What database are you using? – Peter Horsbøll Møller Oct 6 '15 at 14:06
  • hmm ok firstly i wanna access my excel data into my mapbasic code.... – sharanya Oct 8 '15 at 5:07
2

Here is a MapBasic function that you can send the name of an Excel file and MapInfo TabFile and it will open the Excel file into MapInfo Pro

Function EXCELOpen(ByVal sExcelFile As String, ByVal sTabFile As String) As String

Dim sCmd, sTab, sRange As String,
    nCols As Integer

OnError GoTo ErrorOccured

EXCELOpen = ""

If NOT FileExists(sExcelFile) Then
    Note "This Excel file does not exist: " & sExcelFile
    Exit Function
End If

If sTabFile = "" Then
    sTabFile = PathToDirectory$(TempFileName$("")) & "RegisteredExcelFile.tab"
ElseIf sTabFile = PathToTableName$(sTabFile) Then
    sTabFile = PathToDirectory$(TempFileName$("")) & sTabFile & ".tab"
End If
sTab = PathToTableName$(sTabFile)

sCmd    = "Register Table """ & sExcelFile & """"
        & " Type XLS"
        & " Titles"
        & " Into """ & sTabFile & """"
Run Command sCmd
Open Table sTabFile

nCols       = TableInfo(sTab, TAB_INFO_NCOLS) - 1
sRange  = "A" + Str$(2)+":"+Left$(chr$(64 + nCols\26),int(nCols > 25)) + Chr$(65 + nCols mod 26) + TableInfo(sTab, TAB_INFO_NROWS)

Close Table sTab

sCmd    = "Register Table """ & sExcelFile & """"
        & " Type XLS"
        & " Titles"
        & " Range """ & sRange & """"
        & " Into """ & sTabFile & """"
Run Command sCmd
Open Table sTabFile

EXCELOpen = sTab

Exit Function
'-------------------------
ErrorOccured:
    Note Err() & " " & Error$() & ": " & EXCELOpen"

End Function

This function is part of the MapBasic Library that I have shared on GitHub. You can find this and other functions for working with Excel in the EXCELLib module.

This function only works with the "classic" XLS format. It doesn't work with the new XLSX format

As for the Mod values you should have a look at the Mod operator. You can even use this operator in an expression when adding a thematic layer to your map.

  • ok this works to input the values from excel sheet into my mapbasic programmn right... – sharanya Oct 15 '15 at 5:18
  • Is there a question in your comment? – Peter Horsbøll Møller Oct 15 '15 at 10:13

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.