Number

From Team Developer SqlWindows Wiki
Revision as of 20:42, 24 September 2008 by DaveRabelink (Talk | contribs)

Jump to: navigation, search

This page covers Number datatype tips & tricks.

Contents


Pointer2.png How to combine two numbers to one and vice versa Pointer.png

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 )


Pointer2.png How to convert a number to string using prefixed zeros Pointer.png

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"




Pointer2.png An alternative way to define a number in boolean expressions Pointer.png

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


Pointer2.png Enter new tip title here Pointer.png

Enter new tip description here