Find Values in Tags and Total Them

This clip takes the following:
+ =
This person has values in tag sets named as above. I just read the first two values and then spit out the calculated value under the third tag. I don’t really error trap, other than to spit you out if these three tags don’t appear in succession.

;*** Effort by Don Passenger
;*** don a-t htmlfixit d-o-t com
;*** discuss things live in chat at http://htmlfixit.com
;*******************************************************
;*** will take this:
;-130.45
;-13.05
;xxxx
;and calculate the sum-net

; always start at the top of the document
^!Jump DOC_START

:LoopSum
;find the total-sum tag
;find next tag start
^!Find "< " TIS ;quit when no more tags ^!IfError Finish ^!ClearVariables ;%TAG% will be empty if cursor is not inside a tag. ;determine if tag and get the name of the tag ;if not "total-sum" cycle to next via NotTag subroutine ^!Set %TAG%="^$GetHtmlTag(TRUE)$" ^!IfTrue ^$IsEmpty(^%TAG%)$ NotTag ^!Set %TAGNAME%="^$GetHtmlTagName("^%TAG%";UPPERCASE)$" ^!If "TOTAL-SUM" = "^%TAGNAME%" TOTAL-SUM ELSE NotTag :NotTag ^!Jump Select_End ^!Goto LoopSum ;if TOTAL-SUM tag, get the value :TOTAL-SUM ;jump to the end of the TOTAL-SUM tag ^!Jump Select_End ;figure out where cursor is ^!Set %row%="^$GetRow$" ^!Set %column%="^$GetCol$" ;find the start of the /total-sum tag ;note I assume it is the next tag ;no error checking ^!Find "<" TIS ;select the number and then load it to a variable ^!SelectTo ^%row%:^%column% ^!Set %SUM%=^$GetSelection$ ;NEXT GET THE SUM-VAT VALUE ;advance one line ^!Jump +1 ;find the total-sum-vat tag ^!Find "<" TIS ;quit when no more tags ^!IfError Problem ^!Set %TAG2%="^$GetHtmlTag(TRUE)$" ^!IfTrue ^$IsEmpty(^%TAG2%)$ Problem ^!Set %TAGNAME2%="^$GetHtmlTagName("^%TAG2%";UPPERCASE)$" ^!If "TOTAL-SUM-VAT" = "^%TAGNAME2%" TOTAL-SUM-VAT ELSE Problem ;if TOTAL-SUM tag, get the value :TOTAL-SUM-VAT ;jump to the end of the TOTAL-SUM-VAT tag ^!Jump Select_End ;figure out where cursor is ^!Set %row%="^$GetRow$" ^!Set %column%="^$GetCol$" ;find the start of the /total-sum-vat tag ;note I assume it is the next tag ;no error checking ^!Find "<" TIS ;select the number and then load it to a variable ^!SelectTo ^%row%:^%column% ^!Set %SUMVAT%=^$GetSelection$ ;NEXT DO MATH AND REPLACE THE SUM-NET VALUE ;advance one line ^!Jump +1 ;find the total-sum-vat tag ^!Find "<" TIS ;quit when no more tags ^!IfError Problem ^!Set %TAG3%="^$GetHtmlTag(TRUE)$" ^!IfTrue ^$IsEmpty(^%TAG3%)$ Problem ^!Set %TAGNAME3%="^$GetHtmlTagName("^%TAG3%";UPPERCASE)$" ^!If "TOTAL-SUM-NET" = "^%TAGNAME3%" TOTAL-SUM-NET ELSE Problem ;if TOTAL-NET tag, get the value :TOTAL-SUM-NET ;jump to the end of the TOTAL-SUM-NET tag ^!Jump Select_End ;figure out where cursor is ^!Set %row%="^$GetRow$" ^!Set %column%="^$GetCol$" ;find the start of the /total-sum-net tag ;note I assume it is the next tag ;no error checking ^!Find "<" TIS ;select the number and then load it to a variable ^!SelectTo ^%row%:^%column% ;now do the math ^!SetClipboard ^$Calc(^%SUM%+^%SUMVAT%)$ ^!Paste ;GET NEXT SET OF TAGS ;advance one line ^!Jump +1 ^!Goto LoopSum :Problem ^!Info [C]we have a tag mismatch -- something is wrong with formatting ^!Goto End :Finish ^!SetScreenUpdate On ^!ClearVariables ;line 117 if you have all lines unrapped (including blank lines)

Leave a Reply

Recent Posts

Archives

Topics