Array & JavaScript puzzle

For some time I’ve been using an array to insert a string of text into an i18n before presentation to the user. Works like charm. But for the first time I’ve attempted to insert a number instead of text. Returns gibberish.

This code works:

var vFee = 'abc';
var vTitle = i18n.getI18NMessage('7office.dlg.newuser');
var vMsg = i18n.getI18NMessage('7office.dlg.newuserfee', new Array(vFee));
var vBtn = plugins.dialogs.showQuestionDialog(vTitle, vMsg);
//  returns 'Please approve a one-time charge of $abc.'

This code doesn’t:

var vFee = sevid$sec_to_seven.fee_newuser; // a number field which returns 150
var vTitle = i18n.getI18NMessage('7office.dlg.newuser');
var vMsg = i18n.getI18NMessage('7office.dlg.newuserfee', new Array(vFee));
var vBtn = plugins.dialogs.showQuestionDialog(vTitle, vMsg);
//  returns 'Please approve a one-time charge of $java.lang.Object@1336.'

I’m unsure where the problem lies – with the way I’m understanding arrays or with my JavaScript, or both.

I’ve looked for but haven’t found a way of converting a number to a text string.

===========

10 minutes after posting the above I discover a probably inelegant way to force it to work. But beyond having just code that works, I’d also like to know what’s going on here, what I’m misunderstanding.

Code that works:

var vTemp = sevid$sec_to_seven.fee_newuser; // a number field which returns 150
var vFee = '' + vTemp + '';
var vTitle = i18n.getI18NMessage('7office.dlg.newuser');
var vMsg = i18n.getI18NMessage('7office.dlg.newuserfee', new Array(vFee));
var vBtn = plugins.dialogs.showQuestionDialog(vTitle, vMsg);
//  returns 'Please approve a one-time charge of $150.'

I’m not positive, but judging by your last work-around solution, it looks like there are some Casting issues going on here.

Your code of (var vFee = ‘’ + vTemp + ‘’) is forcing vFee into a String. Otherwise it is seeing vFee as a generic Java Object.

Other ways you could do it…

var vFee = utils.stringToNumber(sevid$sec_to_seven.fee_newuser); //will filter out any non-numeric characters

OR

var vFee = utils.stringTrim(sevid$sec_to_seven.fee_newuser); //will filter out any spaces

If you are familar with pure Java, this would be similar to doing this…

String vFee = (String)sevid$sec_to_seven.fee_newuser;

But, to directly answer your questions, I’m not sure why
var vTemp = sevid$sec_to_seven.fee_newuser;
is not returning a String into vTemp… maybe a question for the Servoy experts?

The problem is, that this

new Array(150)

creates an Array of SIZE 150 without any content.

What you can do is either this

var fee = 150;
var args = new Array();
args[0] = fee;
i18n.getI18NMessage('7office.dlg.newuserfee', args);

or this should also work

var fee = sevid$sec_to_seven.fee_newuser + ''; 
i18n.getI18NMessage('7office.dlg.newuserfee', new Array(fee));

Hope this helps.

I suspect the answer is I was unwittingly creating an array of 150 elements rather than creating an array containing the number 150. Makes sense.

Thanks Patrick and GoldCougar.