home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / exitcode / exit2.bas < prev    next >
Encoding:
BASIC Source File  |  1994-04-07  |  3.2 KB  |  107 lines

  1. '******************************EXIT2.BAS*********************************
  2. '
  3. '
  4. 'JRD NOTE:    Thu  04-07-1994  11:25:48
  5. '
  6. 'Tony Elliot just wrote a piece in Visual BASIC Programmer's Journal saying
  7. 'that what I did not only DOESN'T WORK, but it locks the computer.
  8. 'So, I am trying the method he mentioned.
  9. '
  10. 'Dave Cleary wrote about the same code back in about 1991, it is to use
  11. 'a BASIC -internal- run time library command with the ALIAS command as
  12. 'follows:
  13. '
  14. 'DECLARE SUB EndLevel ALIAS "_exit" (BYVAL ErrorLevel%)
  15. '
  16. 'See ALIAS.BAS which contains the note about this. At the time, I
  17. 'didn't understand it. Since you are calling an -internal- command,
  18. 'there is no SUB to flesh out, guess that's what confused me.
  19. '
  20. 'By the way, the original works fine..... so far, but in fairness to
  21. 'everyone, once I heard from the guys that use debuggers like Periscope
  22. 'that what I did maybe unstable, had to also give you what they say is a
  23. 'better method.
  24. '
  25. 'EXIT2.BAS works with BATCH2.BAT, and must be compiled to a stand-alone
  26. '*.EXE file,
  27. '
  28. '   *****       DO NOT RUN IT IN THE QB.EXE ENVIRONMENT!!!   ******
  29. '
  30. '------------------SOME TEXT OF EXITCODE.BAS FOLLOWS------------------
  31. '
  32. 'I've been looking for this technique to use in QuickBASIC 4.5 for
  33. 'years.... but it was there all the time by using CALL interrupt.
  34. '
  35. 'JRD NOTE:
  36. 'With this code you can set an ERRORLEVEL when you exit your QuickBASIC
  37. '4.5 program.
  38. 'I know you can do this with PDS 7.1 and VisualBASIC for DOS, with
  39. '
  40. 'END Exitcode% Statement
  41. '
  42. 'but....
  43. '
  44. 'I wanted to know -where- the COMMAND.COM got that ERRORLEVEL number from
  45. 'Now I know...
  46. '
  47. '&H21 Interrupt, Service 4CH is the "Terminate with return code"
  48. 'We try it to exit and set an ERRORLEVEL. '1/19/94
  49. '
  50. 'WOW!
  51. 'if you run this in the QuickBASIC Environment....
  52. '
  53. ' All HELL breaks loose!
  54. '
  55. 'So....DON'T DO IT.... Remember you were warned. This overwrites ROM,
  56. 'some how messes up LPT1, and does other weird things.... INCLUDING
  57. 'causing the cursor to disappear if you run the executable code,
  58. 'EXITCODE.EXE from a batch file and don't set the cursor as this program
  59. 'does.
  60. '
  61. 'BUT.... the good news is.... IT WORKS.
  62. '
  63. 'I made BATCH.BAT to be used with this. It is a true blue
  64. 'IF ERRORLEVEL batch file
  65. 'need to make SURE you slap the cursor need nothing more
  66. 'than the following to prevent the cursor from disappearing:
  67. '
  68. 'LOCATE , , 1 ,4 ,7
  69. '
  70. 'declarations, etc.
  71. DEFINT A-Z
  72. DECLARE SUB LocateIt (row%, text$)
  73. DECLARE SUB ColorIt (Fgd%, Bgd%)
  74. DECLARE SUB EndLevel ALIAS "_exit" (BYVAL ErrorLevel%)
  75.  
  76. 'executable code
  77. COLOR 15, 1
  78. CLS
  79. text$ = "TYPE: an Exit Code (1 to 10) to test"
  80. CALL LocateIt(10, text$)
  81. text$ = SPACE$(2)
  82. CALL ColorIt(11, 0)
  83. CALL LocateIt(11, text$)
  84. row = CSRLIN
  85. col = POS(0)
  86.  
  87. LOCATE row, col - 2, 1, 4, 7
  88. INPUT "", ExitCode%
  89. CALL ColorIt(15, 1)
  90. text$ = "Setting ERRORLEVEL TO: " + STR$(ExitCode%)
  91. CALL LocateIt(13, text$)
  92. PRINT
  93.  
  94.     CALL EndLevel(ExitCode%)
  95.     'the next never gets printed as we are out of here
  96.     text$ = "Return Code is: " + STR$(Regs.ax MOD 256)
  97.  
  98. SUB ColorIt (Fgd, Bgd)
  99. COLOR Fgd, Bgd
  100. END SUB
  101.  
  102. SUB LocateIt (row%, text$)
  103. LOCATE row%, 41 - (LEN(text$) \ 2)
  104. PRINT text$;
  105. END SUB
  106.  
  107.