msstdfmt.dll and vbscripts on windows server 2012

Posted on 2013-12-17
Last Modified: 2014-10-29
I have been using a format function based on msstdfmt.dll for many years to help format dates within a VBScript both on clients and servers. (see below).
It appears that msstdfmt.dll is no longer installed as standard on 64 bit operating systems.
Searching the web the advice seems to be to download a copy and register it on the machine running the VBScript.
Is this a sensible thing to do, or will it cause problems?
More importantly, is there a different way of achieving this code. It doesn't seem right to issue VBScript that can't run on a native operating system without downloading old components.

Hope you can help

Function Format(vExpression, sFormat)
     set fmt = CreateObject("MSSTDFMT.StdDataFormat")
     fmt.Format = sFormat

     Set rs = CreateObject("ADODB.Recordset")
     rs.Fields.Append "fldExpression", 12


     Set rs("fldExpression").DataFormat = fmt
     rs("fldExpression").Value = vExpression

     Format = rs("fldExpression").Value

     rs.close: Set rs = Nothing: Set fmt = Nothing

 End Function
Question by:ieg

Accepted Solution

ieg earned 0 total points
ID: 39726098
Well with a bit of help from a friend I have re-written this function to use the .Net Framework and not MSSTDFMT.
For those of you interested the code is below.

'Filename : fn_Format.vbs
'Author   : Andy Latham/Peter Willingham
'Date     : 17/12/2012
'This Function simulates the VBA Format Function
'I used to use
'Set fmt = CreateObject("MSSTDFMT.StdDataFormat")  
'but MSSTDFMT is not installed as standard in windows 7 or later
'This technique uses the .Net framework to format strings
'It can be used like this
'MsgBox Format("5/6/2007","yyyy-MM-dd")
'MsgBox Format(123456, "#,##0.00")
'MsgBox Format(now(), "dd/MM/yyyy hh:mm:ss")
'Please note that some of the custom formatting strings are different between
'MSSTDFMT and the .Net framework (e.g. dd/mm/yyyy is now dd/MM/yyyy)
'For Custom Date and Time format strings
'For Custom numeric format strings

Function Format(vExpression, sFormat)

Dim sb
Set sb = createobject("System.Text.StringBuilder")

If isDate(vExpression) Then
    Call sb.AppendFormat ("{0:" & sFormat & "}", cdate(vExpression))
    Format = sb.ToString()
    Call sb.AppendFormat ("{0:" & sFormat & "}", vExpression)
    Format = sb.ToString()
End If

End Function

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Custom auto number 6 64
Problem to open text file 11 110
Message Logon Windows 2012 R2 Server 16 26
Using VBScript. How to obtain the recomended paging file size? 8 52
Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question