Macro To Format Txt List into saved Javascipt Snippet file

Macro To Format Txt List into saved Javascipt Snippet file

1
NewbieNewbie
1

    Apr 03, 2006#1

    For the life of me I can't figure out how to tweak the macro commands to create the output I need. My source text list looks like so:

    Code: Select all

    genpage.php?category=Beer+Steins&subcategory_1=Steins&start=50
    k-285
    Bayern Beer Stein
    103
    70
    45.00
    40.50
    
    genpage.php?category=Beer+Mugs&subcategory_1=Steins&start=150
    z123456
    German Beer Mugs
    99
    70
    85.00
    80.50
    and I'm trying to get my UltraEdit macro to loop through the above source list and create an "output.txt" file that would look like this:

    Code: Select all

    document.write('<table width="100%" border="0" cellspacing="0" cellpadding="1">');
    document.write('<tr valign=top><td width="1%">');
    document.write('<a href=genpage.php?category=Beer+Steins&subcategory_1=Steins&start=50><img src=discounts/k-285sm.gif alt=Bayern Beer Stein width=103 height=70 hspace=0 vspace=0 border=1></a>');
    document.write('<br><img src=images/space.gif width=100 height=1 border=0 alt=Bayern Beer Stein></td></tr><tr><td bgcolor=#ffffff>');
    document.write('<font face=Arial,Helvetica,Geneva,Swiss,SunSans-Regular><a href=genpage.php?category=Beer+Steins&subcategory_1=Steins&start=50><b>Bayern Beer Stein</b></a></font><br>');
    document.write('<font face=Arial,Helvetica,Geneva,Swiss,SunSans-Regular size=-1>');
    document.write('<b>WAS</b> $<strike>45.00</strike> &nbsp;&nbsp; <b>NOW <font color=#FF0000>$40.50</font></b>!');
    document.write('</font>');
    document.write('</td></tr></table><p>');
    
    document.write('<table width="100%" border="0" cellspacing="0" cellpadding="1">');
    document.write('<tr valign=top><td width="1%">');
    document.write('<a href=genpage.php?category=Beer+Mugs&subcategory_1=Steins&start=150><img src=discounts/z123456sm.gif alt=German Beer Mugs width=99 height=70 hspace=0 vspace=0 border=1></a>');
    document.write('<br><img src=images/space.gif width=100 height=1 border=0 alt=German Beer Mugs></td></tr><tr><td bgcolor=#ffffff>');
    document.write('<font face=Arial,Helvetica,Geneva,Swiss,SunSans-Regular><a href=genpage.php?category=Beer+Mugs&subcategory_1=Steins&start=150><b>German Beer Mugs</b></a></font><br>');
    document.write('<font face=Arial,Helvetica,Geneva,Swiss,SunSans-Regular size=-1>');
    document.write('<b>WAS</b> $<strike>85.00</strike> &nbsp;&nbsp; <b>NOW <font color=#FF0000>$80.50</font></b>!');
    document.write('</font>');
    document.write('</td></tr></table><p>');
    My macro is not looping nor saving .. nor do I think my approach was correct. How would you revise the following macro I constructed listed below:

    InsertMode
    ColumnModeOff
    HexOff
    UnixReOff
    Loop
    IfEof
    ExitMacro
    Else
    ClearClipboard
    Clipboard 0
    SelectLine
    StartSelect
    Copy
    EndSelect
    Key END
    Key HOME
    Clipboard 1
    SelectLine
    StartSelect
    Copy
    EndSelect
    Key END
    Key HOME
    Clipboard 2
    SelectLine
    StartSelect
    Copy
    EndSelect
    Key END
    Key HOME
    Clipboard 3
    SelectLine
    StartSelect
    Copy
    EndSelect
    Key END
    Key HOME
    Clipboard 4
    SelectLine
    StartSelect
    Copy
    EndSelect
    Key END
    Key HOME
    Clipboard 5
    SelectLine
    StartSelect
    Copy
    EndSelect
    Key END
    Key HOME
    Clipboard 6
    SelectLine
    StartSelect
    Copy
    EndSelect
    Key END
    Key HOME
    Clipboard 7
    StartSelect
    Copy
    EndSelect
    NewFile
    "document.write('<table width="100%" border="0" cellspacing="0" cellpadding="1">');
    document.write('<tr valign=top><td width="1%">');
    document.write('<a href="
    Clipboard 0
    Paste
    "><img src=discounts/"
    Clipboard 1
    Paste
    "sm.gif alt="
    Clipboard 2
    Paste
    " width="
    Clipboard 3
    Paste
    " height="
    Clipboard 4
    Paste
    " hspace=0 vspace=0 border=1></a>');
    document.write('<br><img src=images/space.gif width=100 height=1 border=0 alt="
    Clipboard 2
    Paste
    "></td></tr><tr><td bgcolor=#ffffff>');
    document.write('<font face=Arial,Helvetica,Geneva,Swiss,SunSans-Regular><a href="
    Clipboard 0
    Paste
    "><b>"
    Clipboard 2
    Paste
    "</b></a></font><br>');
    document.write('<font face=
    Arial,Helvetica,Geneva,Swiss,SunSans-Regular size=-1>');
    document.write('<b>WAS</b>
    $<strike>"
    Clipboard 5
    Paste
    "</strike> &nbsp;&nbsp; <b>NOW <font color=#FF0000>$"
    Clipboard 6
    Paste
    "</font></b>!');
    document.write('</font>');
    document.write('</td></tr></table><p>');"
    EndSelect
    Key END
    "
    "
    Key DOWN ARROW
    ClearClipboard
    EndLoop
    SaveAs "output.txt"
    CloseFile



    Sincerely,

    Theodore

    6,686585
    Grand MasterGrand Master
    6,686585

      Apr 05, 2006#2

      The loop was not working because you have forgotten the EndIf command for the Else branch of the IfEof command. Command ExitMacro is also not good because the lines after EndLoop will not be executed. Command SelectLine also selects the CRLF of the line which is not good for the output. NewFile must be executed before the loop or you will create always a new file for every block and last I missed the window switching commands NextWindow and PreviousWindow.

      Here is your corrected macro:

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Bottom
      IfColNum 1
      Else
      "
      "
      EndIf
      Top
      TrimTrailingSpaces 
      NewFile
      NextWindow
      Loop 
      IfEof
      ExitLoop
      EndIf
      Clipboard 0
      StartSelect
      Key END
      Copy 
      EndSelect
      Key DOWN ARROW
      Key HOME
      Clipboard 1
      StartSelect
      Key END
      Copy 
      EndSelect
      Key DOWN ARROW
      Key HOME
      Clipboard 2
      StartSelect
      Key END
      Copy 
      EndSelect
      Key DOWN ARROW
      Key HOME
      Clipboard 3
      StartSelect
      Key END
      Copy 
      EndSelect
      Key DOWN ARROW
      Key HOME
      Clipboard 4
      StartSelect
      Key END
      Copy 
      EndSelect
      Key DOWN ARROW
      Key HOME
      Clipboard 5
      StartSelect
      Key END
      Copy 
      EndSelect
      Key DOWN ARROW
      Key HOME
      Clipboard 6
      StartSelect
      Key END
      Copy 
      EndSelect
      Key DOWN ARROW
      Key HOME
      Clipboard 7
      StartSelect
      Key END
      Copy 
      EndSelect
      Key DOWN ARROW
      Key HOME
      PreviousWindow
      "document.write('<table width="100%" border="0" cellspacing="0" cellpadding="1">');
      document.write('<tr valign=top><td width="1%">');
      document.write('<a href="
      Clipboard 0
      Paste 
      "><img src=discounts/"
      Clipboard 1
      Paste 
      "sm.gif alt="
      Clipboard 2
      Paste 
      " width="
      Clipboard 3
      Paste 
      " height="
      Clipboard 4
      Paste 
      " hspace=0 vspace=0 border=1></a>');
      document.write('<br><img src=images/space.gif width=100 height=1 border=0 alt="
      Clipboard 2
      Paste 
      "></td></tr><tr><td bgcolor=#ffffff>');
      document.write('<font face=Arial,Helvetica,Geneva,Swiss,SunSans-Regular><a href="
      Clipboard 0
      Paste 
      "><b>"
      Clipboard 2
      Paste 
      "</b></a></font><br>');
      document.write('<font face=Arial,Helvetica,Geneva,Swiss,SunSans-Regular size=-1>');
      document.write('<b>WAS</b> $<strike>"
      Clipboard 5
      Paste 
      "</strike> &nbsp;&nbsp; <b>NOW <font color=#FF0000>$"
      Clipboard 6
      Paste 
      "</font></b>!');
      document.write('</font>');
      document.write('</td></tr></table><p>');
      
      "
      NextWindow
      EndLoop
      PreviousWindow
      SaveAs "output.txt"
      CloseFile
      Clipboard 0
      ClearClipboard
      But your conversion can also be done with following macro, which is much faster because it uses a single regular expression replace for the conversion. UE supports up to 9 replacement expressions and up to 1000 characters for the search and the replace string. In your case 7 replacement expression are needed (^1 ... ^7) and the replace string has 745 characters. So no problem to do the conversion with a search and replace.

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      SelectAll
      Clipboard 9
      Copy 
      EndSelect
      Top
      NewFile
      Paste 
      ClearClipboard
      Clipboard 0
      IfColNum 1
      Else
      "
      "
      EndIf
      Top
      TrimTrailingSpaces
      Find RegExp "%^([~^p]+^)^p^([~^p]+^)^p^([~^p]+^)^p^([~^p]+^)^p^([~^p]+^)^p^([~^p]+^)^p^([~^p]+^)^p"
      Replace All "document.write('<table width="100%" border="0" cellspacing="0" cellpadding="1">');^pdocument.write('<tr valign=top><td width="1%">');^pdocument.write('<a href=^1><img src=discounts/^2sm.gif alt=^3 width=^4 height=^5 hspace=0 vspace=0 border=1></a>');^pdocument.write('<br><img src=images/space.gif width=100 height=1 border=0 alt=^3></td></tr><tr><td bgcolor=#ffffff>');^pdocument.write('<font face=Arial,Helvetica,Geneva,Swiss,SunSans-Regular><a href=^1><b>^3</b></a></font><br>');^pdocument.write('<font face=Arial,Helvetica,Geneva,Swiss,SunSans-Regular size=-1>');^pdocument.write('<b>WAS</b> $<strike>^6</strike> &nbsp;&nbsp; <b>NOW <font color=#FF0000>$^7</font></b>!');^pdocument.write('</font>');^pdocument.write('</td></tr></table><p>');^p"
      SaveAs "output.txt"
      CloseFile
      For this macro make sure that macro property Continue if a Find with Replace not found is NOT checked to avoid creating the file output.txt if the regular expression search string is not found.
      Best regards from an UC/UE/UES for Windows user from Austria