I haven't blogged much about our Midas Rich Text LSX recently, and I thought I would describe an undocumented/semi-documented secret for all of you Midas users out there, or those just interested in Midas. Perhaps this will even motivate me to document it properly. Perhaps.
Since this tip relates to chunks, you might want to read Midas 101 - Chunks first if you are not comfortable with the concept.
Imagine the following nested tables (which came from today's CNN site) and that these are surrounded by lots more rich text stuff (as they are in that site):
|STOCK/FUND QUOTES: |
|MARKETS: 04:05PM ET, 01/09 |
Now, imagine that you want to get a handle on the blue table with the MARKETS: hotspot. Midas is pretty flexible, so you could use FindTextChunk and find the appropriate text, or cycle through the hotspots until you found the right one. After that, you could cycle through the various nested tables until you found one whose LastRecord property was greater than the LastRecord property of the hotspot or text chunk and whose FirstRecord property was less than the FirstRecord property of the hotspot or text chunk. Possible, but kind of far away from the dream I espouse for Midas. So, a few versions back, I added a better way.
In my imagination, a developer or user would look at this problem and say "I want that table which has the word MARKETS in the upper left hand corner". The question is, how to handle that in Midas-think. My solution was to add a syntax close to that used in the FindTextChunk property. Now, you can say:
Set rtchunk = rtitem.DefineChunk("Table 'MARKETS:' 1")
and the chunk will try to match the first table in which the string MARKETS: is the first string found. Now, that may be a bit too precise, so you could also use
Set rtchunk = rtitem.DefineChunk("Table Starts 'MARKETS' 1")
where the first string in the table would need to start with the string, or
Set rtchunk = rtitem.DefineChunk("Table Substring 'MARKETS' 1")
where the first string in the table would need to contain as a substring the specified string, or
Set rtchunk = rtitem.DefineChunk("Table Ends 'TS:' 1")
where the first string in the table would need to end the string. By the way, the search is not case sensitive, as that seemed a bit too constrained.
Now, like all chunks, you can cycle through each hit, so if you had a table such as the following:
you could use the following code to get the total of all the quotas for all the sales people whose last name started with C:
total_quota = 0
Set rtchunk = rtitem.DefineChunk("Table 1; Row Starts 'C' 1; Column 2")
total_quota = total_quota + Clng(rtchunk.Text)
There are lots more ways to use this, some less obvious than others. See if you can guess what the logic of these other chunk definitions are and why they might be useful:
Set rtchunk = rtitem.DefineChunk("Text Substring '(216)' 1")
Set rtchunk = rtitem.DefineChunk("Hyperlink Substring '/showcase.nsf/' 1")
Set rtchunk = rtitem.DefineChunk("Hyperlink Substring '/Aladdin/' 1")
Set rtchunk = rtitem.DefineChunk("ActionHotspot Ends ' shutdown' 1")
Set rtchunk = rtitem.DefineChunk("Paragraph 'Table of Contents' 1")
Now, if you are a regular Midas user, you have learned something new. If not, I hope you have gotten at least a taste of how simple and powerful Midas programming can be.
Copyright © 2004 Genii Software Ltd.