11-04-2004, 11:24 PM
Since everyone posted easy solutions, I now post a hard solution
[syntax="QBasic"]'// ThisFile.bas
'// Prints out this file's contents
'$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 [/syntax]
Have fun
NOTE: It doesn't use QB's OPEN command It uses DOS's commands for file handling
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.
[syntax="QBasic"]'// ThisFile.bas
'// Prints out this file's contents
'$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 [/syntax]
Have fun
NOTE: It doesn't use QB's OPEN command It uses DOS's commands for file handling
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.