Microsoft KB Archive/105954

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 11:25, 21 July 2020 by X010 (talk | contribs) (Text replacement - "&" to "&")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Microsoft Knowledge Base

XL: Visual Basic Interprets mm:ss as Month Not Minutes

Last reviewed: June 11, 1997
Article ID: Q105954

The information in this article applies to:

  • Microsoft Excel for Windows, version 5.0
  • Microsoft Excel for the Macintosh, version 5.0
  • Microsoft Excel for Windows 95, version 7.0

SUMMARY

When a date format is evaluated in a Visual Basic module, it may be changed from months to minutes.

The following macro command will return months followed by seconds:

     MsgBox Format(Now, "mm:ss")

While Microsoft Excel uses the format mm:ss for minutes and seconds, Visual Basic uses the format "nn:ss" for minutes and seconds.

This issue will not be seen by using the format "h:mm:ss". Visual Basic will interpret this correctly as hours:minutes:seconds, as this is a less ambiguous format.

MORE INFORMATION

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Example

The following Visual Basic macro creates a message box with three numbers that display the system date and time. The first number is formatted as month and seconds, while the second two numbers display minutes and seconds.

Sub My_string()
   Dim Msg, NL
   NL = Chr(10)
   Msg = Format(Now, "mm:ss") & NL            'Returns "Month & Seconds"
   Msg = Msg & Format(Now, "nn:ss") & NL      'Returns "Minutes & Seconds"
   Msg = Msg & Application.Text(Now, "mm:ss") 'Returns "Minutes & Seconds"
   MsgBox Msg
End Sub

REFERENCES

"Visual Basic User's Guide," version 5.0, pages 111-113

For more information about User Defined Date/Time Formats, choose the Search button in Visual Basic Reference Help and type:

    Formatting Times

Additional reference words: 5.00 7.00

Keywords : kbprg PgmOthr
Version : 5.00 7.00 | 5.00
Platform : MACINTOSH WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 11, 1997
©1997 Microsoft Corporation. All rights reserved. Legal Notices.