Solved

Create and sort multi-dimentional array

Posted on 2014-02-07
9
266 Views
Last Modified: 2014-02-12
I'm writing an classic ASP page.  I have a 1 dimentional array with the data like this: (FileName-Date-Content)


This is a test - 03 Apr 2000 - Test 1
Another test - 12 Dec 2003 - Test 2
Test again - 22 May 2012 - Test 3
Test number 4 - 09 Jun 2008 - Test 4

How can I display the latest date first so the data looks like this:

Test again - 22 May 2012 - Test 3
Test number 4 - 09 Jun 2008 - Test 4
Another test - 12 Dec 2003 - Test 2
This is a test - 03 Apr 2000 - Test 1

Thanks!
0
Comment
Question by:ttta83
  • 4
  • 4
9 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 39842359
Is the data hard coded out does it come from a database, where you could sort by using the order by clause?
0
 

Author Comment

by:ttta83
ID: 39842424
Hi Big Monty,

I used MSXML2.ServerXMLHTTP to get the data from other web page so I cannot sort by date.

Thanks
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39842430
If you need to sort the array, it is much faster to do this client side than using vbs.  

You can either write the data to a js/jquery array and sort using the timestamp.   If you need to get this out to a table, I like  using data tables.  http://datatables.net/release-datatables/examples/basic_init/table_sorting.html  It can be a bit much for just one small item, but if you are doing this a lot, it makes sense.

Otherwise, it is explained in 4guys how to sort arrays in asp/vbs http://www.4guysfromrolla.com/webtech/011001-1.shtml but there are better methods.  Big Monty is on the easiest track by using sql.    I would use vbs arrays sorting as a last resort.

If you still want to go into that in detail, let us know.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39842449
How much data are you dealing with?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ttta83
ID: 39842472
Hi Padas,

About 800 rows.  would you please help!
0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39842621
Do you have to bring in all 800 rows of data at once?  Or is it easy to  page through?   If you do have to bring them all in at once, I would really go the js/jquery route and sort in the browser.  It will be much faster.

Lets look at datatables using a javascript array as an example http://datatables.net/release-datatables/examples/data_sources/js_array.html

We just need to get the data in this form in no  particular order.
"aaData": [
            /* Reduced data set */
            [ "Trident", "Internet Explorer 4.0", "Win 95+", 4, "X" ],
            [ "Trident", "Internet Explorer 5.0", "Win 95+", 5, "C" ],
            [ "Trident", "Internet Explorer 5.5", "Win 95+", 5.5, "A" ],
            [ "Trident", "Internet Explorer 6.0", "Win 98+", 6, "A" ],
            [ "Trident", "Internet Explorer 7.0", "Win XP SP2+", 7, "A" ],
            [ "Gecko", "Firefox 1.5", "Win 98+ / OSX.2+", 1.8, "A" ],
            [ "Gecko", "Firefox 2", "Win 98+ / OSX.2+", 1.8, "A" ],
            [ "Gecko", "Firefox 3", "Win 2k+ / OSX.3+", 1.9, "A" ],
            [ "Webkit", "Safari 1.2", "OSX.3", 125.5, "A" ],
            [ "Webkit", "Safari 1.3", "OSX.3", 312.8, "A" ],
            [ "Webkit", "Safari 2.0", "OSX.4+", 419.3, "A" ],
            [ "Webkit", "Safari 3.0", "OSX.4+", 522.1, "A" ]
        ],

Open in new window


If you are getting this data as in array is this part
This is a test - 03 Apr 2000 - Test 1
how it comes in or is it array(0,0), array(0,1), array(0,2)?

If it is not an array, we can split the row of data.
str="This is a test - 03 Apr 2000 - Test 1"
array=split(str,"-")
text1=array(0)
date=array(1)
text2=array(2)

Once we have that we can simply create the js we need.
response.write "<script>"
' response.write each line of the sample to match your needs
response.write "["
for each line in httppost
   array=split(str,"-")
   response.write "'['"&"'"&array(0)&"',"& array(0) &"',"&array(0)&"'],"
       ' do a test for end of the line so you don't print out the very last comma
next
response.write "],"
' response.write the rest of the js needed as sample

Open in new window

800 rows is a lot, but this will make it go faster.

Get it to work with static data first.  

With dates, https://editor.datatables.net/release/DataTables/extras/Editor/examples/dates.html you just need to give it the dateformat as sampled.
0
 

Author Comment

by:ttta83
ID: 39842895
Padas,

would you please run this code?  I have the data displayed on the screen but I want to sort by the year... It takes about 90 seconds for the page to load 'cause I have to go through each individual file to get the distinct first 3 characters of each file.   WHat should I do to make it run faster and with the list sorted by the dates.  

Without using jQuery, can we make it sort by date?

Please let me know if you have any questions.  

Again, thank you very much for your help on this.

<%
Response.Buffer = False
url="http://www.cpms.osd.mil/WageData/wagedata"
Set xmlHttp =  Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
xmlHttp.Open "GET", url, False
    xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
    xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
    xmlHttp.Send
    getHTML = xmlHttp.responseText
    strArr = split(xmlHttp.responseText,"<br>")
	set xmlHttp = Nothing
    
    for i=0 to ubound(strArr)
		lData = trim(ucase(strArr(i)))
		NAFDATLoc = InStrRev(lData,"NAF.DAT",-1)
		If (NAFDATLoc > 0) then
			FileName = mid(trim(strArr(i)),NAFDATLoc-9,16)
			If (IsNumeric(mid(FileName,1,4))) then
				'Only display year 2000 and above and don't display *.dat.old.dat (there's one file with ext .dat.old.dat)
				If (cInt(mid(FileName,1,4)) >= 2000) and (mid(trim(strArr(i)),NAFDATLoc+7,1) <> ".") then
					FirstSpaceLoc = Instr(lData," ")
					FirstMLoc = Instr(lData,"M")
					strDate = mid(lData,1,FirstSpaceLoc)
                                         
					if mid(strDate,2,1) = "/" then
									strDate = "0" & strDate
					end if
					if mid(strDate,5,1) = "/" then
									strDate = left(strDate,3) & "0" & mid(strDate,4,9)
					end if
           
					Select Case mid(strDate,1,2)
						Case "01"
							strSpellMonth = "Jan"
						Case "02"
							strSpellMonth = "Feb"
						Case "03"
							strSpellMonth = "Mar"
						Case "04"
							strSpellMonth = "Apr"
						Case "05"
							strSpellMonth = "May"
						Case "06"
							strSpellMonth = "Jun"
						Case "07"
							strSpellMonth = "Jul"
						Case "08"
							strSpellMonth = "Aug"
						Case "09"
							strSpellMonth = "Sep"
						Case "10"
							strSpellMonth = "Oct"
						Case "11"
							strSpellMonth = "Nov"
						Case "12"
							strSpellMonth = "Dec"
					End Select

					DateDisplay = mid(strDate,4,2) & " " & strSpellMonth & " " & mid(strDate,7,4)
 
					url="http://www.cpms.osd.mil/WageData/wagedata/" & FileName
					Set xmlHttpData =  Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
					
					xmlHttpData.Open "GET", url, False
					xmlHttpData.setRequestHeader "User-Agent", "asp httprequest"
					xmlHttpData.setRequestHeader "content-type", "application/x-www-form-urlencoded"
					xmlHttpData.Send
					getHTMLData = xmlHttpData.responseText
					strArrData = split(xmlHttpData.responseText,vbCrLf)  'vbCrLf
					set xmlHttpData = Nothing                                         
 
					strWageAreas = "("
					strPrevWageArea = ""
					'For lngIdx = 1 To lngFileArraySize
					for j=0 to ubound(strArrData)
						'Response.Write(strArrData(j))
						intPos = InStr(strArrData(j),"|")
						'Response.Write(intPos)
						if intPos > 0 then
							strCurrWageArea = mid(strArrData(j), 1, intPos - 1)
							If strCurrWageArea <> strPrevWageArea Then
								If strWageAreas = "(" Then
									strWageAreas = strWageAreas & strCurrWageArea
							   Else
									strWageAreas = strWageAreas & ", " & strCurrWageArea
								End If
								strPrevWageArea = strCurrWageArea
							End If
						'Else
						'    strWageAreas = ""
						End if
					Next
 
                    If strWageAreas = "(" Then
                        strWageAreas = ""
                    Else
                        strWageAreas = strWageAreas & ")"
                    End If
 
                    GetWageAreas = strWageAreas
 
					FileName = mid(trim(strArr(i)),NAFDATLoc-9,16)
					Response.Write(FileName & " --  " & DateDisplay & " --- " & GetWageAreas & "<br>")

				End if
            End if
		end if
		GetWageAreas = ""
		strWageAreas = ""
 
	next
%>

Open in new window

0
 

Author Comment

by:ttta83
ID: 39853865
I use vbscript array and it works ok now.

Thanks for the help.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39853897
Glad you have it working.  I did not get to see your other response until now.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
can I post data from an asp page to php page? 4 46
Auto Submit on dropdown box 14 51
Script is being strange 8 63
How to show result of a NULL value at random? 32 39
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now