Define() establishes specific data definitions. This involves defining columns/fields and creating the tables/files with optional indexes.
Below is the code for Define():
'
' Define()
'
' Open the table, if it exists. Otherwise create and open the table
'
Sub Define()
Dim do_create As Boolean = False
Console.WriteLine("DEFINE")
Try
Console.WriteLine(ControlChars.Tab + "Open table...")
MyTable.Open("custmast", OPEN_MODE.NORMAL_OPEN)
Catch
' table does not exist. Try to create it
do_create = True
End Try
If (do_create) Then
' create the table
Console.WriteLine(ControlChars.Tab + "Add fields...")
Try
MyTable.AddField("cm_custnumb", FIELD_TYPE.FSTRING, 4)
MyTable.AddField("cm_custzipc", FIELD_TYPE.FSTRING, 9)
MyTable.AddField("cm_custstat", FIELD_TYPE.FSTRING, 2)
MyTable.AddField("cm_custrtng", FIELD_TYPE.FSTRING, 1)
MyTable.AddField("cm_custname", FIELD_TYPE.VSTRING, 47)
MyTable.AddField("cm_custaddr", FIELD_TYPE.VSTRING, 47)
MyTable.AddField("cm_custcity", FIELD_TYPE.VSTRING, 47)
Console.WriteLine(ControlChars.Tab + "Create table...")
MyTable.Create("custmast", CREATE_MODE.NORMAL_CREATE)
MyTable.Open("custmast", OPEN_MODE.NORMAL_OPEN)
Catch E As CTException
Handle_Exception(E)
End Try
Else
Check_Table_Mode(MyTable)
End If
End Sub
'
' Check_Table_Mode()
'
' Check if existing table has transaction processing flag enabled.
' If a table is under transaction processing control, modify the
' table mode to disable transaction processing
'
Sub Check_Table_Mode(ByVal table As CTTable)
Try
' get table create mode
Dim mode As CREATE_MODE = table.GetCreateMode()
' check if table is under transaction processing control
If ((mode And CREATE_MODE.TRNLOG_CREATE) <> 0) Then
' change file mode to disable transaction processing
mode = mode Xor CREATE_MODE.TRNLOG_CREATE
table.UpdateCreateMode(mode)
End If
Catch E As CTException
Handle_Exception(E)
End Try
End Sub