AutoHotkey Community

It is currently May 27th, 2012, 6:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Creating HTML with AHK
PostPosted: March 3rd, 2011, 8:58 pm 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
okay... I tried looking for this in the forum, but didn't stumble on it. I'm sure it's somewhere, but kinda hard to search for stuff when you're constantly being interrupted at work. Anyways.....

Okay, I'm trying to have my AHK reprocess a text file that isn't delimited properly (uses spaces to produce columns). I'm doing fine with that, but when I'm trying to reassemble the date in to an HTML table, I keep getting this error:
Quote:
Error
The following variable name contains an illegal character:
"" align="righ">"
the program will exit.

now here's the code I'm working with:
Code:
Loop, read, Warrant List (no Headers).txt, Warrant List (HTML1).htm
{

if StrLen(A_LoopReadLine) > 1 ; to skip blank lines
  {
  IfNotInString, A_LoopReadLine, Total ; to process lines that have 'Total' in them
   {
    StringLeft, Line, A_LoopReadLine, 5
    IfInString, Line, %A_Space% ; check for lines that have spaces in the beginning of them.
      { ;If spaces were found. This will be the data in the table
     WarNbr := SubStr(A_LoopReadLine, 09, 12)
     DocNbr := SubStr(A_LoopReadLine, 24, 10)
     WDoNbr := SubStr(A_LoopReadLine, 38, 10)
     FinCos := SubStr(A_LoopReadLine, 55, 11)
     Bonded := SubStr(A_LoopReadLine, 68, 14)
     AppendStrg = `n  <tr>`n   <td width="20%" align="right">%WarNbr%</td>`n`n   <td width="20%" align="right">%DocNbr%</td>`n`n   <td width="20%" align="right">%WDoNbr%</td>`n`n   <td width="20%" align="right">%FinCos%</td>`n`n   <td width="20%" align="right">%Bonded%</td>`n  </tr>
      FileAppend,%AppendStrg%
    }
     else
    { ; If no spaces were found this will be the start of a new table and the 'title' row.
         AppendStrg = <Table width="100%">`n <TR><TD ColSpan=5>%A_LoopReadLine%</td></tr>
         FileAppend,%AppendStrg%
    }
    }
     else
    { ; this is the section where 'Total' was found.  this completes the table by placing the totals in the appropiate cells and closes the table
     FinToT := SubStr(A_LoopReadLine, 54, 12)
     BonToT := SubStr(A_LoopReadLine, 67, 15)
     AppendStrg = `n  <tr>`n   <td width="20%" align="right"></td>`n`n   <td width="20%" align="right"></td>`n`n   <td width="20%" align="right">Total:</td>`n`n   <td width="20%" align="right">%FinToT%</td>`n`n   <td width="20%" align="right">%BonToT%</td>`n  </tr>
     FileAppend,%AppendStrg%
     AppendStrg = <Table width="100%">`n <TR><td width="100%" colspan="5">%A_LoopReadLine%</td></tr>
     FileAppend,%AppendStrg%
    }
   }
  }
sample data would be this:
Code:
Lastname, MARY                  1409 W Street     ThatVILLE, ST 12345
        008211   -01    020012089     020012089           $328.90          $0.00
        008211F  -01   020012089F     020012089F          $514.80          $0.00

                                           TOTAL          $843.70          $0.00
Surname, MIGUEL ANGEL          4969  Downyonder DR     AnyTOWN, ST 65431
        200202149-01    020001725     020001725           $279.50   ** No Bond **

                                           TOTAL          $279.50          $0.00
Obviously, AHK is choking on the HTML tagging.
How do I get the HTML generation to work?

THANKS IN ADVANCE!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 3rd, 2011, 9:06 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
the problem is probably here with the % signs you need to escape them with a ` width="20`%"

see
http://www.autohotkey.com/docs/Scripts.htm#esc
http://www.autohotkey.com/docs/commands/_EscapeChar.htm

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 3rd, 2011, 9:51 pm 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
hugov wrote:
the problem is probably here with the % signs you need to escape them with a ` width="20`%"

HOGOV,
Thanks for the reply... and solution. Sometimes the littles things ESC you... hahaha.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 3rd, 2011, 10:55 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
Here's an example of how to streamline this task for your perusal:

Code:
var=
(
Lastname, MARY                  1409 W Street     ThatVILLE, ST 12345
        008211   -01    020012089     020012089           $328.90          $0.00
        008211F  -01   020012089F     020012089F          $514.80          $0.00

                                           TOTAL          $843.70          $0.00
Surname, MIGUEL ANGEL          4969  Downyonder DR     AnyTOWN, ST 65431
        200202149-01    020001725     020001725           $279.50   ** No Bond **

                                           TOTAL          $279.50          $0.00
)
var :=   RegExReplace(var,"\h{2,}","`t")   ; replaces all sections of two or more spaces with a single tab
var :=   RegExReplace(var,"\h(?=-\d+)")   ; removes any spaces before the number preceded with a dash
; MsgBox %var%
Loop, parse, var, `n, `r
{
   if   !StrLen(A_LoopField)   ; skips blank lines
      continue
   if   !RegExMatch(A_LoopField,"^\h")   ; if line does not start with tab
      FileAppend, %   "<table width=""100%"">`n`t<tr><td colspan=5>" A_LoopField "</td></tr>"
   else if   InStr(A_LoopField,"TOTAL")   ; if line contains TOTAL
   {
      tmp :=   RegExReplace(A_LoopField,"^\s+")   ; removes tab from beginning of line
      StringSplit, total, tmp, %A_Tab%      ; splits line into vars delimited by tab
      FileAppend, %   "`n`t<tr>`n`t<td width=""20%"" align=""right""></td>"
       . "`n`n`t<td width=""20%"" align=""right""></td>"
       . "`n`n`t<td width=""20%"" align=""right"">Total:</td>"
       . "`n`n`t<td width=""20%"" align=""right"">" total2 "</td>"
       . "`n`n`t<td width=""20%"" align=""right"">" total3 "</td>`n`t</tr>"
   } else {
      tmpvar :=   RegExReplace(A_LoopField,"^\s+")   ; removes tab from beginning of line
      StringSplit, info, tmpvar, %A_Tab%         ; splits line into vars delimited by tab
      FileAppend, %   "`n`t<tr>`n`t<td width=""20%"" align=""right"">" info1 "</td>"
       . "`n`n`t<td width=""20%"" align=""right"">" info2 "</td>"
       . "`n`n`t<td width=""20%"" align=""right"">" info3 "</td>"
       . "`n`n`t<td width=""20%"" align=""right"">" info4 "</td>"
       . "`n`n`t<td width=""20%"" align=""right"">" info5 "</td>`n`t</tr>"
   }
}

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 3rd, 2011, 11:00 pm 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
sinkfaze wrote:
Here's an example of how to streamline this task for your perusal:

Thanks Sinkfaze. I was wondering how I was gonna figure that one out. fumbled throw what I know and settled for fixed with columns. I'll implement your code though :D


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], hd0202 and 56 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group