Page 1 of 2
Displaying integers in a text object?
Posted: 18 Oct 2016 20:27
by GV1
How can I display an integer in a text object?
The following example doesn't work:
Code: Select all
decl val = 9;
setattribute(OctaveLabel.octaveValue, 'content', val);
But if I do the following it works fine:
Code: Select all
setattribute(OctaveLabel.octaveValue, 'content', '5');
Re: Displaying integers in a text object?
Posted: 18 Oct 2016 20:40
by oldgearguy
try this:
Code: Select all
decl val = 9;
setattribute(OctaveLabel.octaveValue, 'content', ''+val);
outside the box man, outside the box.
Re: Displaying integers in a text object?
Posted: 18 Oct 2016 20:42
by MrCorba
You'll have to concatenate the integer and an empty string and this will turn the value into a string. Like this
Code: Select all
decl val = 9;
setattribute(OctaveLabel.octaveValue, 'content', '' + val);
It's not optimal but once you know it it's easy to work around it.
Ah damn, oldgearguy beat me to it
Re: Displaying integers in a text object?
Posted: 18 Oct 2016 20:43
by GV1
oldgearguy wrote:try this:
Code: Select all
decl val = 9;
setattribute(OctaveLabel.octaveValue, 'content', ''+val);
outside the box man, outside the box.
I tried that, it didn't work. Really odd. Unless this is only available in newer updates.
Re: Displaying integers in a text object?
Posted: 18 Oct 2016 20:51
by GV1
Only other thing I can think of is use a monitor object, make it transparent and put a black empty text object over monitor. Urgh. Hackish if I have to do that.
Re: Displaying integers in a text object?
Posted: 18 Oct 2016 21:54
by oldgearguy
GV1 wrote:oldgearguy wrote:try this:
I tried that, it didn't work. Really odd. Unless this is only available in newer updates.
I forgot you were on original hardware. Does this work?
Code: Select all
decl val={0x39};
setattribute (Label, 'content', arraytostring(val));
If it does, that means you'll have to do more math to add 0x30 to each decimal place and do the division to break down the raw number.
Re: Displaying integers in a text object?
Posted: 18 Oct 2016 22:20
by oldgearguy
Here's a quick and dirty way to take a number and array-ify it. You'll probably want to make it more elegant, but you get the idea:
Code: Select all
decl val, tmp;
decl num=4819, i=0, remain;
while (num > 0) {
remain = num % 10;
tmp[i++] = remain + 0x30;
num = floor(num / 10);
}
i--;
while (i >= 0)
val[sizeof(tmp) - i - 1] = tmp[i--];
setattribute (Label, 'content', arraytostring(val));
Re: Displaying integers in a text object?
Posted: 18 Oct 2016 23:17
by GV1
Thanks. I was thinking about doing this. Will give it a shot tomorrow.
Re: Displaying integers in a text object?
Posted: 19 Oct 2016 09:27
by GV1
Testing now. I'm not sure how I can make it more elegant except to contain it in a function ... that's a solid solution to be honest.
Re: Displaying integers in a text object?
Posted: 19 Oct 2016 10:02
by GV1
Works
Code: Select all
setattribute(testTxt, 'content', Helpers.intToString(49));
Thanks!