TEXT
Fill an array of strings with the lines of an Edit Field
This was taken from one of my programs.
myEFHndl& = TEHANDLE(efID%)
LONG IF myEFHndl& <> 0
nlines = myEFHndl&..teNLines%
LONG IF nlines > 5
BEEP ' Maximum of 5 lines
nlines = 5
END IF
Z = 0
GET FIELD scriptHndl&, efID%
LONG IF scriptHndl& <> 0
FOR linloop = 1 TO nlines
Z = PEEK WORD(PEEK LONG(myEFHndl&) + 94 + ((linloop) * 2))
Z2 = PEEK WORD(PEEK LONG(myEFHndl&) + 94 + ((linloop + 1) * 2))
FOR X = Z TO Z2 - 2
myArray$(linloop) = myArray$(linloop) + CHR$(PEEK([scriptHndl&]+ X + 2))
NEXT X
NEXT linloop
dum$ = CHR$(PEEK([scriptHndl&]+ X + 2))
IF ASC(dum$) <> 13 THEN myArray$(nlines) = myArray$(nlines) +
CHR$(PEEK([scriptHndl&]+ X + 2))
KILL FIELD scriptHndl&
END IF
END IF
This is just off the top of my head, but try it. It may at least give you a push in the right direction:
lineStart = 0 'assumes you are taking 1st line in field
FOR myLine = 1 to 5 'assumes there _are_ 5 lines
lineEnd = {myEFHndl&..teLines% + myLine*2 +2} - 1 'get offset of last char
IF lineEnd = 0 THEN lineEnd = myEFHndl&..teLength%
lineLen = lineEnd - lineStart
myArray$(myLine);lineLen = [myEFHndl&..teTextH&] + lineStart 'move text
lineStart = lineEnd + 1
NEXT
This is the kind of thing I usually have to debug for a half-hour. I don't remember for sure how the end of the field is treated in the .lineStarts array--maybe you can check it out in Macsbug. I'd be interested to know what changes you have to make if use it.
The responses were excellant... thanks. I combined the ideas and came up with a solution that works for me. I present it here in a detailed example for others to benefit if they should ever want to:
Assume I just want to copy the 2nd line in the edit field to a string array.
Given:
myArray$(5) 'my destination array (each element to be a line of text)
myTEHndl& 'handle to my edit field containing 5 lines of text
Test$ 'temporary string variable (prev DIM'd) to assist with the copy
'start of code
ln% = 2 ' 2nd line
lnStr% = {[myTEHndl&]+_TElines+(ln%-1)*2} ' offset to start of 2nd line
lnNxt% = {[myTEHndl&]+_TElines+((ln%-1)+1)*2} ' offset to start of 3rd line
lnEnd% = lnNxt%-1 ' offset to end of 2nd line
lnLen% = lnEnd% - lnStr% + 1 ' num characters in 2nd line
lnLen% = lnLen% AND 255 ' force length to 255 char
BLOCKMOVE [FN TEGETTEXT(myTEHndl&)]+lnStr%,VARPTR(Test$)+1,lnLen%
POKE VARPTR(Test$),lnLen% ' set the string length
myArray$(2) = Test$ ' copy string to array
'end of code
|