REad *.doc

Blitz3D Forums/Blitz3D Beginners Area/REad *.doc

If you just want the text from a Word doc, try this:
(it's easier to show you the code than to type in the explanation)

Graphics 800,600

SetBuffer BackBuffer()

; Open the file to Read 
filein% = ReadFile("C:\My Documents\Blitz test.doc") 
;Just copied and pasted this code into a Word document

; Loop this until we reach the end of file 
While Not Eof(filein)
 
	GetByte% = ReadByte( filein )
	;count the bytes as you read them in
	count = count + 1

	;The Word doc header is 1,536 characters, so just skip past them
	;BTW, the header length is the same for both Word 97 and Word 2000
	If count > 1536 Then

		;Chr$(13) is the next line character, so print the current line, and reset "Word$" to null
		If GetByte = 13 Then
			Text 0,spacing,Word$
			spacing = spacing + 15
			Word$ = ""
		End If

		;If valid ASCII character then continue adding to Word$
		If GetByte > 31 And GetByte < 128 Then
			Word$ = Word$ + Chr$(GetByte)
		End If

	End If

Wend

Flip

WaitKey()

CloseFile filein

End



The straggler characters at the end can be ignored, or I'll leave it to you to figure the rest (cuz I don't know how).

As you can see in the code, the header data is skipped and any valid ASCII character is concatenated to the "Word$" variable. I haven't checked to see if the length of the "footer" data is the same length for every document, but this may be a way to eliminate the stray characters at the end of the text.

Andy