The following code compiled with PB/Win 8.04 and run under XP Home generates a GPF: TestCall.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
It's something to do with the BYVAL in the call to the function. Take that away and it works fine, or add BYVALs to both parameters in the Function header and it works OK. Taking away most of the 'innards' of the function also cures the problem! What's going on or what have I overlooked?
It's something to do with the BYVAL in the call to the function. Take that away and it works fine, or add BYVALs to both parameters in the Function header and it works OK. Taking away most of the 'innards' of the function also cures the problem! What's going on or what have I overlooked?
Code:
FUNCTION SplitLines(S AS STRING,MaxC AS LONG) AS STRING 'insert $CRLFs in place of spaces to make lines no longer than MaxC LOCAL SL(),S1, S2 AS STRING, L, I,J AS LONG L=PARSECOUNT(S,$CRLF) DIM SL(1:L) PARSE S,SL(),$CRLF FOR J=1 TO L S2=RTRIM$(SL(J)) : S1="" DO WHILE LEN(S2)>MaxC I=INSTR(-1,LEFT$(S2,MaxC)," ") IF I=0 THEN I=INSTR(-1,LEFT$(S2,MaxC),ANY $DQ+",-_/\") IF I=0 THEN I=MaxC IF S1<>"" THEN S1=S1+$CRLF S1=S1+RTRIM$(LEFT$(S2,I)) S2=MID$(S2,I+1) LOOP IF S1<>"" THEN SL(J)=S1+$CRLF+S2 NEXT J FUNCTION=JOIN$(SL(),$CRLF) END FUNCTION FUNCTION PBMAIN LOCAL TBLine AS STRING, ComLen AS LONG ComLen=12 TBLine="AAAAAAA BBBBBBBB CCCCCCCC DDDDDDD EEEEEEE" MSGBOX SplitLines(TBLine, BYVAL ComLen) END FUNCTION
Comment