Example: PDM Autofix

If the custom check you have defined supports an automatic correction, you enter its script on the Autofix Script tab using VBScript. In this example, we will write a script to fix a Sybase IQ index linked with columns with an invalid data type.

The script is initialized with the following line, which must not be altered:
Function %Fix%(obj, outmsg)
At run-time the variable %Fix% is replaced by the name of the fix. The parameter obj contains the object being checked and outmsg, the message to be output.
We begin by defining a certain number of variables after the default function definition:
Dim c 'temporary  index column
Dim col 'temporary column
Dim position
Dim DT_col
Next, we enter the function body, which starts by setting the %Fix% to false (meaning that it does nothing) and then iterates over each of the columns associated with the index and tests their datatype. If a column has a varchar longer than 255, the script outputs a message, deletes the column from the collection of columns associated with the index, and sets the fix to true (it has made a correction):
%Fix% = False
 If obj.type = "LF" or obj.type = "HG" or obj.type = "CMP" or obj.type ="HNG" Then
  For Each c In obj.IndexColumns
   Set col = c.column
   position = InStr(col.datatype,"(") 
   If position <> 0 Then
    DT_col = Left(col.datatype, position -1) 
   Else 
    DT_col = col.datatype
   End If
   If (Ucase(DT_col) = "VARCHAR") And (col.length > 255) Then
    outmsg = "Automatic correction has removed column " & col.Name & " from index."
    c.Delete
    %Fix% = True
   End If
  Next
 End If