[jawsscripts] function for sorting two segmented strings

  • From: "John Martyn" <johnrobertmartyn@xxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Sat, 24 Mar 2012 09:25:40 -0700

Probably one of the most complex while loops I've ever done, but I wanted to
sort a list of artists from a segmented string with the values of another
segmented string.
There was no JAWS function to do this, so I had to write one up and it may
be useful to you.
Here's the scenario. I have a list of artists, genres, ratings, and recently
played artists in segmented strings. It picks out the favorites based on
some other values such as play counts and play skips, but this leaves you
with an alphabetic segmented string.
It took me a day to think of how to accomplish this but here's the code.


function SortTheSegments(string segment1,string segment2)
;sort the segmented strings from highest to lowest
var
variant newList,
variant exclude,
variant tempList,
int theMax,
int tempMax,
int skipIt,
int trigger,
int safety,
int trigger2,
int safety2,
int trigger3,
int safety3
let theMax = 0
while trigger != 1
;iterate through the list for the highest number
while trigger2 != 1
let safety2 = safety2+1
while trigger3 != 1
let safety3 = safety3+1
if StringToInt (StringSegment (exclude, "|", safety3)) == safety2 then
let skipIt = 1
endif
if safety3 >= StringSegmentCount (exclude, "|") then
let trigger3 = 1
endif
endwhile
let safety3 = 0
let trigger3 = 0

if skipIt == 0 then
let tempList = StringSegment (segment2, "|", safety2)
if theMax < StringToInt (tempList ) then
let theMax = tempList
let tempMax = safety2
endif
if exclude == "" then
let exclude = tempMax
let theMax = 0
endif
else
let skipIt = 0
endif
if safety2 >= StringSegmentCount (segment2, "|") then
let exclude = exclude+"|"+tempMax
let theMax = 0
let trigger2 = 1

endif

endwhile
let safety2 = 0
let trigger2 = 0

if StringSegmentCount (exclude, "|") == StringSegmentCount (segment2, "|")
then
let trigger = 1
endif
endwhile
let trigger = 0
let trigger2 = 0
let safety = 0
let safety2 = 0

;now organize the list
while trigger != 1
let safety = safety+1
While trigger2 != 1
let safety2 = safety2+1
let tempList = StringSegment (exclude, "|", safety2)
if safety == StringToInt (tempList) then
if newList == "" then
let newList = StringSegment (segment1, "|", safety2)
else
let newList = newList+"|"+StringSegment (segment1, "|", safety2)
endif

endif
if safety2 >= StringSegmentCount (segment1, "|") then
let trigger2 = 1
endif
endwhile
let trigger2 = 0
let safety2 = 0

if StringSegmentCount (newList, "|") >= StringSegmentCount (segment2, "|")
then
let trigger = 1
endif
endwhile
return newList
EndFunction



__________�

View the list's information and change your settings at 
//www.freelists.org/list/jawsscripts

Other related posts:

  • » [jawsscripts] function for sorting two segmented strings - John Martyn