Announcement

Collapse
No announcement yet.

Array Delete failing

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

  • Array Delete failing

    I'm reposting since the code is changed, er, simplified

    Array Delete question

    Basically when an html file is received there are 10 lines of header information:
    HTTP/1.1 200 OK
    Date: Mon, 08 May 2000 16:31:55 GMT
    Server: Apache/1.3.6 (Unix) PHP/3.0.7 mod_perl/1.21 mod_frontpage/3.0.4.3
    Last-Modified: Sun, 23 Apr 2000 03:47:23 GMT
    ETag: "6828-21a0-3902724b"
    Accept-Ranges: bytes
    Content-Length: 8608
    Keep-Alive: timeout=65, max=200
    Connection: Keep-Alive
    Content-Type: text/html

    Here's the code:
    Code:
    Dim PageArray(1:10000) As String
    'Wait for response/page etc
    Do Until Eof(hTcp)
      Incr lCount
      Tcp Line hTcp, PageArray(lCount)
      Replace Chr$(13) With $CRLF In PageArray(lCount)
    Loop
    Tcp Close hTcp
    ErrType = Err
    If ErrType Then GoTo CLEANUP
    
    'Get the last modified date from inet server of page requested
    LastModDate = Right$(PageArray(4),Len(PageArray(4)) - 15)
    'Done with header, now get rid of it
    Array Delete PageArray(10) For 10
    
    Am I going about this wrong?
    Seems to me that I may be just deleting #10, when in fact I want to nuke #1 THROUGH 10 and shift all elements up..
    
    Thanks
    
    Scott


    [This message has been edited by Scott Turchin (edited May 08, 2000).]
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    hi scott

    there's a couple of problems with your code:

    first you loop until eof
    do until eof(htcp)
    incr lcount
    tcp line htcp, pagearray(lcount)
    replace chr$(13) with $crlf in pagearray(lcount)
    loop
    since the server is giving you back the length of the document in the "content-length" parameter, it would be much more efficient to parse the header (which off the top of my head should end at the first crlf + crlf combination), get the length and loop until the received length = "content-length".

    alternatively see thread http://www.powerbasic.com/support/pb...ad.php?t=13526 where lance shows that looping while len(buffer) is a better way to get all the info than using the eof flag.

    for the array delete statement the pb docs state clearly:
    together, index and count specify the portion of darray to be sorted. index specifies the element at which the sort is to begin, while count specifies the number of consecutive elements to be sorted. if index is omitted, the sort begins at the first element of darray.
    you are at present deleting 10 elements from item #10: just call array delete as array delete pagearray() for 10

    cheers

    florent

    ------------------

    Comment


    • #3
      Grabbing it binarily means I have one data chunk in say "buffer", now I have to parse it.
      A bit more overhead but if it is more efficient I will give that a shot..

      Now problem is, I can parse it on $CR but in some instances there are null lines and no $CR's, it makes a mess of my page..

      But, Your Array Delete PageArray() For 10 deleted all except line 10..

      It's getting uglier, good thing I backed it up

      I'll give it a shot after my dentist appt (Sorry Jim!! LOL)


      Thanks

      Scott

      ------------------
      Scott
      mailto:[email protected][email protected]</A>
      Scott Turchin
      MCSE, MCP+I
      http://www.tngbbs.com
      ----------------------
      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

      Comment


      • #4
        PS, the Dental thing is an inside joke with Jim and I

        Scott

        ------------------
        Scott
        mailto:[email protected][email protected]</A>
        Scott Turchin
        MCSE, MCP+I
        http://www.tngbbs.com
        ----------------------
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

        Comment


        • #5
          Hi Scott

          Scott: I must be tired, the quote I gave you was from the ARRAY SORT description - needless to say that doesn't work with ARRAY DELETE .

          Whats ARRAY DELETE actually does is not exactly deletion. What it effectively does is PUSH the elements up, ERASING their values but not DE-ALLOCATING them.

          One way to effectively DELETE / SLICE an array is to encapsulate the ARRAY DELETE function. Here's an example:

          Code:
          #COMPILE EXE
          
          #INCLUDE "win32api.inc"
          
          SUB ArrayDelete( BYREF sDelArray() AS STRING, BYVAL lFrom AS LONG, BYVAL lTo AS LONG)
             LOCAL i AS LONG
           
             FOR i = lFrom TO lTo
                 ARRAY DELETE sDelArray(1)
           
             NEXT
           
             REDIM PRESERVE sDelArray( lFrom : UBOUND(sDelArray(),1)-lTo )
           
          END SUB
           
          
          FUNCTION PBMAIN() AS LONG
             LOCAL i AS LONG
             LOCAL sMsg AS STRING
             DIM Test(1 : 50) AS STRING
           
             FOR i = 1 TO 50
                 Test(i) = STR$(i)
             NEXT
           
             FOR i = LBOUND(Test(),1) TO UBOUND(Test(),1)
                 sMsg = sMsg + Test(i) + CHR$(13)
             NEXT
           
             MSGBOX sMsg
             'delete elements 1 to 10
             CALL ArrayDelete( Test(), 1, 10)
           
             sMsg = ""
             FOR i = LBOUND(Test(),1) TO UBOUND(Test(),1)
                 sMsg = sMsg + Test(i) + CHR$(13)
             NEXT
           
             MSGBOX sMsg
           
          END FUNCTION
          Of course in you case it would be much more efficient NOT TO place the first 10 elements in the array

          Cheers

          Florent

          [This message has been edited by Florent Heyworth (edited May 08, 2000).]

          Comment


          • #6
            ARRAY DELETE AnyArray() FOR 10

            deletes 10 elements starting with the base - in your case, it deletes elements 0 thru 9 and should leave element 10 alone.

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

            Comment


            • #7
              After I get this TCP thing fixed I will go back and look at it.
              It may be possible for what i am doing to eliminate the array and just REMOVE the header into another array, parse it for the 2 items i need and write the BINARY data at this point to a file (html file)...that would work

              I gotta admit, this is just short of a browser, I put a sniffer on the wire, captured the browser sending the request, duplicated ALL the headers etc, everything, and the function is almost flawless...

              I'll post it when done, it allows the application to hit a server and grab the newer html help files...rather slick actually..


              Thanks, I'll let you know on the Array delete, it SHOULD work...


              Scott

              ------------------
              Scott
              mailto:[email protected][email protected]</A>
              Scott Turchin
              MCSE, MCP+I
              http://www.tngbbs.com
              ----------------------
              True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

              Comment


              • #8
                Folks, ARRAY DELETE is only every capable of deleting one array element... please reread the doc's carefully...
                ARRAY DELETE deletes a single element from array, an n-dimensional array. You can specify the index of the element which is to be deleted, how many elements it is allowed to shift when deleting it (count), and what value to give the last element after the rest of the elements have been shifted (expression).
                Michael was close (yet wrong) when he said:
                ARRAY DELETE AnyArray() FOR 10
                deletes 10 elements starting with the base - in your case, it deletes elements 0 thru 9 and should leave element 10 alone.
                What actually happens (in this case) is that the lowest subscript is deleted (ie, subscript zero unless a specific non-zero LBOUND was given, or a specific subscript number was specified), and then elements 1 to 9 are moved down one position, leaving element 9 "blank", and elements 10 onward untouched.

                If you want to delete 10 items, then you'll have to execute ARRAY DELETE 10 times (ie, in a loop)

                Try is for yourself:
                Code:
                ' PB/CC code to demonstrate the correct operation of ARRAY DELETE
                FUNCTION PBMAIN
                    DIM a$(12)
                    FOR x& = 0 TO 12
                        a$(x&) = FORMAT$(x&)
                        PRINT x&, a$(x&)
                    NEXT x&
                    ARRAY DELETE A$() FOR 10
                    FOR x& = 0 TO 12
                        PRINT x&, a$(x&)
                    NEXT x&
                    WAITKEY$
                END FUNCTION
                In other words, Scott's first message was an observation of the correct operation of ARRAY DELETE.


                ------------------
                Lance
                PowerBASIC Support
                mailto:[email protected][email protected]</A>
                Lance
                mailto:[email protected]

                Comment

                Working...
                X