Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently January 15th, 2025, 2:05 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Script Help Required
PostPosted: April 5th, 2005, 3:14 pm 
Offline

Joined: January 10th, 2005, 11:08 am
Posts: 63
Location: Birmingham, United Kingdom
Opus: All between ver Pro XE 4.5 and Ver 9.62
OS: Windows XP Pro SP3
System: Intel Core2 Duo 2.67Ghz, Matrox Millennium G550 dual head graphics card
I am making a production that uses a self-evaluation feature. Basically users pick from various lists and we end up with four values which I am storing in variables.
What I need to do is to be able to present these values in accending order, along with the corresponding variable name. I will be showing them from left to right on a group of vectors which resemble stepping stones in a lake.
I am a very basic scripter and I have already realised that I can use Math.max to find the largest and Math.min to find the smallest value, but I am stuck sorting the rest out. I plan to store the results in arrays (unless you can think of something easier).
:idea: Any clever ideas would be gratefully received.
Andy Thompson.


Top
 Profile Visit website  
 
 Post subject:
PostPosted: April 6th, 2005, 1:26 pm 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
Hi,


Thank you for your enquiry.

I'm not sure if I have correctly visualised your requirements, but please find attached a sample publication which should hopefully operate in the way you require.

The Selection page of this publication displays four listboxes, each containing the values 1 to 10. The first listbox stores the selected value into a variable named apples, the second listbox stores to bananas, the third carrots and the last stores to dates.

On the Sorted page, I have added a script object which first creates a new array named items containing the four item names as strings ("apples", "bananas", "carrots" and "dates"), then creates another array named values which contains the values of the apples, bananas, carrots and dates variables.

I have then used a bubble sort algorithm to sort the values in the values array in ascending numerical order, whilst simultaneously making the same swaps in the items array. This leaves me with a sorted values array and a rearranged items array.

I have then used a series of ReplaceSelection() functions to insert each index of the values array into the top four text objects on the page and each index of the items array into the bottom four text objects.

I hope this helps. Please do not hesitate to contact me if you have any further queries or encounter any problems integrating this solution into your publication.

Kind regards,


You do not have the required permissions to view the files attached to this post.

_________________
Robin Garrett
Digital Workshop Technical Support


Top
 Profile Visit website  
 
 Post subject:
PostPosted: April 6th, 2005, 2:12 pm 
Offline

Joined: January 10th, 2005, 11:08 am
Posts: 63
Location: Birmingham, United Kingdom
Opus: All between ver Pro XE 4.5 and Ver 9.62
OS: Windows XP Pro SP3
System: Intel Core2 Duo 2.67Ghz, Matrox Millennium G550 dual head graphics card
Robin, thank you :D ..smashing code, works fine........until...........
you select 10 for any value, then it seems to go a bit adrift.
After a bit of experimenting I found that it ranks the numbers thus
1, 10, 2, 3, 4, etc

Any clues :?:


Top
 Profile Visit website  
 
 Post subject:
PostPosted: April 6th, 2005, 2:25 pm 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
Whoops! It appears to be treating the values as strings, so all of the numbers starting with 1 are grouped together.

The solution is to convert the apples, bananas, carrots and dates variables to numbers using the String.number() function.

This also solves a little problem I had encountered with the original bubble sort algorithm which appeared to be sorting identical values in reverse order (so if apples and bananas both equalled 1, bananas would be shown first). To correct this, I changed the line:

Code:
if (values[j+1] < values[j]) {

to:
Code:
if (values[j+1] <= values[j]) {

However, converting the values to numbers resolves the original issue, so I have reverted this back to the original syntax.

Please find attached the modified publication.

Kind regards,


You do not have the required permissions to view the files attached to this post.

_________________
Robin Garrett
Digital Workshop Technical Support


Top
 Profile Visit website  
 
 Post subject:
PostPosted: April 6th, 2005, 2:48 pm 
Offline

Joined: January 10th, 2005, 11:08 am
Posts: 63
Location: Birmingham, United Kingdom
Opus: All between ver Pro XE 4.5 and Ver 9.62
OS: Windows XP Pro SP3
System: Intel Core2 Duo 2.67Ghz, Matrox Millennium G550 dual head graphics card
Thank you Robin......now works perfectly
I knew I could rely on you.
Andy Thompson :D


Top
 Profile Visit website  
 
 Post subject:
PostPosted: April 6th, 2005, 3:00 pm 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
In retrospect, I should have realised that the values were being stored as text as I was using the Store selected text option in the properties of the Listbox objects.

:| - Doh!

Another solution would have been to use the Store index of selected item option and add 1 to this number at some point (as number 1 in the list is actually index 0). This would ensure that the values were in number format before the bubble sort took place.

Kind regards,

_________________
Robin Garrett
Digital Workshop Technical Support


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group