The product form of the customer app from the series Building a customer app in Uniface 10 has a button Export CSV.... It should open a save dialog, write all products to the chosen file, and select the file in Windows Explorer.
In the click test, the button did nothing. No dialog, no message, no error in the log. This article is about why, and about handling filebox so that "nothing happens" can't happen again.
Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, October 2026. Paths are shortened to C:/Projects/CustomerApp/.
The first version
activate "SETTINGS_SVC".GET_SETTING("EXPORT_DIR", "", vDir)
filebox/save "*.csv", vDir
if ($status != 1)
return 0
endif
vFile = $result
GET_SETTING reads the export folder from the settings table, with an empty default. In the test database the setting was not set, so vDir was empty. Other forms of the same app passed a default such as "C:/Projects/CustomerApp/export/" here.
The check $status != 1 treats everything that is not "file chosen" as "the user cancelled" and returns silently. That is why nothing at all happened.
What filebox returns
filebox sets $status:
$status |
Meaning |
|---|---|
| 1 | a file was chosen, $result holds the full path |
| 0 | the user cancelled |
| < 0 | error, details in $procerror (-406 is a filebox error) |
The second argument is a default directory. The Uniface documentation says that a directory given there must end with the path separator of the platform - on Windows that is a backslash.
The fix took two steps, and the first one was not enough:
- Passing the same default folder as the other exports,
"C:/Projects/CustomerApp/export/", still gave no dialog - the form now said "Export cancelled.", sofileboxhad returned without a file. - That folder is written with forward slashes (they are easier to keep in settings and SQL strings), so it did not end with the Windows separator. Converting the slashes to backslashes before the call made the dialog open in the export folder.
The fixed version
activate "SETTINGS_SVC".GET_SETTING("EXPORT_DIR", "C:/Projects/CustomerApp/export/", vDir)
vDir = $replace(vDir, 1, "/", "\", -1)
filebox/save "*.csv", vDir
if ($status < 0)
INFO.PRD_DMY = "The file dialog could not be opened (error %%($procerror))."
return -1
endif
if ($status != 1)
INFO.PRD_DMY = "Export cancelled."
return 0
endif
vFile = $result
activate "IMPORT2_SVC".EXPORT_PRODUCTS(vFile, vCount, vError)
if ($status < 0)
rollback
INFO.PRD_DMY = vError
return -1
endif
commit
INFO.PRD_DMY = "%%(vCount) product(s) exported to %%(vFile)."
vWin = $replace(vFile, 1, "/", "\", -1)
spawn $concat("explorer.exe /select,", vWin)
return 0
Three changes:
- A real default folder, the same one the other exports use.
-
$replace(vDir, 1, "/", "\", -1)turns every forward slash into a backslash before the dialog sees it. The last argument-1means "all occurrences". - Three outcomes, three messages. An error now shows the error number, and a cancel says "Export cancelled." instead of nothing.
After the second step, the save dialog opened in the export folder. Cancelling it showed "Export cancelled." in the form's message line.
The same pattern elsewhere
A search of the other forms found the same filebox call with a forward-slash default in two older components. They were left unchanged in this stage and are noted for a later one - a reminder that a pattern copied once is usually copied more than once.
Takeaways
- Never treat "not 1" after
fileboxas "cancelled". Check$status < 0separately and show$procerror. - Give the default directory the Windows separator at the end, and convert slashes right before the call.
- A button that does nothing is worse than a button that shows an error. Every exit path of a button entry should leave a message for the user.
Top comments (0)