VERIFIED SOLUTION i
X

How To Assign strings column values using table names stored in variables in MapBasic.

UPDATED: April 20, 2017


One example of assigning a table name and the column name stored in a String variable. 

A table name and the column name stored in a String variable from a selection.  

dim tmpname as string
tmpname = SelectionInfo(SEL_INFO_SELNAME)
dim tmp_pin as alias
Dim Pin_Field as string
pin_Field = ".ColumnName"
tmp_pin = tmpname+pin_Field
dim strValue as string
strValue =tmp_pin
note strvalue

User-added image

---------------------------------------------------------------------------------------------------------------------------------------------------------------

In the next example displays a table name in a String variable, and the column name is hard-coded. 


When storing a table name in a variable the following code doesn't work:

dim strTableName as string
dim strValue as string
strTableName = "USA"
strValue= strTableName.state

It will return the error: Unrecognized Command: ..

Resolution:
 MapBasic is interpreting the "." and trying to figure out string.state instead of what is wanted: USA.state. To let MapBasic know that the later is the desired value, aliases can be used as per the following example:

dim strTableName as string
dim alsColumn as alias
dim strValue as string
'assign the table name
strTableName = "USA"
'create the alias
alsColumn = strTableName & ".state"
fetch first from strTableName
'get the value from the alias
strValue = alsColumn
'display
note strValue
 

Environment Details


 

Downloads

  • No Downloads