Difference between revisions of "Number"
From Team Developer SqlWindows Wiki
(New page: This page covers number datatype tips & tricks. __TOC__ <br> <h2 style="margin:0;background-color:#ddcef2;font-size:120%;font-weight:bold; border:1px solid #afa3bf;text-align:left;color:...) |
DaveRabelink (Talk | contribs) |
||
Line 1: | Line 1: | ||
− | This page covers | + | '''This page covers Number datatype tips & tricks.''' |
__TOC__ | __TOC__ | ||
<br> | <br> | ||
− | < | + | <!------------------------------------------------------------------------------------------------------------------------------> |
− | + | {{TipHeader|How to combine two numbers to one and ''vice versa''}} | |
To combine two numbers into one, use the next function | To combine two numbers into one, use the next function | ||
<pre> | <pre> | ||
Line 20: | Line 20: | ||
− | < | + | <!------------------------------------------------------------------------------------------------------------------------------> |
− | + | {{TipHeader|How to convert a number to string using prefixed zeros}} | |
An easy way to do that is using this function | An easy way to do that is using this function | ||
<pre> | <pre> | ||
Line 39: | Line 39: | ||
− | < | + | <!------------------------------------------------------------------------------------------------------------------------------> |
− | + | {{TipHeader|An alternative way to define a number in boolean expressions}} | |
Look at the next piece of code | Look at the next piece of code | ||
Line 62: | Line 62: | ||
− | < | + | <!------------------------------------------------------------------------------------------------------------------------------> |
+ | {{TipHeader|Enter new tip title here}} | ||
Enter new tip description here | Enter new tip description here |
Revision as of 20:42, 24 September 2008
This page covers Number datatype tips & tricks.
Contents |
How to combine two numbers to one and vice versa 
To combine two numbers into one, use the next function
nCombined = VisNumberMakeLong( nValue1, nValue2)
You can find this function in vtmisc.apl
Beware that the two input parameters must have a value between 0 and 65535.
To get the two values back from the combined number
Set nValue1= SalNumberLow( nCombined ) Set nValue2= SalNumberHigh( nCombined )
How to convert a number to string using prefixed zeros 
An easy way to do that is using this function
sResult = SalFmtFormatNumber( nValue, sPicture )
So if you want to have a string with 5 characters and if nValue results in less characters and should be prefixed with zeros
Set nValue = 12 Set sResult = SalFmtFormatNumber( nValue, "00000" ) ! Picture parameter has 5 zeros specified ! sResult has the value "00012"
An alternative way to define a number in boolean expressions 
Look at the next piece of code
If bOk = TRUE Set nValue = 1 Else Set nValue = -1
It can be rewritten using one line of code using this function from vtmisc.apl
nResult = VisNumberChoose( bExpression, nTrueNumber, nFalseNumber )
So the If/Else construction above can be rewritten to
Set nValue = VisNumberChoose( bOk = TRUE, 1, -1 )
See also String : An alternative way to define a string in boolean expressions
Enter new tip title here 
Enter new tip description here