Genii Weblog

Secret tip for Midas users (or wannabes)

Fri 9 Jan 2004, 04:05 PM



by Ben Langhinrichs
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:
enter symbol

MARKETS: 04:05PM ET, 01/09
DJIA
-133.55
10458.89
-1.26%
NAS
-13.33
2086.92
-0.63%
S&P
-10.06
1121.86
-0.89%

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:

Salesperson
Quota ($)
Abelson, Bernard
100000
Anderson, Art
225000
Bratsworth, George
55000
Cadwell, Lori
175000
Carter, Billy
15000
Dirk, Sidwell
45000

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")
While rtchunk.Exists
   total_quota = total_quota + Clng(rtchunk.Text)
   rtchunk.GetNextTarget
Wend
 
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.

What has been said:

No documents found