Search code examples
messageboxpowerbuilder

MessageBox display text and variable value in Power Builder


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


Solution

  • 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]'))