Text to Number Question

I think this one has an easy answer. I just can’t find it!

I’m trying to return values as a number from variables by concatenating text with the current index. The problem is that the output is the literal text value of the concatenation (f1, t1, m1, f2, t2, m2, etc.).

var f1 = 1; t1 = 5; m1 = 60
var f2 = 6; t2 = 11; m2 = 55
var f3 = 12; t3 = 23; m3 = 50

for (var i = 1; i <=3; i++)
{
controller.newRecord
qty_from = ‘f’ + i
qty_to = ‘t’ + i
margin = ‘m’ + i
}

Can the actual value of the variable be retuned as a number in this way?

Here’s a link to a good javascript reference
(it’s written by netscape, but I believe they closed their dev website where it originally came from)
http://www.byteshift.de/javascript-1415/CoreReferenceJS15/number.htm

Syntax
parseInt(string[, radix])

The parseInt function parses its first argument, a string, and attempts to return an integer of the specified radix (base). For example, a radix of 10 indicates to convert to a decimal number, 8 octal, 16 hexadecimal, and so on. For radixes above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.

If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values. Leading and trailing spaces are allowed.

If the radix is not specified or is specified as 0, JavaScript assumes the following:

  • If the input string begins with “0x”, the radix is 16 (hexadecimal).

  • If the input string begins with “0”, the radix is eight (octal). This feature is deprecated.

  • If the input string begins with any other value, the radix is 10 (decimal).

If the first character cannot be converted to a number, parseInt returns NaN.

maarten:
Here’s a link to a good javascript reference
(it’s written by netscape, but I believe they closed their dev website where it originally came from)
http://www.byteshift.de/javascript-1415/CoreReferenceJS15/number.htm

Syntax
parseInt(string[, radix])

The parseInt function parses its first argument, a string, and attempts to return an integer of the specified radix (base). For example, a radix of 10 indicates to convert to a decimal number, 8 octal, 16 hexadecimal, and so on. For radixes above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.

If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values. Leading and trailing spaces are allowed.

If the radix is not specified or is specified as 0, JavaScript assumes the following:

  • If the input string begins with “0x”, the radix is 16 (hexadecimal).

  • If the input string begins with “0”, the radix is eight (octal). This feature is deprecated.

  • If the input string begins with any other value, the radix is 10 (decimal).

If the first character cannot be converted to a number, parseInt returns NaN.

You can also read about the parseInt function and see a couple of simple
examples in the printed Servoy Developer Edition Volume 2: Reference
Guide, in chapter 6.5 “Methods: JS Lib”, section 6.5.3 “Methods, JS Lib,
Math”, page 144.

If you don’t yet have the printed documentation, you can also access
information about the parseInt function in the online Servoy Help Navigator:
-Choose Help>Help (F1).
-Open the “Index” tab.
-Enter “method” in the topic entry box at the top.
-Select “JS Lib” from the index entries.
-Double click on “Methods, JS Lib, Math”.

Once the topic is open:
-Choose Tools>Find.
-Enter “parse” in the “Find What” criteria.
-Press the “Find Next” button to highlight the first instance of “parse” - in
this case, the “parseInt” function.


Marc Norman
Servoy