DEV Community

Peter + AI
Peter + AI

Posted on

Understanding Uniface $text Function: Easy Message Handling πŸ“

Note: This article was created with AI assistance to help developers understand Uniface 10.4 features better.

What is $text? πŸ€”

The $text function in Uniface 10.4 is a simple way to get message texts and help texts in your application. Think of it as your message library manager that speaks multiple languages! 🌍

Basic Syntax πŸ’»

Using $text is straightforward:

$text(IDString)
Enter fullscreen mode Exit fullscreen mode

Where IDString is the name of your message. Simple, right?

Real World Example 🎯

Let's say you want to display help text for a field. Here's how you do it:

trigger help
  help/noborder $text(HELPTEXT),3,4,7,23
end; help
Enter fullscreen mode Exit fullscreen mode

If you have a naming convention for help messages (like adding _HLP to field names), you can make it even more dynamic:

trigger help ; of field
  help $text("%%$fieldname%%%_HLP")
end; help
Enter fullscreen mode Exit fullscreen mode

Smart Language Features πŸ—£οΈ

Here's where $text gets really clever! It automatically uses your current language and library settings from $language and $variation. If it can't find your message in the current language, Uniface doesn't give up. It falls back to USA language and USYS library. Pretty smart! 🧠

Important Things to Know ⚠️

  • Return Values: You get the text of your message, or message 8006 if the message doesn't exist
  • Where to Use: You can use $text in all component types
  • Server Usage: When running on a server, make sure your text messages are in a UAR file
  • Check Before Using: Use $textexist to check if a message exists before calling $text

Working with Variables πŸ”§

If you store your message ID in a variable, you need to substitute it properly in a string:

vString = "9004"
help $text("%%vString")
Enter fullscreen mode Exit fullscreen mode

Notice the %% before the variable name? That's important! ✨

Quick Example for Labels 🏷️

Want to get text for a label? Easy:

vLabelText = $text(%%$fieldname)
Enter fullscreen mode Exit fullscreen mode

Why Use $text? πŸ’‘

  • Makes your application multilingual ready
  • Keeps messages in one place (runtime libraries)
  • Easy to maintain and update texts
  • Automatic fallback to default language

Pro Tips πŸŽ“

  • Create a consistent naming convention for your messages
  • Always check message existence with $textexist before accessing it
  • Document your message IDs for your team
  • Test with different languages to ensure fallback works

Conclusion πŸŽ‰

The $text function is your friend for managing messages and help texts in Uniface applications. It's simple to use, supports multiple languages automatically, and helps keep your code clean and maintainable. Start using it today and make your application more professional! πŸš€

Happy coding! πŸ‘¨β€πŸ’»πŸ‘©β€πŸ’»

Top comments (0)