Working with counters in Uniface? The numset function is your go-to tool for initializing counter values! π
This article is based on the official Uniface Documentation 10.4, with AI assistance helping to structure this developer-friendly guide.
π What is numset?
The numset statement allows you to initialize the value of a specified counter in Uniface. It's particularly useful when working with the numgen statement for generating sequential numbers.
π οΈ Syntax
numset CounterName, InitialValue {, LibraryName}
π Parameters Breakdown
| Parameter | Data Type | Description |
|---|---|---|
| CounterName | String | Name of the counter in the specified library |
| InitialValue | Number | Integer value between -2,147,483,648 and 2,147,483,647 |
| LibraryName | String | Library name (optional - defaults to SYSTEM_LIBRARY) |
β Return Values
The function returns status values in $status:
- 0: Success! π Counter was initialized successfully
- -1: Error occurred (value out of range, counter not defined, or repository access issue)
β οΈ Common Error Codes
Keep an eye on $procerror for these common issues:
-
-2 to -12: Database I/O errors -
-16 to -30: Network I/O errors -
-1108 (UPROCERR_COUNTER): Repository access or undefined counter -
-1203 (UPROCERR_RANGE): Value out of range
π‘ Practical Example
Here's how to reset a counter named "NUMBERCOUNTER" in the "SALES_LIBRARY" to 0:
; trigger: Detail
numset "NUMBERCOUNTER", 0, "SALES_LIBRARY"
commit "$UUU"
message "Counter %%NUMBERCOUNTER in SALES_LIBRARY set to 0."
π― Key Points to Remember
- ποΈ Component Compatibility: Works in all component types except self-contained Reports and Services
- π Library Management: Different projects can maintain separate counter sets using libraries
- π Integration: Perfect companion to the
numgenstatement for counter-based operations - πΎ Don't forget: Always commit your changes with
commit "$UUU"
π Best Practices
- Always specify the library name for better organization
- Handle error conditions by checking
$statusand$procerror - Use meaningful counter names for better code maintenance
- Remember to commit changes to persist counter values
Happy coding with Uniface! π
Top comments (0)