BBS: Inland Empire Archive Date: 03-28-93 (12:05) Number: 37 From: TOM HAMMOND Refer#: NONE To: SEAN SULLIVAN Recvd: NO Subj: Need A Routine Conf: (2) Quik_Bas
SS>I know I've seen a routine for determining the directory from which a program was launched, but can't remember where. Anyone have this info? Found this on the echo quite a while ago. Hope it's (close to) that which you seek. Tom Hammond ' ************************************************************* ' ** ** ' ** This program will read the TRUE program name from the ** ' ** Environment. If you are executing a program called ** ' ** HELLO.EXE, and only typed HELLO at the command line, ** ' ** It would return the ENTIRE PATH of where HELLO.EXE is ** ' ** located. If HELLO.EXE is in C:\DOS\BASIC\QB, the ** ' ** line returned from this program would be ** ' ** c:\dos\basic\qb\HELLO.EXE instead of just HELLO ** ' ** ** ' ** This program is basically a reprint from a very early ** ' ** Cobb Inside Microsoft Basic Journal, but can be used ** ' ** freely. It is in the Public Domain. No credit or ** ' ** other compensation is necessary or expected. ** ' ** ** ' ** This program should work with BOTH QuickBasic 4.5 and ** ' ** the Basic Professional Development System 7.xx ** ' ** ** ' ************************************************************* ' **** Below is the main program module ************ DECLARE FUNCTION ProgramName$ () DEFINT A-Z CONST FALSE = 0 CONST TRUE = -1 'PDS users should change the next line to include the QBX.BI file '$INCLUDE: 'QB.BI' CLS PRINT "Program name = "; ProgramName$ END ' **** Below is a FUNCTION that should be parsed by the QB *** ' **** or QBX Environments. ********************************* '=================== Function ProgramName$ ====================== '== INPUT: None == '== RETURNS: Name of currently executing program == '================================================================ ' FUNCTION ProgramName$ DIM Regs AS RegType 'Get PSP address Regs.ax = &H6200 CALL Interrupt(&H21, Regs, Regs) PSPSegment = Regs.bx 'Find environment address from PSP DEF SEG = PSPSegment EnvSegment = PEEK(&H2D) * 256 + PEEK(&H2C) 'Find the filename DEF SEG = EnvSegment EOT = FALSE 'Set end of environment table flag Offset = 0 WHILE NOT EOT Byte = PEEK(Offset) 'Get table character IF Byte = 0 THEN 'End of environment string? ' PRINT 'Uncomment to print environment Offset = Offset + 1 Byte = PEEK(Offset) IF Byte = 0 THEN 'End of environment? Offset = Offset + 3 'Yes - Skip over nulls & tbl info C% = PEEK(Offset) WHILE C% <> 0 'Assemble filename string FileN$ = FileN$ + CHR$(C%) ' from individual Offset = Offset + 1 ' characters C% = PEEK(Offset) WEND EOT = TRUE 'Set flag to exit while/wend loop END IF ELSE 'No-Read more environment string ' PRINT CHR$(Byte); 'Uncomment to print environment Offset = Offset + 1 END IF WEND ProgramName$ = FileN$ DEF SEG END FUNCTION --- * Origin: Night Shift BBS (314)635-7588 HST 14.4 (1:289/15)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET