JavaScript Toolkit

 

 

This page contains the source code to a range of JavaScript code elements that we have found useful when developing EIS pages for Brio Intelligence. The bulk of the code is made up of a range of utility functions but we have also included some code fragments to show the way these can be used. An appreciation of the standards we use for Brio development is recommended – document details available on request.

The code is grouped into a number of areas – the table of contents below shows the overall organisation

 

General utility functions.
showDeveloperView .
Logon functions
reconnect
showOCEDetails.
sample code for a Process button. 3
Controlling limits.
setLimitValue.
deselectVarLimits.
limitByWeek.
limitByDay.
copyLimit 
copyLimit2DD.
copyDD2Limit
Validation functions.
valDateNumMonth.
valDateTxtMonth
Formatting functions
formatToDP.
formatCurrency.
fmtDateNumMonth
autofitAllCols
Miscellaneous.
makeCode128.

 

General utility functions

showDeveloperView

 Show or hide the toolbars, section catalog etc. We also hide all sections that end users are not likely to use – usually the query sections but could also include results sets.  

This version also creates default file export names – the file name for export is defined as a global and we use different default export directories in production and test.

 

/*----------------------------------------------------------
-- Function: showDeveloperView
-- Parameters: abShow - true/false
--
-- Turn catalog, toolbars etc on/off according to parameter
-----------------------------------------------------------*/
function showDeveloperView(abShow){

var nSecNum; //Number of Sections
var nSecCount; //Section count

ShowSectionTitleBar = true;
ShowMenuBar = true;
ShowCatalog = abShow;
ShowStatusBar = abShow;

Toolbars["Sections"].Visible = abShow;
Toolbars["Formatting"].Visible = abShow;
Toolbars["Standard"].Visible = abShow;

//Loop turning section properties on/off
nSecNum = ActiveDocument.Sections.Count;
for (nSecCount = 1; nSecCount <= nSecNum; nSecCount++){

   if ( (ActiveDocument.Sections[nSecCount].Type != bqEIS) && (ActiveDocument.Sections[nSecCount].Type != bqReport) ) {
      ActiveDocument.Sections[nSecCount].Visible = abShow;
   }
   ActiveDocument.Sections[nSecCount].ShowOutliner = abShow;
} //end for

//Developer objects on Selector
Sections["Selector"].Shapes["cbGlobals"].Visible = abShow;
Sections["Selector"].Shapes["cbGlobals"].Enabled = abShow;
Sections["Selector"].Shapes["cbTest"].Visible = abShow;
Sections["Selector"].Shapes["cbTest"].Enabled = abShow;

//Set export file location
g_sFileName = abShow ? g_sDevExportDir : g_sPrdExportDir
g_sFileName += g_sExportName
Console.Writeln('Export file '+ g_sFileName)

}
g_showDeveloperView = showDeveloperView;  // define global version

Home

 

Logon functions

 

reconnect

Connects to database – will disconnect first. Assumes globals for User ID and Password have been defined in the EIS – these are supplied as parameters.

 

/*----------------------------------------------------------------------------------------------------------
-- Function: reconnect
-- Result: boolean true if connected, else false
-- Parameters: asQuery - Section Name
-- asId - Userid
-- asPw - Password
--
-- Disconnect and reconnect query to database
-----------------------------------------------------------------------------------------------------------*/
function reconnect( asQuery, asId, asPw) {

var sOCEName = ActiveDocument. Sections[ asQuery].DataModel.Connection.Filename


//Disconnect from database
ActiveDocument.Sections[ asQuery ].DataModel.Connection.Disconnect();

//Reload OCE in case details have changed
ActiveDocument. Sections[ asQuery ].DataModel.Connection.Open(sOCEName);

// Set Query connection parameters
ActiveDocument.Sections[ asQuery ].DataModel.Connection.Username = asId;
ActiveDocument.Sections[ asQuery ].DataModel.Connection.SetPassword( asPw );

// Log Query on to database
try{
ActiveDocument.Sections[ asQuery ].DataModel.Connection.Connect();
} catch(errConnect) {
Alert('Database connection error: '+errConnect.toString())
return false;
}

// Connected OK
return true;

}
g_reconnect = reconnect;  // define global version

 

Home

 

showOCEDetails

We will often show the name of the OCE being used on an EIS page. We will also show the SID (for Oracle databases). This is helpful in a production environment where database locations can vary and a query using the wrong database can cause problems.

 

/*----------------------------------------------------------------------------------------------------------
-- Function: showOCEDetails
-- Result: 
-- Parameters: asQuery - Section Name
-- asLabel - Label on Logon page to update
--
-- updates OCE details on Logon page
-----------------------------------------------------------------------------------------------------------*/
function showOCEDetails(asQuery,asLabel){


ActiveDocument.Sections["Logon"].Shapes[asLabel].Text = ActiveDocument.Sections[asQuery].DataModel.Connection.Filename + ' 
- ' +ActiveDocument.Sections[asQuery].DataModel.Connection.HostName
Console.Writeln('OCE details updated')

}
g_showOCEDetails = showOCEDetails; // define global version

 

Home

 

sample code for a Process button

//*----------------------------------------------------------------------------------------------------------
-- Project: XYZ
-- Desc: Process queries if connected
--
--ChngLog Author Reason
-- 09Jul01 ANT Created
-----------------------------------------------------------------------------------------------------------*/

//If any query unconnected - go to logon section
if ( ActiveDocument.Sections["Received Query"].DataModel.Connection.Connected == false || 
ActiveDocument.Sections["Returned Query"].DataModel.Connection.Connected 
==false || 
ActiveDocument.Sections["Issued Query"].DataModel.Connection.Connected 
== false ) {
Alert("You are not connected to XYZ - Please logon to Process","Connect Error");
Sections["Logon"].Activate();
return;
} //end connect test


//Disconnect from Queries and then Reconnect - in case of timeout
if( g_reconnect( "Query", g_sXYZId, g_sXYZPassword ) ){
// add limit setting code here
//..
// add limit copying from earlier sections
//..
ActiveDocument.Sections["Query"].Process();
} else {
Sections["Logon"].Activate();
return;
}

 

Home

 

Controlling limits

This is probably the biggest category of utilities. We have found it extremely useful to create a wide range of utility functions to control limit dialogs. We will often rely on a variable limit dialog rather than coding the limit functionality onto the EIS page.

Many of these functions will be varied slightly to suit the query in which they are used – default date ranges being a good example.

 

setLimitValue

A very simple utility to put a selected value into a limit.

/*----------------------------------------------------------------------------------------------------------
-- Function: setLimitValue
-- Parameters: asQueryName, asLimitName, adValue,adOperator
--
-- Set custom limit on <asLimitName> in section <asQueryName>
-- to <adValue> using <adOperator>
-- set single value in limit
-----------------------------------------------------------------------------------------------------------*/
function setLimitValue(asQueryName, asLimitName, advalue,adOperator) {

var oLimit = ActiveDocument.Sections[asQueryName].Limits[asLimitName];

oLimit.Operator = adOperator;
oLimit.SelectedValues.RemoveAll();
oLimit.CustomValues.RemoveAll();

oLimit.CustomValues.Add(adValue);
oLimit.SelectedValues.Add(adValue);


}
g_setLimitValue = setLimitValue; // define global version

 

Home

 

deselectVarLimits

It’s quite helpful to remove previous entries from variable limits – it forces the user to enter something and also avoids the inadvertent use of pre-selected values.

 

/*----------------------------------------------------------------------------------------------------------
-- Function: deselectVarLimits
--
-- Remove SelectedValues for any variable Limits
--
-- 05Dec02 ANT Created
-----------------------------------------------------------------------------------------------------------*/
function deselectVarLimits(){

var nSecNum; //Number of Sections
var nSecCount; //Section count
var oSection; //Section
var nLmt; //Limit Count

//Loop for all sections
nSecNum = ActiveDocument.Sections.Count;
for (nSecCount = 1; nSecCount <= nSecNum; nSecCount++){
oSection = ActiveDocument.Sections[nSecCount];

   if( oSection.Type == bqQuery ) {

//Loop for Limits in Section
      for (nLmt = 1; nLmt <= oSection.Limits.Count; nLmt++){
         if(oSection.Limits[nLmt].VariableLimit){
            oSection.Limits[nLmt].SelectedValues.RemoveAll();
         }
      } //end Limit loop
   } // end if right section type

} //end Section loop
}
g_deselectVarLimits = deselectVarLimits;  // define global version

 

Home

 

limitByWeek

One of a number of default date ranges.

 

/*----------------------------------------------------------------------------------------------------------
-- Function: limitByWeek
-- Parameters: asQueryName, asLimitName, adDate
--
-- Set custom limit on <asLimitName> in section <asQueryName>
-- to <adDate> between 00:00:00 one week ago and 23:59:59 yesterday
-----------------------------------------------------------------------------------------------------------*/
function limitByWeek(asQueryName, asLimitName, adDate) {

// dates are objects &v passed by ref - we'll make two new objects

var dStart = new Date(Date.parse(adDate.toGMTString())) - 7;
var dEnd = new Date(Date.parse(adDate.toGMTString()));
//Start datetime is beginning of supplied date

dStart.setHours(0);
dStart.setMinutes(0);
dStart.setSeconds(0);

//End datetime is 1 second to midnight

dEnd.setHours(23);
dEnd.setMinutes(59);
dEnd.setSeconds(59);

var oLimit = ActiveDocument.Sections[asQueryName].Limits[asLimitName];
oLimit.SelectedValues.RemoveAll();
oLimit.CustomValues.RemoveAll();

oLimit.CustomValues.Add(dStart);
oLimit.CustomValues.Add(dEnd);
oLimit.SelectedValues.Add(dStart);
oLimit.SelectedValues.Add(dEnd);

}
g_limitByWeek = limitByWeek;  // global version

 

Home

 

limitByDay

Set the limit to a specified 24 hour range – usually yesterday.

 

 

/*----------------------------------------------------------------------------------------------------------

--   Function:    limitByDay

-- Parameters:    asQueryName, asLimitName, adDate

--

-- In section <asQueryName>, set custom limit on <asLimitName> to be range

--    between 00:00:00 and 23:59:59 on <adDate>

-----------------------------------------------------------------------------------------------------------*/

function limitByDay(asQueryName, asLimitName, adDate) {

// dates are objects & passed by ref - we'll make two new objects

var dStart     = new Date(Date.parse(adDate.toGMTString()));

var dEnd       = new Date(Date.parse(adDate.toGMTString()));

 

//Start datetime is beginning of supplied date

dStart.setHours(0);

dStart.setMinutes(0);

dStart.setSeconds(0);

 

//End datetime is 1 second to midnight

dEnd.setHours(23);

dEnd.setMinutes(59);

dEnd.setSeconds(59);

 

var oLimit = ActiveDocument.Sections[asQueryName].Limits[asLimitName];

oLimit.SelectedValues.RemoveAll();

oLimit.CustomValues.RemoveAll();

oLimit.CustomValues.Add(dStart);

oLimit.CustomValues.Add(dEnd);

oLimit.SelectedValues.Add(dStart);

oLimit.SelectedValues.Add(dEnd);

 

}     // end of limitByDay definition

 

g_limitByDay = limitByDay;          //Define global version of function

 

Home

 

copyLimit

We often find that we are applying the same limit values to multiple sections – either because we are accessing more than one database or because we are running a particularly complex query. This function will let us use variable limits on one query section and then copy these limit values to other sections before they are processed.

 

/*----------------------------------------------------------------------------------------------------------

--   Function:    copyLimit

-- Parameters:    asSourceSection, asSourceLimitName,

--                            asDestSection,   asDestLimitName

--

-- Copies the selected CUSTOM values from one limit to another, duplicating

--  other settings (Ignore, Operator, Nulls etc)

-- NOTE: Internal Error on attempt to set limit values on a computed column

-----------------------------------------------------------------------------------------------------------*/

function copyLimit(asSourceSection, asSourceLimitName, asDestSection, asDestLimitName) {

var oSourceObj = ActiveDocument.Sections[asSourceSection].Limits[asSourceLimitName]

var oDestObj         = ActiveDocument.Sections[asDestSection].Limits[asDestLimitName]

 

// read source limit settings

var bIgnore =  oSourceObj.Ignore

var bIncludeNulls    = oSourceObj.IncludeNulls

var nNegate = oSourceObj.Negate

var nOperator  = oSourceObj.Operator

var nSelectedValuesCount = oSourceObj.SelectedValues.Count

var nSelVal

 

// set the limits on the second query

if (bIgnore) {

            oDestObj.Ignore= true

}

else {

oDestObj.Ignore = false

   oDestObj.IncludeNulls = bIncludeNulls

   oDestObj.Negate = nNegate

   oDestObj.Operator = nOperator

   oDestObj.SelectedValues.RemoveAll()

   oDestObj.CustomValues.RemoveAll()

 

            for (var i=1; i<=nSelectedValuesCount; i++) {

                  nSelVal=(oSourceObj.SelectedValues[i])

                  oDestObj.CustomValues.Add(nSelVal)

                  oDestObj.SelectedValues.Add(nSelVal)

            } // end for all limit values

 

} // end else

 

}     // end of copyLimit definition

 

g_copyLimit = copyLimit;            //Define global version of function

 

Home

 

copyLimit2DD

Copies limit values to a dropdown. We also allow the top value (i.e. the one seen by the user first) to be preset.

 

/*----------------------------------------------------------------------------------------------------------

--   Function:    copyLimit2DD

-- Parameters:    asSrcSct    - source section name (table or results) on which limit is set

--                            asSrcLmt    - source limit name

--                            asTgtSct    - target section

--                            asTgtDD     - target dropdown name

--                            asTopLbl    - label to add to top of list

--

-- Populate drop down (or list box) with available limit values

-- & add supplied value to top

--

-- v1.0  01Jan02  Maddox Ford Created

------------------------------------------------------------------------------------------------------------*/

function copyLimit2DD(asSrcSct, asSrcLmt, asTgtSct, asTgtDD, asTopLbl){

//use pointers for clarity

var oLimit = ActiveDocument.Sections[asSrcSct].Limits[asSrcLmt];

var oDD =  ActiveDocument.Sections[asTgtSct].Shapes[asTgtDD];

 

//empty the dropdown

oDD.RemoveAll();

 

//Reset the limit values

oLimit.RefreshAvailableValues();

var nAvailValues = oLimit.AvailableValues.Count;

 

//update the dropdown

oDD.Add( asTopLbl );

for (var iVal=1; iVal <= nAvailValues ; iVal++){

oDD.Add(oLimit.AvailableValues[iVal]);

}

}     // end of copyLimit2DD definition

 

g_copyLimit2DD = copyLimit2DD;            //Define global version of function

 

Home

 

copyDD2Limit

Copies a dropdown selection to a limit. Should work on a multi-select list box too.

 

/*----------------------------------------------------------------------------------------------------------

--   Function:    copyDD2Limit

-- Parameters:    asSrcSct    - source EIS section name, containing dropdown

--                            asSrcDD     - source dropdown name

--                            asTgtSct    - target section name (table or results)

--                            asTgtLmt    - target limit name

--

-- Populate limit with values selected from DD

--

-- v1.0  18Feb02  Maddox Ford Created

------------------------------------------------------------------------------------------------------------*/

function copyDD2Limit(asSrcSct, asSrcDD, asTgtSct, asTgtLmt){

//use pointers for clarity

var      oDD =  ActiveDocument.Sections[asSrcSct].Shapes[asSrcDD];

var oLimit = ActiveDocument.Sections[asTgtSct].Limits[asTgtLmt];

 

//Reset the limit

oLimit.SelectedValues.RemoveAll();

oLimit.CustomValues.RemoveAll();

 

//update the limit

for (var iRow=1; iRow <= oDD.SelectedValues.Count ; iRow++){

oLimit.CustomValues.Add(oDD[iRow]);

oLimit.SelectedValues.Add(oDD[iRow]);

}

}     // end of copyDD2Limit definition

 

g_copyDD2Limit = copyDD2Limit;            //Define global version of function

 

Home

 

Validation functions

If the user is entering dates onto an EIS page, you’ll need to validate them before using them. Here are a couple of functions to use.

 

valDateNumMonth

Checks whether a string contains a valid date.

This version is for use with a numeric month, if you use text months, see valDateTxtMonth, below.

 

/*---------------------------------------------------------------------------------------------

--   Function:    valDateNumMonth

-- Parameters:    asIn  -  String to be validated

--     Result:    Returns date or error message as appropriate

--

-- Is string a date of format d-mm-yy or dmmyy, with 2d or 4d year?

---------------------------------------------------------------------------------------------*/

function valDateNumMonth(asIn){

if( asIn.length < 5 || asIn.length > 10 ){return 'Invalid Length'};

 

//Declare local variables and constants

var nDay, nMonth, nYear, dIn;

var DAYSINMONTH = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

var DELIMITERS = "-/ ._";

var DIGITS = "0123456789"

 

// 1st character must be a number

if( DIGITS.search(asIn[0]) == -1 ){return "Invalid Day"};

 

// Split entry into nDay, sMonth, nYear

if( DELIMITERS.search(asIn[1]) > -1 ){

 

// Must be d-mm-yy

nDay = Number( asIn[0] );

nMonth = Number(asIn.substr(2, 2));

nYear = Number( asIn.substr(5));

 

} else {

if( DELIMITERS.search(asIn[2]) > -1 ){

// Must be dd-mm-yy

nDay = Number( asIn.substr(0, 2) );

nMonth = Number( asIn.substr(3, 2) );

nYear = Number( asIn.substr(6) );

 

} else {

if( asIn.length == 5 || asIn.length == 7 ){

// Must be dmmyy or dmmyyyy

nDay = Number( asIn[0] );

nMonth = Number( asIn.substr(1, 2) );

nYear = Number( asIn.substr(3) );

 

} else {

// Must be ddmmyy or ddmmyyyy

nDay = Number( asIn.substr(0, 2) );

nMonth = Number( asIn.substr(2, 2) );

nYear = Number( asIn.substr(4) );

}

}

}

 

// Valid day number?

if(isNaN(nDay)){return "Invalid Day"};

 

// Valid month number?

if (isNaN(nMonth)){return "Invalid Month"};

 

// Valid year number?

if(isNaN(nYear)){return "Invalid Year"};

 

// Change 2-digit to full year, catering for Y2K

if( nYear <= 50 ){

nYear += 2000;

} else {

if( nYear < 1000 ){nYear += 1900};

}

 

// Is this a leap year?

if( nYear%100 == 0 ){

// Year divisible by 100, so must be divisible by 400 to be a leap year

if( nYear%400 == 0 ){DAYSINMONTH[1] = 29};

} else {

// Year not divisible by 100, so must be divisible by 4 to be a leap year

if( nYear%4 == 0 ){DAYSINMONTH[1] = 29};

}

 

// Is day appropriate for month?

if( nDay<1 || nDay > DAYSINMONTH[nMonth] ){

return "Invalid Day for Month";

}

 

// All checks OK - return date

dIn = new Date(nYear, nMonth, nDay);

return dIn;

 

}     // end of valDateNumMonth definition

 

g_valDateNumMonth = valDateNumMonth;            //Define global version of function

 

Home

 

valDateTxtMonth

Checks whether a string contains a valid date.

This version is for use where month are in text form, if you use numeric months, see valDateNumMonth, above.

 

/*---------------------------------------------------------------------------------------------

--  Function:     valDateTxtMonth

--  Parameters:   asIn  -  String to be validated

--

-- Is string a date of format d-mmm-yy or dmmmyy, with 2d or 4d year

-- Returns date or error message as appropriate

---------------------------------------------------------------------------------------------*/

function valDateTxtMonth(asIn){

if( asIn.length < 6 || asIn.length > 11 ){return 'Invalid Length'};

 

//Declare local variables and constants

var sMonth, nDay, nMonth, nYear, dIn;

var MONTHS = "janfebmaraprmayjunjulaugsepoctnovdec";

var DAYSINMONTH = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

var DELIMITERS = "-/ ._";

var DIGITS = "0123456789"

 

// 1st character must be a number

if( DIGITS.search(asIn[0]) == -1 ){return "Invalid Day"};

 

// Split entry into nDay, sMonth, nYear

if( DELIMITERS.search(asIn[1]) > -1){

 

// Must be d-mmm-yy

nDay = Number( asIn[0] );

sMonth = asIn.substr(2, 3);

nYear = Number( asIn.substr(6));

 

} else {

if( DIGITS.search(asIn[1]) == -1 ){

// Not a delimiter, not a digit, so must be dmmmyy

nDay = Number( asIn[0] );

sMonth = asIn.substr(1, 3);

nYear = Number( asIn.substr(4));

 

} else {

// Must start with dd....

nDay = Number(asIn.substr(0,2));

 

if( DELIMITERS.search(asIn[2]) == -1 ){

// Must be ddmmmyy

sMonth = asIn.substr(2, 3);

nYear = Number( asIn.substr(5));

 

} else {

// Must be dd-mmm-yy

sMonth = asIn.substr(3, 3);

nYear = Number( asIn.substr(7));

}

}

}

 

// Valid day number?

if(isNaN(nDay)){return "Invalid Day"};

 

// Valid 3-letter month?

nMonth = MONTHS.search(sMonth.toLowerCase());

if (nMonth%3 != 0){

return "Invalid Month";

} else {

nMonth =  nMonth/3;

}

 

// Valid year number?

if(isNaN(nYear)){return "Invalid Year"};

 

// Change 2-digit to full year, catering for Y2K

if( nYear <= 50 ){

nYear += 2000;

} else {

if( nYear < 1000 ){nYear += 1900};

}

 

// Is this a leap year?

if( nYear%100 == 0 ){

// Year divisible by 100, so must be divisible by 400 to be a leap year

if( nYear%400 == 0 ){DAYSINMONTH[1] = 29};

} else {

// Year not divisible by 100, so must be divisible by 4 to be a leap year

if( nYear%4 == 0 ){DAYSINMONTH[1] = 29};

}

 

// Is day appropriate for month?

if( nDay<1 || nDay > DAYSINMONTH[nMonth] ){

return "Invalid Day for Month";

}

 

// All checks OK - return date

dIn = new Date(nYear, nMonth, nDay);

return dIn;

 

}     // end of valDateTxtMonth definition

 

g_valDateTxtMonth = valDateTxtMonth;            //Define global version of function

 

Home

 

Formatting functions

You can usually rely on Brio to format data for you. When you are writing formatted numbers onto an EIS page you’ll have to do the formatting by hand and JavaScript doesn’t have built in formatting capabilities.

 

formatToDP

Simple formatting of a number to n decimal places.

 

/*----------------------------------------------------------------------------------------------------------

--   Function:    formatToDP

-- Parameters:    anNum, anDP

--     Result:    Returns text string with number <anNum> formatted to <anDP> places

-----------------------------------------------------------------------------------------------------------*/

function formatToDP(anNum, anDP){

      var sNum

 

// eliminate fractional part for now

anNum = Math.round(anNum*Math.pow(10,anDP));

sNum = anNum.toString();

 

if (anDP != 0) {

// decimal place required

            sNum = sNum.slice(0,(sNum.length - anDP)) + ' .'  + sNum.slice(sNum.length - anDP)

}

 

return sNum

 

}     // end of formatToDP definition

 

g_formatToDP = formatToDP;          //Define global version of function

 

Home

 

formatCurrency

Currency formatting, adds a currency symbol, puts commas into the number and formats to  n decimal places.

 

/*----------------------------------------------------------------------------------------------------------

--   Function:    formatCurrency

-- Parameters:    anAmount, anDP

--

-- Returns text string of number <anAmount> formatted to <anDP> places

-- (usually 2 or 0), with separators every third place

-- and a currency symbol prefix

-----------------------------------------------------------------------------------------------------------*/

function formatCurrency(anAmount,anDP){

      //Define Constants – edit to suit requirements

var CURRENCYSYMBOL = '£';

var SEPARATOR = ',' ;

 

//Define Local variables

var nPoint;

var sOutput = '';                      //blank

var sNum;

 

// round to right number of decimal places

// eliminate fractional part for now

anAmount = Math.round(anAmount*Math.pow(10,anDP));

sNum = anAmount.toString();

 

if (anDP != 0) {

// decimal place required

sNum = sNum.slice(0,(sNum.length - anDP)) + '.'  + sNum.slice(sNum.length - anDP);

}

 

// standard format function to here,  now add the Separators & Currency

 

nPoint = sNum.indexOf('.');

if (nPoint == -1) { nPoint = sNum.length};

 

for (var i=0 ; i < nPoint; i++) {

if (((nPoint - i)%3 == 0)&&( i!=0)) {

sOutput += SEPARATOR;

}

sOutput += sNum.substr(i,1);

}

 

sOutput += anum.substr(nPoint); // fails gracefully for 0 DP

 

return CURRENCYSYMBOL + sOutput;

 

    // end of formatCurrency definition

 

g_formatCurrency  = formatCurrency;             //Define global version of function

 

Home

 

fmtDateNumMonth

Formats a Javascript date as a string of form dd/mm/yy.

 

/*----------------------------------------------------------------------------------------------------------

--   Function:    fmtDateNumMonth

-- Parameters:    adDate - Javascript date

--     Result:    String as dd/mm/yy

-----------------------------------------------------------------------------------------------------------*/

function fmtDateNumMonth(adDate){

   //Format day

   var sDay = adDate.getDate();

   if (sDay <= 9 ) {sDay = '0' + sDay} ;

 

   //Format month - NB: JavaScript months start at 0

   var sMonth = adDate.getMonth()+1;

   if  (sMonth <= 9) { sMonth  = '0' +sMonth };

 

   //Format Year

   var sYear = adDate.getFullYear();

 

   var sDateString = sDay +'/' + sMonth +'/' + sYear;      

 

   return sDateString;

 

}     // end of fmtDateNumMonth definition

 

g_fmtDateNumMonth = fmtDateNumMonth;      //define global version of function

 

Home

 

autofitAllCols

Set All columns in given section to 'autofit'

 

/*---------------------------------------------------------------------------------------------

--   Function: autofitAllCols

-- Parameters: asSctName  - Name of section

--

-- Set All columns in given section to 'autofit'

--

-- v1.0  01Jan02  Maddox Ford Created

---------------------------------------------------------------------------------------------*/

function autofitAllCols( asSctName ) {

 

      //Consider all columns in section

var oColumns = ActiveDocument.Sections[asSctName].Columns;

var iColCnt = oColumns.Count;

 

for(var iCol = 1; iCol <= iColCnt; iCol++){

oColumns[iCol].ResizeToBestFit()

}

 

} // end of autofitAllCols definition

 

g_autofitAllCols = autofitAllCols;

 

Home

 

Miscellaneous

There’s always a section like this – i.e. the functions that can’t be categorised!

 

makeCode128

Used to create code128 barcodes for reports that have barcodes on them.

 

/*----------------------------------------------------------------------------------------------------------

--   Function:    makeCode128

-- Parameters:    asData      -  Data Value to be encoded

--     Result:    code 128 string for barcoding

 

-- takes a data value and creates a code 128 string for barcoding

-- assumes the use of the AdvC128 font from bizfonts

--    www.bizfonts.com/code128fonts/

-- this version sticks with Character set A

-- adapted from an example supplied in

-- "Visual Basic / VBA Functions for Bar Code Fonts 2.11"

-- "Copyright, IDAutomation.com, Inc. 2000. All rights reserved."

-----------------------------------------------------------------------------------------------------------*/

function makeCode128(asData){

//Define constants

var STARTDIGIT = 203;            //Start Digit for Character Set A

var STOPDIGIT = 206;

 

//Following not used in this function

//var STARTDIGIT = 204;          //Start Digit for Character Set B

//var STARTDIGIT = 205;          //Start Digit for Character Set C

//var FNC1DIGIT  = 202;

 

//Define local variables

var sCodedData = "";

var nCheckDigit = 0;

var nTotal = STARTDIGIT - 100;   // A character set weighted value is  char - 100

 

      //Only code non-null string

if (asData != null ) {

 

            //Loop for each character to calculate check sum

            for (var i=0;i<asData.length;i++) {

                  if (asData.charCodeAt(i) < 135 ) {

                        nTotal = nTotal +( (1+i) *(asData.charCodeAt(i) -32) );

                  } else {

                        nTotal = nTotal +( (1+i) *(asData.charCodeAt(i) -100) );

                  }    

            }

 

   nCheckDigit = nTotal%103;

            if (nCheckDigit == 0 ) {

                  nCheckDigit = 194

   } else if (nCheckDigit < 95 ) {

                  nCheckDigit  += 32

   } else {

         nCheckDigit  += 100

}

 

   sCodedData = String.fromCharCode(STARTDIGIT);         //start

            sCodedData += asData;                                             //data

   sCodedData += String.fromCharCode(nCheckDigit); //checksum

            sCodedData += String.fromCharCode(STOPDIGIT);         //stop

 

} // end if not null argument

 

return sCodedData

 

    // end of function definition

 

g_makeCode128 = makeCode128;        //Define global version of function

 

Home

 

 

 

Home | Profile | Market Specialisations | Technical Expertise | Culture | Clients | Opportunites | Find Us © Maddox Ford 2004