Announcement

Collapse
No announcement yet.

Line up data in columns from cgi program

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

  • Line up data in columns from cgi program

    New to CGI coding and would like to know how to line up data in columns using proportional fonts. The code below works fine if I leave the default as Courier New of course.

    Code:
          WriteCGI "<pre>"
          WriteCGI "<font size='1' face='Verdana'>"
          WHILE CNT < 1000
            A$ = F1.ACTNR$
            B$ = F1.ACTNAM$
            D$ = FNDT$(FNCVDATC$(F1.INSDAT$))
            E$ = USING$("\      \    \                            \ \          \",A$,B$,D$)
            WriteCGI  E$
            QF = 6: Q = %F1: GOSUB 60000
            INCR CNT
          WEND
          WriteCGI "</pre>"
    Bob Mechler

  • #2
    I'd say this is a HTML issue as opposed to a cgi issue.

    If you don't want to use a font like courier, I'd suggest outputting your data into a HTML table. I don't think you can use PB formatting for output. The browser will just ignore most if not all of it.

    Comment


    • #3
      Template with REPLACE

      Html template pages can be created and placeholders replaced with text.
      This is a crude example with a link to some additional html tags.
      TemplateMethod.Bas creates TemplateMethod.htm

      In actual use the template would probably be an html page and just
      use the cgi program to replace whatever you want.
      Spaces are first replaced with &nbsp to maintain alignment.

      WriteCGI is replaced here with WriteIt to shell to the created html file.
      This allows testing pages on your local machine without a server.

      Big problem:
      After looking into this more, the columns only align with fixed numbers of characters of the same size.


      Code:
      #COMPILE EXE    'TemplateMethod.bas
      #DIM ALL
      #INCLUDE "win32api.inc"
       
      $Space =  "&nbsp;"
      GLOBAL gHTMLFile AS ASCIIZ * 100
       
      'Alignments using HTML  http://www.w3.org/TR/html401/present/graphics.html
       
      FUNCTION PBMAIN () AS LONG
       
        gHTMLFile = "\TemplateMethod.htm"
        LOCAL s,Verdana, Bookman, Courier, Impact AS STRING, LineNumber AS LONG
       
        Verdana = "<font face='Verdana' size='1'>"
        Bookman = "<font face='Bookman' size='2'>"
        Courier = "<font face='Courier' size='3'>"
        Impact  = "<font face='Impact' size='4'>"
       
        WriteIt  "<html><head><title>Test</title></head><body>"
        WriteIt  Verdana + "This is Verdana in " + gHtmlFile + "<p>"
       
        FOR LineNumber = 1 TO 3
       
           s = "@1   @2  @3   @4"  'template or html page to change
       
          'Insert spaces
          REPLACE " "  WITH $Space   IN s
       
          'insert fonts
          REPLACE "@1" WITH Verdana + "@1" IN s
          REPLACE "@2" WITH Bookman + "@2" IN s
          REPLACE "@3" WITH Courier + "@3" IN s
          REPLACE "@4" WITH Impact  + "@4" IN s
       
          'insert text, mail merge using WITH
          REPLACE "@1" WITH "Verdana on line" + STR$(LineNumber) IN s
          REPLACE "@2" WITH "Bookman on line" + STR$(LineNumber) IN s
          REPLACE "@3" WITH "Courier on line" + STR$(LineNumber) IN s
          REPLACE "@4" WITH "Impact  on line" + STR$(LineNumber) IN s
          WriteIt s
          WriteIt "<BR>"
        NEXT
        WriteIt "<p><a href='http://www.w3.org/TR/html401/present/graphics.html'>http://www.w3.org/TR/html401/present/graphics.html</a></p>"
       
        'write last line of document
        WriteIt "</body></html>"
       
        'close file
        WriteIt "CLOSEME"
        ShellExecute %HWND_DESKTOP, "Open", gHTMLFile, BYVAL 0, BYVAL 0, %SW_SHOWNORMAL
      END FUNCTION
       
      SUB WriteIt(s AS STRING)
        STATIC h AS LONG
       
        IF h = 0 THEN
          h = FREEFILE
          OPEN gHTMLFile FOR OUTPUT AS #h
          IF ERR THEN ? "error occurred"
        END IF
       
        IF s = "CLOSEME" THEN
           CLOSE #h
        ELSE
           PRINT #h, s
        END IF
      END SUB
      Last edited by Mike Doty; 28 Mar 2009, 09:04 AM. Reason: Cosmetic
      How long is an idea? Write it down.

      Comment


      • #4
        Unforunately, it doesn't work with different characters.

        'insert text, mail merge using WITH
        REPLACE "@1" WITH STRING$(5,64 + LineNumber) IN s
        REPLACE "@2" WITH STRING$(4,64 + LineNumber) IN s
        REPLACE "@3" WITH STRING$(7,64 + LineNumber) IN s
        REPLACE "@4" WITH STRING$(6,64 + LineNumber) IN s

        Not sure if it can be done without a table?
        Last edited by Mike Doty; 28 Mar 2009, 09:05 AM.
        How long is an idea? Write it down.

        Comment


        • #5
          >would like to know how to line up data in columns using proportional fonts

          Other than using HTML or some other 'data-alignment' facility (eg tables), the only way this can be done is to print each column item individually. If left-justified, you just start printing at the desired offset from the origin (at left). If right-justified, you have to either use a printing verb which supports right-justification, or you have to measure the string to be printed, subtract that length from the offset of the right edge of the text and print left-justified at that calculated point.

          Depending on output medium (eg, a listbox control offers this), you might have available a "print with tabstops" function. These are used by inserting $TAB characters between the column data items and calling the function passing the modified string. (After setting the tabstop positions).

          Measuring text with monospaced fonts is easy: it's the number of characters in the string. With proportional fonts you need to use a text-measurement function. Which function you use depends on the device to which the string will be printed.

          Proportional fonts are easier to read and look more professional; but they are a bit more work than use than are monospaced fonts. TANSTAAFL.
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Listbox, etc. will not work.
            This is in the programming the internet forum for use with cgi programs.
            I'd like to see a way other than using table.

            Reading this: Designing without tables.
            http://www.sitepoint.com/article/uto...ng-tables-css/

            CSS tableless forms:
            http://www.cssdrive.com/index.php/ex...bleless_forms/

            We need a CSS programmer here.

            How about this:
            http://www.w3.org/Style/Examples/007/evenodd
            Last edited by Mike Doty; 28 Mar 2009, 09:49 AM.
            How long is an idea? Write it down.

            Comment


            • #7
              You certainly don't need to use tables specifically, but you have to use some sort of HTML/CSS based alignment and not PB alignment tools.

              Code:
              local html as string
              html=""
              html=html+"<table>"
                    WHILE CNT < 1000
                      A$ = F1.ACTNR$
                      B$ = F1.ACTNAM$
                      D$ = FNDT$(FNCVDATC$(F1.INSDAT$))
                      html=html+"<tr>"
                      html=html+"<td>"+a$+"</td>"
                      html=html+"<td>"+b$+"</td>"
                      html=html+"<td>"+c$+"</td>"
                      html=html+"<td>"+d$+"</td>"
                      html=html+"</tr>"
                      QF = 6: Q = %F1: GOSUB 60000
                      INCR CNT
                    WEND
              html=html+"</table>"
              writeCGI html

              Comment


              • #8
                I'm sorry, I just have to ask WHY? What is the reason for wanting to do artificially with a proportional font that which a monospaced font will do naturally? Just seems like a lot of unnecessary (and complicated) work...


                I can understand various reasons why Courier New isn't acceptable, but there are other monospace fonts that look fine.

                From: http://en.wikipedia.org/wiki/List_of_typefaces

                Monospaced
                Here you can find a graphical version of this table.

                Andale Mono
                Arial Monospaced
                Vera Sans Mono
                Consolas
                Courier
                CourierHP
                Courier New
                Fontcraft Courier
                DejaVu Sans Mono
                Everson Mono, also known as Everson Mono Unicode.
                Fedra Mono
                Fixed
                Fixedsys
                Fixedsys Excelsior
                Liberation Mono
                Lucida Console
                Lucida Sans Typewriter
                Lucida Typewriter
                Monaco (one of the original Macintosh system fonts)
                Monospace
                MS Gothic
                MS Mincho
                Nimbus Mono L
                OCR-A
                OCR-B
                Orator
                Ormaxx
                Prestige (similar to Courier)
                ProFont (A freeware font designed for easy readability at small sizes)
                Proggy Programming Fonts
                Sydnie (included with QuickTime)
                Terminal
                I didn't review all of them, but Andale, Consolas, and Lucida Console are "san serif"; Consolas is a bit wider font. They look similar to Arial, yet are monospaced and will automatically align.

                What would you lose by using one of them?

                Comment


                • #9
                  Any font you want displayed in a client browser must be installed on the client system.

                  I'd bet that 90% of those listed are not installed on a standard XP computer. If you're going to use mono spaced, use a times or courier font.

                  To me, it's just not a big deal to force alignment using a HTML or CSS means and a standard font.

                  Then you know it will always look how you expect it to look.

                  Comment


                  • #10
                    What is the reason for wanting to do artificially with a proportional font that which a monospaced font will do naturally?
                    Much easier for the user to read and far more professional-looking, that's why.
                    Michael Mattias
                    Tal Systems Inc. (retired)
                    Racine WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Originally posted by Michael Mattias View Post
                      Much easier for the user to read and far more professional-looking, that's why.
                      "professional-looking" (characteristics not divulged)

                      You might be presuming that all monospaced fonts look like Courier...
                      If so, take a look at the ones mentioned: Andale, Consolas, and Lucida Console. They are "professional-looking"...

                      I'm not familiar with CSS, so I don't know how simple that makes it.

                      Comment


                      • #12
                        If you are just displaying numerics I have a feeling somewhere from deep in the back of my brain that proportional font numeric characters are always the width of two spaces in the same font. So you can always create columns of right justified numerics by adding the appropriate numbers of spaces to the front of a string representation of a number.

                        But don't shoot me down in flames if this isn't correct, as I say, its from the back of my brain and could be wrong information.

                        Nick

                        Comment


                        • #13
                          have a feeling somewhere from deep in the back of my brain that proportional font numeric characters are always the width of two spaces in the same font
                          I don't know that it is two (2) spaces, but I do know numeric digits are all the same width.

                          But that format mask with all those spaces in it? Maybe you need to put two spaces in maks where where you want one space in the output? But mixed character strings and numbers are always going to be a problem I think... because you can't know how many "two in the mask" spaces you need without measuring the string which precedes those spaces... and if you are back to measuring text anyway, why not do it the most straightforward way?
                          Michael Mattias
                          Tal Systems Inc. (retired)
                          Racine WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment

                          Working...
                          X