load text file into scrollable window by Phaelax18th Jan 2005 7:39
|
---|
Summary load a text file into a scrollable window with preferred dimensions Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com set display mode 1024,768,16 rem text file to display filename$ = "c:\vraylog.txt" rem wrap text to this many characters (0 for no text wrapping) maxCharWidth = 57 rem array list to hold text from file dim words$(0) as string rem check to see if file specified is a text file if lower$(right$(filename$, 4)) = ".txt" rem check if file exists if file exist(filename$) rem open file for reading open to read 1, filename$ rem add text from file to array list while file end(1) = 0 read string 1, temp$ if maxCharWidth > 0 wrapText(temp$, maxCharWidth) else array insert at bottom words$(0) words$(array count(words$(0))) = temp$ endif endwhile endif endif rem close the file close file 1 lin as integer count as integer tx as integer ty as integer lin = 1 count = 20 tx = 100 ty = 100 boxLength = text width(space$(maxCharWidth)) if maxCharWidth = 0 then boxLength = screen width() boxHeight = text height(space$(1))*(count+1) repeat cls if upkey() = 1 if lin > 1 then dec lin, 1 endif if downkey() = 1 if lin < array count(words$(0))-count then inc lin, 1 endif rem box to show text boundaries ink rgb(100,100,100),0 box tx, ty, tx+boxLength, ty+boxHeight rem display the text showText(tx,ty,lin,count, rgb(255,128,255)) until spacekey() rem wraps text and adds lines appropriately to array list function wrapText(t$ as string, max as integer) r$ = left$(t$,max) array insert at bottom words$(0) i = array count(words$(0)) words$(i) = r$ nl = len(t$) - max if nl > 0 t$ = right$(t$,nl) wrapText(t$, max) endif endfunction rem displays text starting at coordinates X,Y and starts with line "lin" rem showing "count" number of rows (or until end of text is reached) function showText(x as integer, y as integer, lin as integer, count as integer, color as dword) if lin > 0 th = text height(words$(1)) L = 0 ink color, 0 for t = lin to lin+count if t <= array count(words$(0)) text x, y + L*th, words$(t) inc L endif next t endif endfunction |