VBScript Minimum and Maximum functions

Results 1 to 4 of 4

Thread: VBScript Minimum and Maximum functions

  1. #1
    Mike - UK Guest

    Default VBScript Minimum and Maximum functions

    I&#039;m fairly new to ASP/VBScript and am having a spot of trouble tracking down a standard VBScript function which returns the minimum/maximum of a list of numbers.<BR><BR>I would have expected something along the lines of <BR><BR>"Min (2,3,4,5,6,7,8,9)" to return 2.<BR><BR>However, this isn&#039;t the right syntax ("undefined variable")<BR><BR>Anyone out there more experienced care to point me in the right direction (I&#039;ve checked 4Guys, Microsoft&#039;s VBScript reference and various other searches without luck).<BR><BR>Thanks in advance,<BR><BR>Mike.<BR><BR>ps I could write my own but seems little point if there&#039;s one already built into VBSctipr!

  2. #2
    Darren Neimke Guest

    Default I hate to tell you this but...

    unless i&#039;m sorely mistaken, there&#039;s no such vbscript function which accepts a list of numbers and returns the smallest.<BR><BR>here&#039;s a link which may be useful to you:<BR><BR> http://flws.com.au/showusyourcode/codeLib/code/sortArray.asp?catID=1<BR><BR>HTH<BR>Darren<BR>[ darren@showusyourcode.com ]<BR>

  3. #3
    Join Date
    Dec 1969

    Default Actually, I don't think you can...

    There is no way in VBS to write a function such as MAX or MIN that takes any number of arguments. Sorry about that.<BR><BR>The best you could do would be to write a function that would get the min/max value of an array of values.<BR><BR>Darren&#039;s idea of sorting the array would work, too, though if all you need is min/max you can do that a lot faster than doing a full sort.<BR><BR>

  4. #4
    Mike - UK Guest

    Default RE: Actually, I don't think you can...

    Darren/Bill,<BR><BR>Thanks guys ... you&#039;ve saved me from thinking I&#039;m going mad!<BR><BR>I only actually need the min and max so will write a small function to do it (surprised about it being excluded from VBScript).<BR><BR>The article on "bubble sorts" really brings back memories of hours coding in BASIC!<BR><BR>Best wishes,<BR><BR>Mike.<BR><BR>

Posting Permissions

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