DEV Community

Peter + AI
Peter + AI

Posted on

🔢 Understanding Uniface 10.4's numset Function: Initializing Counters Made Easy

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}
Enter fullscreen mode Exit fullscreen mode

📝 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."
Enter fullscreen mode Exit fullscreen mode

🎯 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 numgen statement for counter-based operations
  • 💾 Don't forget: Always commit your changes with commit "$UUU"

🚀 Best Practices

  1. Always specify the library name for better organization
  2. Handle error conditions by checking $status and $procerror
  3. Use meaningful counter names for better code maintenance
  4. Remember to commit changes to persist counter values

Happy coding with Uniface! 🎉

Top comments (0)