Skip to main content

Script to Find Medians

I've never had to find the Median of a range of numbers in a project until this past week.  I first looked to see if there were any functions that will perform this task more quickly (and none exist in VBscript), and I also checked if any exist in SQL Server.  Now if you're running SQL Server 2012 or later then there is a function called PERCENTILE_DISC but we currently run on 2008 R2.

So, I wrote a simple script that will get the job done (some of the ones I found online were more complex than needed to be).  Note, this is in VBScript but you can use the logic and change the syntax based on whatever language you're using.

'FIRST PUT YOUR VALUES IN A STRING (YOU MIGHT HAVE TO READ THIS IN FROM THE DATABASE
Dim aryValues : aryValues = "107, 105, 104, 102, 102, 102, 101, 99, 99, 99, 98, 97, 97, 97, 95, 94, 93"

aryValues = split(aryValues,",")
Dim aryCount : aryCount = ubound(aryValues) + 1 'NUMBER OF VALUES IN OUR STRING
Dim MiddleCount : MiddleCount = aryCount / 2 'DIVIDE THE NUMBER BY 2 TO GET THE MIDDLE VALUE

if inStr(MiddleCount,".5") then 'Count is ODD
      MiddleCount = cint(replace(MiddleCount,".5",""))
        
else 'Count is Even
        'WHEN THERE'S AN EVEN AMOUNT OF NUMBERS YOU AVERAGE THE 2 MIDDLE NUMBERS

        vMedian = ( cint(aryValues(MiddleCount-1)) + aryValues(MiddleCount) ) / 2

end if

Comments

Popular posts from this blog

Cybersecurity

I went to a Cybersecurity conference last week hosted by  Data Connectors and I want to give kudos for the job well done in running the conference.  First of all they held the conference in a very nice Westin downtown, so the facility was great!  The Vendors were very informative and the presentations were very good as well!  There was a good mix of breaks so we could talk with the Vendors and learn more about their products.  The lunch and snacks were good too!  Always a plus! But back to the subject of Cybersecurity.  It's truly amazing all the cyber attacks made against companies, websites, home owners, smart phones, etc.  I don't remember the exact numbers, but at the time they presented them, I was amazed how high it is, and how high it's going to be.  Everything on the web is exposed and most people don't realize the bad exposure that's out there.  Yes, bigger companies are spending lots of money to protect their data but the ...

My Twitter Followers Have Gone Down!

If you're a Twitter user you might have heard or seen on your account the number of followers go down.  For some of us, those numbers might be minimal.  I have a Twitter account @NKYSports which I use in connection with one of my High School sports website NKYSports.com.  Last week I had about 6,070 followers.  That number today is down about 100.  But I have heard users who have followers over 50K, 100K, etc. losing thousands and thousands of "so-called" followers. So what happened?  Twitter has started cleaning accounts due to fake news scandals and data privacy.  That equates to about 1 million accounts the past quarter (2nd Q of 2018).  Twitter CEO Jack Dorsey says improving the health of the platform is critical for future growth. Twitter has been a great tool for my website, but I also like getting updates sent directly to my phone to get the latest news, sports, weather, etc.  I know what to believe and not to believe as well!...

File Size Upload Limits using Godaddy Hosting

I've been working on a new project for a friend of mine and came across an issue with trying to upload photos using the infamous freeASPUpload code.  I've used the code in the past for some past projects but don't recall having issues with limits on uploading files. I'm posting this on my blog b/c there's nothing on the internet that discusses this (or at least I wasn't able to find any explanations), and hopefully this can be a resource to someone else that comes across the same issue. Now I know there are other options, utilities, etc. for uploading pics/files/etc. but  freeASPUpload  is simple, I've used it in the past, and this project is pretty basic.  So, if you want to change the upload file size limit you will first want to go into your Godaddy's hosting account.  Next go into the Virtual Directories option, then click on Directory Properties.  Towards the bottom there is a section called "Maximum size of entity body of an ASP request...