Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Error Subscript is outside defined Range
Message
De
14/03/2013 17:16:32
 
 
À
14/03/2013 11:46:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01568322
Message ID:
01568419
Vues:
42
There is a potential problem in that you're modifying the value of the control variable of a FOR loop -- this could yield unpredictable resuts. The loop may or may not exit as intended. It could cause variable to go out of expected range. In your particular case not only are you incrementing it by 2, but you're doing it within a nested loop -- which almost certainly cause the variable I to exceed the limit value specified in the FOR loop. It also means that variable I will likely contain a value which will cause an out of bounds error when used as an array index.

NOTE: I've only shown you why you get the error -- it doesn't directly tell you how to fix the problem itself.

minor quibble: Even if FoxPro doesn't require it, you really should indent your code. It makes it easier for people to understand it.
T1=TIME()
CLEAR
SET DELETED ON

lcStr = FILETOSTR('1021165156.ps')
lnPOS = AT("%%Pages:",lcStr)
lcPageCount = ALLTRIM(SUBSTR(lcStr, lnPOS, 12))
lnPageCount = VAL(STRTRAN(lcPageCount,'%%Pages:',''))

IF lnPageCount>2
    DIMENSION occoupiedrange(lnPageCount)
    DIMENSION unoccoupiedrange(lnPageCount)

    LOCAL lcFile, lcText
    m.lcFile = [1021165156.ps]
    CREATE CURSOR Dummy (PS c(254), pos i,pageno N(2))
    APPEND FROM (m.lcFile) SDF

    SCAN
        IF Getwordnum(PS, Getwordcount(PS)) = [x] .OR. ;
                Getwordnum(PS, Getwordcount(PS)) = [y] .OR. ;
                Getwordnum(PS, Getwordcount(PS)) = [L] .OR. ;
                Getwordnum(PS, Getwordcount(PS)) = [w]

            m.lcText = Getwordnum(PS, Getwordcount(PS) - 1) && The second last word
            IF LEN(CHRTRAN(m.lcText, [1234567890], [])) = 0 && lcText contains only digits
                REPLACE pos WITH VAL(m.lcText)
            ENDIF
        ENDIF
    ENDSCAN



    FOR i= 1 TO lnPageCount
        CURTEXT='%%Page: '+ALLTRIM(STR(i))+' '+ALLTRIM(STR(i))
        NeXTTEXT='%%Page: '+ALLTRIM(STR(i+1))+" "+ALLTRIM(STR(i+1))

        *DELETE FROM dummy WHERE ps like "%(of%" AND pageno>1
        *DELETE FROM dummy WHERE ps like "%(Page%" AND pageno>1
        *DELETE FROM DUMMY where Ps LIKE '%BHARAT SANCHAR%' AND Pageno>1
        LOCATE FOR ALLTRIM(PS)=CURTEXT
        SCAN WHILE ALLTRIM(PS)<>NeXTTEXT OR EOF()=.T.
            REPLACE pageno WITH i
        ENDSCAN
        SELECT MIN(pos) FROM Dummy WHERE pageno=i AND pos>20 INTO ARRAY X
        SELECT MAX(pos) FROM Dummy WHERE pageno=i INTO ARRAY Y

        STORE Y-X+1 TO occoupiedrange(i)
        STORE (X) TO unoccoupiedrange(i)
        STORE (X-20) TO unoccoupiedrange(i)
    ENDFOR


    FOR i=2 TO (lnPageCount-1)
        BLANK=unoccoupiedrange(i)
        Filled=occoupiedrange(i+1)

        DO WHILE BLANK>=Filled
            NeXTTEXT='%%Page: '+ALLTRIM(STR(i+1))+" "+ALLTRIM(STR(i+1))
            LOCATE FOR PS=NeXTTEXT
            SKIP-1
            REPLACE PS WITH NeXTTEXT
            SKIP
            Prefixmul= ALLTRIM(STR((occoupiedrange(i)/68.7),18,2))
            REPLACE PS WITH '0 -72 &Prefixmul mul translate'
            WAIT WINDOW i
            Filled=Filled+occoupiedrange(i+1)
            WAIT WINDOW i
            i=i+1    && <--- a problem
        ENDDO
    ENDFOR
ENDIF

SELECT Dummy
SET TEXTMERGE ON
SET TEXTMERGE TO myfile.PS NOSHOW
SCAN
\\ << tRIM(pS) >>
\
ENDSCAN
SET TEXTMERGE TO
SET TEXTMERGE OFF

T2=TIME()
WAIT WINDOW T2
WAIT WINDOW T1
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform