Solved

msstdfmt.dll and vbscripts on windows server 2012

Posted on 2013-12-17
3
579 Views
Last Modified: 2014-10-29
Hi
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
Andy

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

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

     rs.Open
     rs.AddNew

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

     Format = rs("fldExpression").Value

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

 End Function
0
Comment
Question by:ieg
3 Comments
 

Accepted Solution

by:
ieg earned 0 total points
Comment Utility
Hi
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.
Andy

'''''''''''''''''''''''''''''''''''''''
'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
'See http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
'
'For Custom numeric format strings
'See http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx
'''

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()
Else
    Call sb.AppendFormat ("{0:" & sFormat & "}", vExpression)
    Format = sb.ToString()
End If


End Function
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now