Index of Functions ------------------ 1: padNum Function Name ( 1): padNum -------------------------------------------------------------------------------- 'Date Created: 18-Dec-2008 11:40:04 AM 'Last Updated: 18-Dec-2008 11:40:04 AM 'Created By : Ira J. Perlow 'Updated By : Ira J. Perlow FUNCTION PadNum AS C (Number=null_value() AS A, Length=10 AS N, Pad_String="0" AS C,Decimal_Places=-1 as N) 'DESCRIPTION: Converts a number to a string and pads the left with a character dim Function_VersionNumber as c dim Function_VersionDate as c Function_VersionNumber="1.00" Function_VersionDate="20081218" dim HelpText as c HelpText=<<%txt% '========================================================================= ' Created by Computer Systems Design & Associates ' Copyright 2008 Computer Systems Design & Associates, All Rights Reserved ' http://www.csda1.com ' ' You may use this code at your own risk in whole or as a part. ' Use in full or part in any application is permitted with proper attributions ' to the source and the full inclusion of this copyright and notice ' except it may not be sold or included as part of any software ' package that primarily is a library of functions or code to be used by ' other developers. '========================================================================= ' PadNum - Version 1.00 Release Date: 20081218 ' ' Syntax C PadNum([* Number[,N length[,C pad_string[,N Decimal_Places]]]]) ' ' ' Purpose: Converts a number to a string and pads the left with a character ' ' Input: Number - A number value. If character, changes it to numeric 1st ' Length - Total Length of character string desired. Default is 10 ' Pad_String - The pad string for the number. If number is negative, ' 1st the negative sign and then the pad character is done ' A null pad string defaults to "0" ' Decimals - negative means use fractions as given, else change decimals to this width ' ' Output: Padded Number ' ' Errors: ' ' Typical Usage: ' ' Examples: ' ?PadNum(1234.56,10,"",3) ' positive number rounded to 3 decimals and zero fill ' ?PadNum(1234.56,10) ' positive number ' ?PadNum(-1234.56,10,"",3) ' negative number rounded to 3 decimals and zero fill ' ?PadNum(-1234.56,10) ' negative number ' ?PadNum("-1234.56",10) ' convert string 1st ' ?PadNum(1234.56,10,"*",3) ' Use asterisk rather than zero for fill ' ?PadNum(1234.56,5) ' Number too big for field ' ?PadNum() ' Returns Help text ' ' Notes: '====================================================================== %txt% OPTION ENCRYPTED_TOKENS ' Set default return value PadNum="" dim tmpn as n IF typeof(Number)=="N" ' Number is numeric IF Decimal_Places>=0 ' Round if using explicit decimal places tmpn=Round(Number,Decimal_Places) ELSE ' Use number as is tmpn=Number END IF ELSE IF typeof(Number) $ "CB" ' Number is character or blob string IF Decimal_Places>=0 ' Convert to number and Round if using explicit decimal places tmpn=Round(val(Number),Decimal_Places) ELSE ' Convert to number tmpn=val(Number) END IF ELSE IF typeof(Number)=="Z" ' If no parameters, display help ui_msg_box("PadNum Help",HelpText) PadNum=HelpText EXIT FUNCTION ELSE ' Unusable number type, so return with null EXIT FUNCTION END IF ' If length <=0, set to width of 10 dim numlen as N IF Length>0 numlen=Length ELSE numlen=10 END IF ' Set sign of number dim sgn as c sgn="" IF tmpn<0 'Leave room for negative sign numlen=numlen-1 ' set sgn character value sgn="-" END IF ' Set absolute value of number dim tmpa as N tmpa=abs(tmpn) ' Convert number to string with needed decimal places dim tmp as c IF decimal_places>=0 tmp=LTRIM(STR(tmpa,25,Decimal_Places)) ELSE ' Convert number to string with all decimal places given tmp=""+tmpa END IF ' Create string of correct width IF len(tmp)<=numlen ' Pad string with specified pad character IF Pad_String=="" ' Pad with "0" if null string tmp=sgn+PADL(tmp,numlen,"0") ELSE tmp=sgn+PADL(tmp,numlen,Pad_String) END IF ELSE ' Length can not hold number so return with sign and string of asterisks tmp=sgn+replicate("*",numlen) END IF ' Return final value PadNum=tmp END FUNCTION End Function ( 1)---------------------------------------------------------------