Stephen Posted May 6, 2021 Share Posted May 6, 2021 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 v.channel 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) try 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.SeekToBegin(handle) 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)") file.Close(handle) catch() ? strLastError endcatch function add_service_Message(string message) v.service_messages.addvalue(formatdateTime("%c", systime()) + ": " + message) delay(.01) beginexport(service_export) endfunction </> 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. __ Steve . Quote Link to comment Share on other sites More sharing options...
Stephen Posted May 6, 2021 Author Share Posted May 6, 2021 Quote Here's a picture. Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted May 7, 2021 Share Posted May 7, 2021 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) Quote Link to comment Share on other sites More sharing options...
Stephen Posted May 8, 2021 Author Share Posted May 8, 2021 Quote Thanks! Very Perl-like... I'll try it and let you know. Quote Link to comment Share on other sites More sharing options...
Stephen Posted May 8, 2021 Author Share Posted May 8, 2021 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(). Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted May 10, 2021 Share Posted May 10, 2021 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.