Solved

msstdfmt.dll and vbscripts on windows server 2012

Posted on 2013-12-17
3
687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
ieg earned 0 total points
ID: 39726098
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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