find a text file

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
stilgar
Newbie
Posts: 4
Joined: Thu Aug 06, 2009 4:55 pm
Location: Ludington, michigan
Contact:

find a text file

Post by stilgar »

Hello all,
I have been out of basic programing for a long while, and decided to get back into it. (I even broke out my old DOS computer :o) I need code to find a text file by file name or date created.

I was asked by a bodyshop friend to make a simple invoice program. He is using DOS 6.22 on his shop computer (his database for parts is still DOS based. so I was thinking of saving each customer invoice as a text file. then he can edit or print them as needed.

I have the input, save, and print functions done. he likes it so far, but asked about a search in case he needs to reprint or edit one.

thanks,
stilgar :D
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Why not use a special file extension? Are you using LPRINT to print the files or Notepad?

Add an extension to a filename like ".CAR". Then you can use FILES "*.CAR to view them to a point where it will scroll.

If you don't want the screen to scroll, you can pipe filenames using SHELL.

SHELL "DIR *.CAR /B > carfiles.txt"

/B just sends just filenames to the carfiles.txt file. you can read the list using INPUT #1, filenames$ and place them in an array so that you can print them to the screen in your own format.

Also you can use PRINT #1, USING to format the part data information using a template.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
stilgar
Newbie
Posts: 4
Joined: Thu Aug 06, 2009 4:55 pm
Location: Ludington, michigan
Contact:

Post by stilgar »

Hello burger2227,

the program I have written is similar to database. upon program start up, the user gets a menu, with options like load a invoice, edit a invoice, and print (sorry I am unable to get to my computer at this time, for full details)

when he adds a new client, fills out a set of fields and the information is saved by the contraction of the client last name and date. the extension is .INV.

the files are saved in a folder called "invoice09". each job is a separate file.
what I need is a sub that will search this folder for a file that has the last name or date.

If I can get to my machine today, would you like me to send you my program so far?

and yes the avitar is the computer I use for programing 8)

thanks,
stilgar
?Remember, cute and cuddly, boys. Cute and cuddly."
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

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$
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
stilgar
Newbie
Posts: 4
Joined: Thu Aug 06, 2009 4:55 pm
Location: Ludington, michigan
Contact:

Post by stilgar »

The idea is, he selects the invoice edit option from the main menu.
then a page asks for a client name. then the search will locate the file.

example file name..."johndoe101209.INV" , (client name...john doe, date of invoice 10/12/2009)

silly question... do you think I am heading in a bad direction, should I rethink the program?? As I stated before I have been out of basic programing for a many years. haven't done much programing at all in the last 3 years.

Thanks,
Stilgar
?Remember, cute and cuddly, boys. Cute and cuddly."
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Qbasic can only read 8.3 filenames max! How did you create those filenames?

DOS will only show the first 6 characters, a ~ and a number 1 or more.

I have an Interrupt routine that can search for information inside of a file, but frequent customers would have many files.

Try just using an invoice number or date up to 8 characters. How is the user supposed to find long filenames in DOS?

Try VB or something.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
stilgar
Newbie
Posts: 4
Joined: Thu Aug 06, 2009 4:55 pm
Location: Ludington, michigan
Contact:

Post by stilgar »

Hmm, I forgot the long file name bit, in the save function, 2 variables LN$ (last name), and the date is combined for file name.

I think I need to go back to start and relook over every thing.
Thanks for the help and insight, will probability have more questions later.

thanks to all, great forum,
stilgar
?Remember, cute and cuddly, boys. Cute and cuddly."
Post Reply