Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge....
#4
Since everyone posted easy solutions, I now post a hard solution Wink

[syntax="QBasic"]'// ThisFile.bas
'// Prints out this file's contents Smile

'$INCLUDE: 'QB.BI'
DIM RegsX AS RegTypeX

'clear screen
CLS

'open the file
RegsX.ax = &H3D00
FILE$ = "THISFILE.BAS" + CHR$(0)
RegsX.ds = VARSEG(FILE$)
RegsX.dx = SADD(FILE$)
CALL INTERRUPTX(&H21, RegsX, RegsX)
Hand% = RegsX.ax

'read file data
RegsX.ax = &H3F00
RegsX.bx = Hand%
RegsX.cx = 1024
DIM Buffer AS STRING * 1024
RegsX.ds = VARSEG(Buffer)
RegsX.dx = VARPTR(Buffer)
CALL INTERRUPTX(&H21, RegsX, RegsX)

'close file
RegsX.ax = &H3E00
RegsX.bx = Hand%
CALL INTERRUPTX(&H21, RegsX, RegsX)

'convert \lf to nothing (leaving \cr only)
A$ = ""
FOR i = 1 TO LEN(Buffer)
IF MID$(Buffer, i, 1) <> CHR$(10) AND MID$(Buffer, i, 1) <> CHR$(0) THEN
A$ = A$ + MID$(Buffer, i, 1)
END IF
NEXT i
PRINT A$

END 'end the prog reading itself Smile[/syntax]

Have fun Smile

NOTE: It doesn't use QB's OPEN command Wink It uses DOS's commands for file handling Smile
Btw, did I use "anything similar"?


There are several options to work out this challenge:
#1: Using QB commands like OPEN like BinarySHOCK's example
#2: Hardcode like Antoni Gual's code
#3: Via shell like Meg's code
#4: Using DOS interrupts
And the last I can think of:
#5: Compile the program as EXE file, find the EXE location in memory, read EXE data and decode this to QB code.
Reply


Messages In This Thread
Challenge.... - by BinarySHOCK - 11-04-2004, 01:59 PM
Challenge.... - by Antoni Gual - 11-04-2004, 08:02 PM
Challenge.... - by Meg - 11-04-2004, 09:17 PM
Challenge.... - by Neo - 11-04-2004, 11:24 PM
Challenge.... - by BinarySHOCK - 11-05-2004, 03:18 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)