Announcement

Collapse
No announcement yet.

Write once, run once code.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Write once, run once code.

    My young brother mentioned a problem he has trying to get an ebook into a form that he could read on a gadget that he goes on holidays with that was full of "<blockquote>" "</blockquote>" formatting but the problem was the two files were about 300 meg and 400 meg. Noting that he was running 32 bit XP, I was not sure he had enough free memory to do the task but spat together a quick scruffy that actually did the job if only just. Did the first file OK but shoved a lot out to virtual memory and was very slow for the second file.

    One of the reasons why I am a great fan of PBCC is the capacity to pelt a scruffy together in under 5 minutes, run it once then forget it.

    Code:
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    FUNCTION PBmain as LONG
    
        LOCAL flen as DWORD
    
      ' --------------------------------------
    
        StdOut "Opening file p1.txt"
    
        Open "p1.txt" for Binary as #1
          flen = lof(1)
          Get$ #1, flen, a$
        Close #1
    
        StdOut "stripping <blockquote>"
        a$ = remove$(a$,"<blockquote>")
    
        StdOut "stripping </blockquote>"
        a$ = remove$(a$,"</blockquote>")
    
        StdOut "writing result to disk"
    
        Open "rslt1.txt" for Output as #1
          Print #1, a$;
        Close #1
    
      ' --------------------------------------
        a$ = ""
      ' --------------------------------------
    
        StdOut "Opening file p2.txt"
    
        Open "p2.txt" for Binary as #1
          flen = lof(1)
          Get$ #1, flen, a$
        Close #1
    
        StdOut "stripping <blockquote>"
        a$ = remove$(a$,"<blockquote>")
    
        StdOut "stripping </blockquote>"
        a$ = remove$(a$,"</blockquote>")
    
        StdOut "writing result to disk"
    
        Open "rslt2.txt" for Output as #1
          Print #1, a$;
        Close #1
    
      ' --------------------------------------
    
        Stdout "Done !, Press any key to exit."
        waitkey$
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com

  • #2
    Agree - PBCC is a great tool for those little gadgets we sometimes need quickly. Have done many of those over the years. Later one can look at code and realize some parts may come in handy other times too and make those parts more "generic", so to speak. In this case, make a couple of "StringToFile" and "FileToString" functions, stored in a library include file for quick & easy use as a one-liner in other codes.

    And on a rainy day, one could even have fun writing a special RemoveText( BYREF sText AS STRING) Sub routine that removes desired text directly in given string without making a copy of the string (like all string Functions does) in order to save on memory when working with huge strings... and gives far better speed

    Comment


    • #3
      Here is another write once, run once masterpiece. I needed to rename a single word in 973 include files. The reason why PBCC will have a place in my dev tools for a long time to come.

      Code:
      FUNCTION PBmain as LONG
      
          cmd$ = command$
      
          Open cmd$ for Binary as #1
            Get$ #1, lof(1), a$
          Close #1
      
          Replace "extern " with "externdef " in a$
      
          Open cmd$ for Output as #1
            Print #1, a$;
          Close #1
      
          StdOut cmd$
      
      End FUNCTION
      Drive it with a batch file.

      Code:
      @echo off
      
      for %%x in (*.inc) do ex2exdef %%x
      hutch at movsd dot com
      The MASM Forum

      www.masm32.com

      Comment


      • #4
        >Drive it with a batch file.

        Or a DIR$ loop. Why create an additional component?

        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Sheer laziness.
          hutch at movsd dot com
          The MASM Forum

          www.masm32.com

          Comment


          • #6
            Yes PBCC is a fantastic tool.

            I normally prototype stuff in excel for some modelling activity, then invariably get annoyed with how slow it is running. I'll convert the functions over to PB and then run it.

            I once had a spreadsheet that was taking nearly 15 minutes to crunch through to the answer, a little bit of PB and the answer was almost instantaneous.

            The trouble with excel is that you need to turn of application updates to get decent speed, but then you run the risk of long run times looking like the machine has hung.

            Long live PBCC.
            --------------
            andrew dot lindsay at westnet dot com dot au

            Comment


            • #7
              The trouble with excel is that you need to turn of application updates to get decent speed, but then you run the risk of long run times looking like the machine has hung
              ==>
              Code:
                 ....
                 MSGBOX "Excel is calculating stuff; don't blame me for the slowness!"
                .....

              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                But seriously ladies and germs..

                The trouble with excel is that you need to turn [off?] application updates to get decent speed..
                If you mean you cannot update your main application's screens whilst "something" is executing in Excel, then using a separate thread of execution for the Excel routines should solve that.

                I have never had issues with Excel's speed; then again, I don't do things like "formulas" and the like.

                Lots of stuff not shown,






                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment

                Working...
                X