Filling a table component with an exported file


Recommended Posts

I'm supporting an application that writes system messages to a file using an export.  The messages are also added to a table component that reflects a that contains all the entries.  When the application is started the export file is read and stuffed into the table.

The problem is that the startup stuff is entered backwards... time goes backwards for all past entries.  New system messages ("Restart' etc) appear in proper chronological order, with the most recent at the top.

Here's some code:


~ Sequence.loadMessages, Priority: 5 - Acquisition

// pass name of export set used to write, and the name of the destination v channel (with v.).  For example:

// loadMessages("message_export","v.SYSTEM_MESSAGES")
function loadMessages(string exportName, string destination)
   private handle = evaluate("file.Open(export." + exportName + ".strFileName,1,0,0,1)")
   file.Read(handle) // read header   
   private theTime = file.ReadDelim(handle, 0, ",", chr(10), -1)
   file.Read(handle) // read header
   private string messages = file.ReadDelim(handle,1,",",chr(10),-1,1)
   messages.time = (theTime - 365*70 - 19) * 86400
   execute(destination + ' = "START OF MESSAGES "')   
   execute(destination + ".AddValue(messages)")
   ? strLastError

function add_service_Message(string message)
   v.service_messages.addvalue(formatdateTime("%c", systime()) + ": " + message)


Is there a way to invert the row order of the array 'messages'?  Is there a way to read the file from the bottom?  Not seeing an easy way out here.




Link to comment
Share on other sites

There are a couple ways.  But if you are using ReadDelim() the first way (inserting in reverse) won't work.  With ReadDelim, what you want to do is assign the timestamp to the actual content variable, then use sortTime().  You already did the first part, so just need to do the second part: messages = sortTime(messages)


Link to comment
Share on other sites

OK, I tried putting the sortTime() right after the read... complains of 'no time parm' or something.

Then I put it right after the 'messages.time = '... it did not complain, but the past values are still listed in ascending order, top-down.  The picture looks exactly as above.

I guess I need a reverse sortTime().


Link to comment
Share on other sites

I'm not sure.  You probably have the timestamp wrong.  Just do a test of sorttime() in the command alert:

global string a = {"A","B","C"}
a = insertTime(a, systime(), 1) // this makes it so time gets bigger as we move through the array

Now, if you do:

? a

you get {"A", "B", "C} and if you then displayed that in a table, "A" would be the top row.

But if you do:

? sorttime(a)

you get {"C", "B", "A"} which is in order from biggest time to smallest.  If you then displayed that in a table, "C" would be the top row.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.