[futurebasic] Re: [FB] External File Resources

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2001 : Group Archive : Group : All Groups

From: Ken Shmidheiser <k.shmidheiser@...>
Date: Tue, 14 Aug 2001 14:53:13 -0400
Bernie wrote concerning Jamin's example:

>Jamin wrote:
>
>  > Depends on how many bytes you want, the layout you want them in, or how the
>  > resource is structured.
>  >
>  > Simple Example:
>  >
>  > LONG IF dataResH& <>  nil
>  >
>  >     FirstTwoBytes%  = dataResH&..nil%
>  >     FirstFourBytes& = dataResH&..nil&
>  >
>  >     PRINT FirstTwoBytes%
>  >     PRINT FirstFourBytes&
>  >
>  > END IF
>
>Thanks, Jamin but, unfortunately, this doesn't seem to help.
>
>A bit more info:
>Basically, the resource I want to read is ASCII text and, at the moment, the
>resource is 364 bytes in size.
>I'd like to transfer this text into a string, in say 255 chr blocks, and
>then search this/these strings to see if certain words exist in the
>resource.
>
>Thanks again
>Bernie

Bernie,

For demo sake we will assume that you are able to locate the resource
you wish to search and obtain its handle. (This demo assumes a
_"TEXT", 128 resource)

Here is one technique that reads the resource handle into a
container. You can than parse the container for the 255-character
string you want by specifying any selStart character and reading the
255 characters that follow from that point.

Of course, rather than slicing the container contents into
255-character strings, you could search the entire container for the
words you want, but I am a little fuzzy on what you are attempting to
do.

Ken

RESOURCES "myTextResource"

BEGIN GLOBALS
DIM tempTextHolder AS CONTAINER
END GLOBALS

LOCAL FN parseResource$( selStart AS LONG )
DIM maxPos    AS LONG
DIM outputStr AS STR255

maxPos = LEN( tempTextHolder )

IF tempTextHolder = "" THEN EXIT FN : Print "This resource is empty"
IF selStart + 255 > maxPos Then PRINT "Your selection exceeds¬
  the number of characters in the resource. The result will be truncated."

PRINT:PRINT "This resource contains"; maxPos; " characters."
PRINT:PRINT "Now reading 255 characters beginning at character"; selStart; ":"
PRINT:PRINT

tempTextHolder = MID$$( tempTextHolder, selStart, 255 )
      outputStr = tempTextHolder
tempTextHolder = ""

END FN = outputStr

WINDOW 1

dataResH& = FN GET1RESOURCE( _"TEXT",128 )
LONG IF dataResH& <> _nil
tempTextHolder = &dataResH&
PRINT FN parseResource$( 15  )'Search beginning at character 15
XELSE
PRINT "Sorry, the resource does not exist or is empty."
END IF

PRINT:PRINT:PRINT "Click mouse to end."

DO
HANDLEEVENTS
UNTIL FN BUTTON