How is the search performed? Does the user enter a name or just look at a list of all of the files available? These are things you will have to consider first.
This function finds the current folder path:
Code: Select all
FUNCTION Path$ 'assign to a variable for later use in other folders!
SHELL "DIR *.INV > INV-DATA.INF" 'get all file & dir info
OPEN "INV-DATA.INF" FOR INPUT AS #1
DO WHILE NOT EOF(1) 'just in case file is empty
LINE INPUT #1, line$
location = INSTR(1, line$, ":\") 'find the drive path notation
IF location THEN EXIT DO
LOOP
CLOSE #1
IF location THEN
line$ = MID$(line$, location - 1, LEN(line$) - location + 2)
Path$ = RTRIM$(line$) + "\" 'a QB useable directory path
ELSE : Path = "" 'returns zero length string if not found
END IF
END FUNCTION
Here is a sub to display the files in SCREEN 12 (156 per page):
Code: Select all
SUB DirList (F$)
DirPath$ = SPACE$(1) + Path$ + SPACE$(1)
SHELL "DIR *.INV /B > INV-DATA.INF" '/B = pipe filenames only
OPEN "INV-DATA.INF" FOR INPUT AS #1
IF LOF(1) THEN
CLS : Border 13: Align 14, 1, DirPath$: COLOR 11: LOCATE 2, 2
DO WHILE NOT EOF(1)
Fcount = Fcount + 1
LINE INPUT #1, FileN$
PRINT FileN$; SPACE$(13 - LEN(FileN$)); 'max DOS filename length is 12
IF Fcount MOD 6 = 0 THEN PRINT "": LOCATE , 2 'new line
IF Fcount MOD 156 = 0 THEN 'next screen
COLOR 14: LOCATE 29, 27: INPUT ; "Enter filename or hit Enter: ", F$
IF LEN(F$) THEN EXIT DO
CLS : Border 13: Align 14, 1, DirPath$: COLOR 11: LOCATE 2, 2
END IF
LOOP
ELSE : Align 12, 28, "NO Files Found!": CLOSE #1: EXIT SUB
END IF
CLOSE #1
Align 10, 28, "Total Files shown =" + STR$(Fcount)
IF LEN(F$) = 0 THEN COLOR 14: LOCATE 29, 27: INPUT ; "Enter filename. Enter quits!: ", F$
END SUB
Here are some auxiliary SUBs used in DirList SUB:
Code: Select all
SUB Border (clr%)
COLOR clr%
FOR Row = 1 TO 30
LOCATE Row, 1: PRINT CHR$(179);
LOCATE Row, 80: PRINT CHR$(179);
NEXT Row
FOR Col = 1 TO 80
LOCATE 1, Col: PRINT CHR$(196);
LOCATE 30, Col: PRINT CHR$(196);
NEXT Col
LOCATE 1, 1: PRINT CHR$(218);
LOCATE 1, 80: PRINT CHR$(191);
LOCATE 30, 1: PRINT CHR$(192);
LOCATE 30, 80: PRINT CHR$(217);
END SUB
SUB Align (Tclr, Trow, Txt$)
Tcol = 41 - (LEN(Txt$) \ 2)
COLOR Tclr: LOCATE Trow, Tcol: PRINT Txt$;
END SUB
The SUB will display up to 156 files per screen and allows a user to enter a choice or press enter for more files. You will need to move to your invoice folder first!
You can save your original folder path using a variable with the Path$ Function like: oldpath$ = Path$ to return to your program folder later using: CHDIR oldpath$