|
For some key values, like a Customer Number, you want to make sure that the value is unique. This method can be used to check any value for uniqueness within its database.
1. Open your Form in Designer.
2. Open the Programming Editor by selecting Program Layout from the Commands Control Panel. Select GLOBAL CODE from the Element dropdown.
Type the program in the Program Editor window.
// Return value of 0 means NOT UNIQUE.
// Return value of 1 means UNIQUE.
Function CheckUnique() as Int
var vRetVal as Int
var vLVal as String
var vLEName as String
vRetVal = 1
vLVal = ""
vLEName = @ElementName(ThisElement)
vLVal = @XLookup(@FN, ThisElement, vLEName, vLEName)
If @Len(vLVal) > 0
{
vRetVal = 0
}
Return(vRetVal)
End Function
|
3. Select the element you want to check from the Element dropdown. Select On Element Change from the Event dropdown.
Type the program in the Program Editor window.
var vUnique as Int
vUnique = CheckUnique()
If vUnique = 0
{
@MsgBox("Value is not unique!", "", "")
}
4. Test your program by selecting Test Program from the Test menu. Fix any syntax errors that are reported.
5. When you are finished, select Close Program Editor from the File menu. Your programming changes will be saved when you save your Form.
You should add code to take whatever action is appropriate for your application if the value is not unique, or the check fails.
Don't forget to save and reconcile your changes!
NOTE: Remember, you can't test X command programming in Preview Mode.
More Information: @XLookup() Programming Guide - Page 127 - 128
|