Results 1 to 2 of 2

Thread: Format in ASP?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    Hi,
    I tryed this:
    <%=format(7,"000")%> in hopes I'd get 007 like in VB

    But I got this:
    Microsoft VBScript runtime error '800a000d'
    Type mismatch: 'format'

    I need to insure three place holders are taken at all times for any integer 1 to 999. Any Help?

  2. #2
    New Member
    Join Date
    Oct 1999
    Posts
    7
    asp Vb Script have only few format functions (currency,percent...), but you can write your own format function. For your example:

    function format(number,length)
    dim i
    if len(number)>length then
    format="ERR"
    else
    for i=1 to length-len(number)
    format=format & "0"
    next
    format=format & number
    end if
    end function

    And then in code just call
    <%format(7,3)%>
    If you wil try to format number in less places then the length of number, you will get ERR.

    Hope it helps, Maxi

Posting Permissions

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



Click Here to Expand Forum to Full Width