+ Reply to Thread
Results 1 to 4 of 4

Invalid "format string" argument in Format fuction

  1. #1
    jjk
    Guest

    Invalid "format string" argument in Format fuction

    Hi,

    I was wondering if there is any way to check for invalid "format
    string" argument in the Format function.
    As far as I can see it accepts all string combinations. Is there any
    exception handling or boounds check that I can place here.
    I ask this because I have to wrap the format functionality and want to
    watch out for any side effects.

    Thanks,
    Jayant

    Ref from Help:

    Format Function
    Returns a Variant (String) containing an expression formatted according
    to instructions contained in a format expression.

    Syntax:
    Format(expression[, format[, firstdayofweek[, firstweekofyear]]])

    expression - Required. Any valid expression.
    format - Optional. A valid named or user-defined format expression.
    firstdayofweek - Optional. A constant that specifies the first day of
    the week.
    firstweekofyear - Optional. A constant that specifies the first week of
    the year.


  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Jayant,

    You can include an Error handler in your code.

    Example;

    Sub FormatData()

    On Error Goto FormatError

    Text = Format(<String>, <Format>)

    Exit Sub

    FormatError:

    MsgBox "The Format specified is Invalid", vbOKOnly + vbCritical

    End Sub


    In the code, "FormatError:" is a Line Label and must not haveany spaces before it.

    Sincerely,
    Leith Ross

  3. #3
    jjk
    Guest

    Re: Invalid "format string" argument in Format fuction

    Thanks Leith.

    I was wondering if there is any list/formula for invalid formats.
    The Format method works for any gibberish specified as format without
    throwing an exception or error.

    Regards,
    Jayant


  4. #4
    Tom Ogilvy
    Guest

    Re: Invalid "format string" argument in Format fuction

    VBA help has a list of valid characters and symbols and what they are used
    for. In xl97 at least, there are several help topics with lists depending
    on what you are formating - numbers, dates.

    --
    Regards,
    Tom Ogilvy


    "jjk" <jayantjk@gmail.com> wrote in message
    news:1118780091.942687.11730@z14g2000cwz.googlegroups.com...
    > Thanks Leith.
    >
    > I was wondering if there is any list/formula for invalid formats.
    > The Format method works for any gibberish specified as format without
    > throwing an exception or error.
    >
    > Regards,
    > Jayant
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1