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
Solved

msstdfmt.dll and vbscripts on windows server 2012

Posted on 2013-12-17
3
656 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…

839 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