MessageBox display text and variable value in Power Builder
The MessageBox()
built-in function can take different datatypes for its second parameter (message) but if you need to mix different types at once, pbscript does not support to concatenate a string
with another type like a long
or a boolean
e.g "foo" + 42
. To do so, you need to convert other types to text with the string()
function:
MessageBox( 'Message', 'Total events so far' + string(NbrRows))
//or if some other processing needed with the value
MessageBox( 'Message', 'Total events so far' + string(Abs(NbrRows)))
Beware that a null value will propagate to the whole expression in the case where NbrRows
could be null, resulting in no message at all. Using the [general]
format with string()
is a useful trick that will replace a null value with an empty string:
MessageBox( 'Message', 'Total events so far' + string(Abs(NbrRows), '[general]'))
dc03kks
Updated on June 17, 2022Comments
-
dc03kks almost 2 years
i have an easy question but i m stack at the moment and i was wondering if anyone can help me out,
i want to display from the messagebox in powerbuilder inside the box static text and then the value of a variable, ok i can show easily the value like that,
Messagebox( 'Message', NbrRows)
But i want to show inside the box before the value of the variable NbrRows the text, 'Total events so far' and then the variable value. I know that the syndax of the messagebox is like that for example with an exclamation icon
MessageBox("Result", Abs(NbrRows), Exclamation!, OKCancel!, 2)
please any help would be really appreciated,
thank you in advance
-
dc03kks over 8 yearsSeki u just rule thank so much!!!!! very helpfull , and very nice trick, really appreciated!!! once again thank you!!!
-
Terry over 8 yearsActually, the second parameter in MessageBox is overloaded, so it will take booleans, doubles (and anything that will cast to doubles), longlong (ditto), as well as strings. To see this, go to Browser in the IDE, select the System tab, choose systemfunctions in the left pane, expand Functions in the right pane, and scroll down to the messagebox in the list. Nice cheat for debugging. <grin>
-
Seki over 8 yearsthanks @Terry for clarifying the possibility to use one of the overloaded
MessageBox()
. I have changed my answer for not teaching a wrong thing. Actually I so often use message boxes with mixed types in a single message that I forget the possibility to useMessageBox
directly with another type thanstring
. For debugging / tracing code, I find the usageOutputDebugString()
is far more convenient than message boxes.