Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8952469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:52:51+00:00 2026-06-15T13:52:51+00:00

I am a C student in VBScript coding and need a little help. My

  • 0

I am a C student in VBScript coding and need a little help.

My code executes a split command as follows:

outputArray = split(Description,” “)

With the individual words from Description now in an array, I want to sort the array based on the string length for each word.

So, for example, if Description is equal to “this is an example of a description” then my array values are [this, is, an, example, of, a, description], right?

But I want to resort the array so that the longest words are first, i.e. the array items are ordered by string length. So, after some VBScript code that I can’t seem to figure out, the array would look like this: [description, example, this, an, is, of, a]

If there’s a tie for string length, the secondary sort would be alphabetical.

I would greatly appreciate some help on this from an A student out there. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:52:52+00:00Added an answer on June 15, 2026 at 1:52 pm

    As VBScript has no native sort, it needs a little help from a friend. In your case – because of your more complex sorting criteria – the friend should not be .Net’s ArrayList, JScript’s sort, or sort.exe (introduced here), but a disconnected ADO recordset:

      Const adInteger          =          3 ' 00000003
      Const adVarChar          =        200 ' 000000C8
    
      Dim sInp : sInp = "this is an example of a description"
      Dim aInp : aInp = Split(sInp)
      WScript.Echo "A:", Join(aInp)
    
      Dim oRS : Set oRS = CreateObject("ADODB.Recordset")
      oRS.Fields.Append "Word", adVarChar, 50
      oRS.Fields.Append "Length", adInteger
      oRS.Open
      Dim sWord
      For Each sWord In aInp
          oRS.AddNew
          oRS.Fields("Word").value = sWord
          oRS.Fields("Length").value = Len(sWord)
          oRS.UpDate
      Next
      oRS.Sort = "Length DESC, Word"
    
      Dim aTable : aTable = oRS.GetRows()
      ReDim aOut(UBound(aTable, 2))
      Dim i
      For i = 0 To UBound(aOut)
          aOut(i) = aTable(0, i)
      Next
      WScript.Echo "B:", Join(aOut)
    

    output:

    A: this is an example of a description
    B: description example this an is of a
    

    For background start here.

    ADDED – For ArrayList Aficionados:

    A Disconnected Recordset should be your first choice, if your data is in essence
    tabular (sort criteria involves more than one aspect/property of the elements).

    ArrayList sorting in VBScript is good for simple cases only, because – AFAIK –
    you can’t pass a compare function to the sort method. Please, prove me wrong!

    If you must use an ArrayList for more complex sorting, consider the
    Schwartzian transform:

    1. prepare customized temporary data to ease comparisons
    2. sort
    3. recover original data

    In code:

      Const csSep = "|"
      Const cnMax = 100
    
      Dim sInp : sInp = "this is an example of a description"
      Dim aInp : aInp = Split(sInp)
      WScript.Echo "A:", Join(aInp)
    
      Dim oNAL : Set oNAL = CreateObject( "System.Collections.ArrayList" )
      Dim oSB  : Set oSB  = CreateObject( "System.Text.StringBuilder" )
      Dim sWord
      For Each sWord In aInp
          oSB.AppendFormat_3 "{0,4}{1}{2}", 100 - Len(sWord), csSep, sWord
          sWord = oSB.ToString()
          oSB.Length = 0
          oNAL.Add sWord
      Next
      oNAL.Sort
    
      ReDim aOut(oNAL.Count - 1)
      Dim i
      For i = 0 To UBound(aOut)
          aOut(i) = Split(oNAL(i), csSep)(1)
      Next
      WScript.Echo "B:", Join(aOut)
    

    output:

    A: this is an example of a description
    B: description example this an is of a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A student of mine submitted some C++ code similar to the following one. The
student code| student.Name |Region Name|Location Name| Assets Details | I have to display asset
An student here who needs help with the logic of the following: I have
The student is back. Thanks for you help an patience ;) I'm using a
I am a CS student and I'd love to make a command line chess
Im a student developer using Qt to build a GUI to help users plot
I am a Student..and right now trying to develop code for android..that shows nearby
Another student asked me what could be wrong with his C code. I successfully
Working to help a student with his project trying to get his Div to
A student in my class brought this to my attention, and I didn't have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.