Tên bảng và tên cột lưu trong biến kiểu String.
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

Trong ví dụ sau: tên bảng lưu trong biến kiểu String, tên cột được code cứng (hard-coded). Đoạn code sau sẽ gây lỗi:
dim strTableName as string
dim strValue as string
strTableName = “USA”
strValue= strTableName.state
Sẽ có thông báo lỗi: Unrecognized Command: …
Giải pháp: MapBasic biên dịch “.” và cố gắng tìm chuỗi .state thay cho mong muốn: USA.state. Để MapBasic lấy giá trị mong muốn đó, aliases được sử dụng như ví dụ dưới đây:
dim strTableName as string
dim alsColumn as alias
dim strValue as string
‘assign the table name
strTableName = “USA”
‘Tạo alias
alsColumn = strTableName & “.state”
fetch first from strTableName
‘Lấy giá trị từ alias
strValue = alsColumn
‘Hiển thị giá trị
note strValue
Bình luận bằng Facebook Comments