WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Number Conversion

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Format Numbers with Commas - Using MSScriptControl

 Keywords:  Format Number Currency Integer MSScriptControl Comma Eval Method FormatNumber FormatCurrency

Simple Example

#DefineFunction udfFormatNumber(num)
   oS = CreateObject("MSScriptControl.ScriptControl")
   oS.Language = "VBScript"
   oS.AllowUI = @FALSE
   STRING=oS.Eval(: 'FormatNumber(%num%,0)')
   oS = 0
   Return(STRING)
#EndFunction

n='123456789234567'
result = udfFormatNumber(n)
Message("Number with Commas",result)

Format Currency and Numbers





;Stan Littlefield / Deana Falk, June 3, 2011
#DefineFunction udfNumberFormat(mode,num,zeros,leading,neg,grp)
;--------------------------------------------------------------------------------;
;udfNumberFormat : Format Numbers or currency using the regional or user defined
;                  settings
;
;--------------------------------------------------------------------------------;
;Mode        : 0 - Number - formatted as a number. (DEFAULT)
;            : 1 - Currency - function returns an expression formatted as a
;                   currency value using the currency symbol defined in the
;                   computer's control panel.
;
;Num         : Number to format
;
;Zeros       : Indicates how many places to the right of the decimal are
;               displayed. Default is -1 (the computer's regional settings are used)
;
;Leading     : Indicates whether or not a leading zero is displayed for fractional values:
;               -2 = TristateUseDefault - Use the computer's regional settings
;               -1 = TristateTrue - True
;               0 = TristateFalse - False

;Neg         : Indicates whether or not to place negative values within parentheses
;               -2 = TristateUseDefault - Use the computer's regional settings
;               -1 = TristateTrue - True
;               0 = TristateFalse - False ;
;
;Grp         : Indicates whether or not numbers are grouped using the group
;               delimiter specified in the computer's regional settings
;               -2 = TristateUseDefault - Use the computer's regional settings
;               -1 = TristateTrue - True
;               0 = TristateFalse - False ;
;
;                                                                                 ;
;--------------------------------------------------------------------------------;
;returns    : @true if success, @false if failure                                ;
;--------------------------------------------------------------------------------;
;                                                                                 ;
;--------------------------------------------------------------------------------;


   ; Check for Valid Inputs
   If !IsNumber(num) Then num=0
   If !IsNumber(mode) Then mode=0
   If !IsNumber(zeros) Then zeros=-1
   If !IsNumber(leading) Then leading=-2
   If !IsNumber(neg) Then neg=-2
   If !IsNumber(grp) Then grp=-2

   If zeros > 0 || zeros <-2 Then zeros=-1
   If leading > 0 || leading <-2 Then leading=-2
   If neg > 0 || neg <-2 Then neg=-2
   If grp > 0 || grp <-2 Then grp=-2


   oS = CreateObject("MSScriptControl.ScriptControl")
   oS.Language = "VBScript"
   oS.AllowUI = @FALSE
   cformat=""
   If mode==0
      cFormat="FormatNumber(":num:",":zeros:",":leading:",":neg:",":grp:")"
   Else
      cFormat="FormatCurrency(":num:",":zeros:",":leading:",":neg:",":grp:")"
   EndIf

   ;Pause('Format', cFormat)
   retvalue = oS.Eval(cFormat)

   ;Clean Up
   oS = 0
   Return(retvalue)
#EndFunction

; Currency Format
n="123456"
result= udfNumberFormat(1,n,"","","","")
Message("",result)
result= udfNumberFormat(1,n,"","","","")
Message("",result)
n='123456789234567'
result= udfNumberFormat(1,n,"","","","")
Message("",result)

; Number Format
n="123456"
result= udfNumberFormat(0,n,"","","","")
Message("",result)
result= udfNumberFormat(0,n,"","","","")
Message("",result)
n='123456789234567'
result= udfNumberFormat(0,n,"","","","")
Message("",result)

Article ID:   W18011
Filename:   Format Numbers with Commas - Using MSScriptControl.txt
File Created: 2011:06:03:12:00:08
Last Updated: 2011:06:03:12:00:08