Normal Topic Sorting a string array (Read 2334 times)
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Sorting a string array
Dec 6th, 2018 at 9:36pm
Print Post Print Post  
I have the following programming to create a list of shipments from my company.  The programming is working well EXCEPT it is not sorting as expected.

I'm trying to sort the array vLine.  I expect it to sort on the vPartNo variable into alphabetical order, but no sort is happening!

Also, is there a way to sort on two variables?  It would be great to sort on vPartNo, then vDate!

Thanks for your help!

NH User




var vElements as string
var vcnt as int
var vloop as int
var vname as string
var vNN as Int
var vTree as INT
var vname1 as string
VAR VLOOK AS STRING
var VLook1 as string
var vA as Int
var pnctest as string
VAR DATE1 AS double
var vStep as String
var vField as String
var vPFS1 as string
var vPFS2 as string
var stepn as string
var vElast as String
var vFabric as String
var vHandle as Int
var VNoOfRecords as Int
var vPartNo as string
var vDCNo as string
var vLocation as string
var vStatus as string
var vDate as string
var vQuantity as String
var vLine as string
var vTemp1 as int
var vStr as string



#include "sbasic_include.sbas"




// View Shipment History


If @mode() = 1

{

     vDCNo = @left(Diacom P\N,4)
     
     
     vHandle=@xResultSetSearch(@FN,"Sales", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!PartNo="+vDCNo+"..")

     vLoop=vA

     
     If(vHandle>-1)
     {
     
           vNoOfRecords = @XResultSetTotal(vHandle)

           If vNoOfRecords>100 then vA=vNoOfRecords-100
     
           For vLoop= vA to vNoOfRecords
     
                 xResultSetCurrentPosition(vHandle,vLoop)
     
                 vPartNo = @xResultSetValue(vHandle,"PartNo")
                 vName = @xResultSetValue(vHandle,"Diaphragms")
                 vDate = @xResultSetValue(vHandle,"Date1")
                 vQuantity = @Decimals(@xResultSetValue(vHandle,"PCS"),0)
     
           // create the variable
                 
                 vLine=vline + vPartNo + "  Date: " + vDate + " -- Quantity: " + vQuantity+ @Newline()
     
                 vTemp1=1
                 Next
     
                 xResultSetClose(vHandle)
     }
     
     
     if vTemp1<1
     {
           Writeln("NO PARTS ARE ON ORDER.")
     }
     else
     {
           vStr=@SortStringArray(vLine,0)
           Writeln(vStr)
     }

}
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2483
Joined: Aug 20th, 2003
Re: Sorting a string array
Reply #1 - Dec 6th, 2018 at 9:43pm
Print Post Print Post  
Rather than sorting the StringArray, you should sort your XResultSet with XResultSetSort() before creating the StringArray. This allows you to sort by multiple fields.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Sorting a string array
Reply #2 - Dec 7th, 2018 at 3:13pm
Print Post Print Post  
Thanks, Ray

Its working great (a partial list is below).  I have two followup questions:

1) Is there a way to change the date format to something more user friendly?  Like "10/02/18"?
2) Is there a way to add a comma to the number so 2500 becomes 2,500?



2725AE  Date: 2016/09/22 -- Quantity: 22500
2725AE  Date: 2016/09/27 -- Quantity: 22500
2725AE  Date: 2016/10/04 -- Quantity: 45000
2725AE  Date: 2016/10/21 -- Quantity: 22500
2725AE  Date: 2016/10/26 -- Quantity: 2500
2725AE1  Date: 2015/05/05 -- Quantity: 17100
2725AE1  Date: 2015/05/07 -- Quantity: 15000
2725AE1  Date: 2015/05/11 -- Quantity: 15300
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2483
Joined: Aug 20th, 2003
Re: Sorting a string array
Reply #3 - Dec 7th, 2018 at 3:23pm
Print Post Print Post  
For both 1 and 2, if you have an element on your form that is set to format the data how you want the data to be displayed, you can use @AsFormattedByLE()

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Sorting a string array
Reply #4 - Dec 7th, 2018 at 6:34pm
Print Post Print Post  
Thanks, Ray!

That a big help!
  
Back to top
 
IP Logged