I've found the appropriate methods and here is the function (actual function file below):
(here is an example I'm working from and I have also verified the methods at w3schools.com)
[syntax=JavaScript]if ([%1] = 'decnum') {
newhexnum = [%2].toString(16);
nbSetVar ( '[newhexnum]', newhexnum );
}
if ([%1] = 'hexnum') {
newdecnum = (parseInt([%2], 16)) ;
nbSetVar ( '[newdecnum]', newdecnum );
}[/syntax]
Two parameters: [%1] is the type of number being submitted use either decnum or hexnum
[%2] is the number submitted
Script should generate a NB variable populated with the appropriately converted number.
I've created a sample app (below) to submit the variables to the function. It works fine for decimal to hex conversion. I'm having problems with the opposite.
When converting from Hex to Dec this happens:
It says it is expecting a ';' (semicolon) on the line it displays but it has one. I've tried adding a space to no avail.
(what I really don't understand is why it even enacts this section if the conditional IF fails, which it does)
Can someone see my error?
App code: create a new 320x200 app and paste this in:
Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=9
Name=TextEntry1
X=110
Y=27
W=192
H=34
Anchor=0
VarName=[DecVal]
Align=1
EditNumber=Yes
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=8
Name=Text1
X=10
Y=29
W=86
H=32
Anchor=0
Font=Arial
FontSize=16
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\qr\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs32\cf0 Decimal}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=1
TabOrder=3
ObjectType=8
Name=Text2
X=12
Y=90
W=86
H=32
Anchor=0
Font=Arial
FontSize=16
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\qr\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs32\cf0 Hex}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=1
TabOrder=4
ObjectType=9
Name=TextEntry2
X=111
Y=84
W=192
H=34
Anchor=0
VarName=[HexVal]
Align=1
EditChars=1234567890abcdefABCDEF
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=5
ObjectType=13
Name=RadioButton1
X=116
Y=131
W=76
H=25
Anchor=0
Text=Hex2Dec
Align=1
VarName=[RadioGroup1]
InitState=0
ObjAction=SetVar "[decval]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=6
ObjectType=13
Name=RadioButton2
X=116
Y=152
W=76
H=25
Anchor=0
Text=Dec2Hex
Align=1
VarName=[RadioGroup1]
InitState=0
ObjAction=SetVar "[hexval]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=7
ObjectType=3
Name=PushButton1
X=219
Y=134
W=89
H=42
Anchor=0
Text=Convert
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=If "[RadioGroup1]" "=" "Hex2Dec"¶Call "convertHexDec" "hexnum" "[HexVal]"¶AlertBox "Decimal Equivalent" "The decimal equivalent of [hexval] is|[newdecnum]"¶Endif¶If "[RadioGroup1]" "=" "Dec2Hex"¶Call "convertHexDec" "decnum" "[DecVal]"¶AlertBox "Hex Equivalent" "The hexadecimal equivalent of [decval] is|[NewHexNum]"¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=8
Code: Select all
{NeoBook Function}
Version=5.80
Language=JScript
Comment=Describe number being submitted as hexnum (hexadecimal) or decnum (decimal). Submit number to convert. |If hexnum ---> returns NB variable [newdecnum]|If decnum ---> returns NB variable [newhexnum]
Param=[%1]|Text|Format of number being submitted. Use: hexnum or decnum
Param=[%2]|Number|Number being submitted for conversion
{End}
if ([%1] = 'decnum') {
newhexnum = [%2].toString(16);
nbSetVar ( '[newhexnum]', newhexnum );
}
if ([%1] = 'hexnum') {
newdecnum = (parseInt([%2], 16)) ;
nbSetVar ( '[newdecnum]', newdecnum );
}