Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

? on searching files based on criteria / storing results

Status
Not open for further replies.

kanin247

Programmer
Apr 23, 2001
113
US
To Whom It May Concern:
I was wondering if you could help me with the following: I am trying to develop a program in QBASIC that takes a list of similar .dat files (as in, the data within each file is in the same format - Date, Time, Name, Description, Production Sales - where each file differs by date) and the program searches these files, based on criteria provided by the user (say, I want the Production Sales for the 7th of every month at 9:00am), and displays the results. So, in this case, the program would look through 12 files and take out the row of data for 9:00am and print/store these results in a new file. I can't seem to visualize how I can create this "search engine." I am able to search through one file, but how do I search different files given criteria?

I would appreciate any help. Thank you.

kanin
 
How you set about this depends on how methodical you were when you named those files. If they were named by date, such as Jun01, Jun02 etc. you could use :-

Get the day from the user, eg 7
Change it to a string, eg 7
If the string length is one then prefix it with a 0, eg 07
or
If the string length is <10 then prefix it with a 0, eg 07

To get the list of files to open you could then use SHELL and the DIR command with wildcards to put a list of the files to be opened into a seperate file. You can use something like

FindFile$ = &quot;dir ???&quot; + CharNum$ + &quot;*.dat > c:\ZFileDir.tmp&quot;
SHELL FindFile$

(I'm surprised that code worked, QBasic is usually very sniffy when mixing commands and strings, but it worked ok on my PC)

Open this zFileDir.tmp, get the file names, then open and extract the info you need from each one.

If you weren't so methodical naming those files, you are going to have to open everyone and search for the date and time. The method should be the same, make a file list using whatever wild cards you think appropriate.

don't forget you are going to have at least three files open. 1) the file listing 2) the file you're reading from and 3) the file you're writing to, so don't forget to use FREEFILE and keep a track of those file numbers when reading and writing.

Ray



 
duh, there is an error in the message above, it should read

If the string length is 1 then prefix it with a 0, eg 07
or
If the number is < 10 then prefix the string version with a 0, eg 07

Ray
 
Ray,
Could I get some clarification in the following:

FindFile$ = &quot;dir ???&quot; + CharNum$ + &quot;*.dat > c:\ZFileDir.tmp&quot;

&quot;dir ???&quot; - does this stand for the directory folder in which my data file exists?

&quot;c:\ZFileDir.tmp&quot; - does this file store my results?

&quot;CharNum$&quot; - what is this referring to? the starting position of my specified heading? for instance,

====data file====
07/07/02 8:00:00 Name Description 131.03

the time would start at character position 11

I appreciate you help. Thank you.

kanin
 
' =============================================
' Data search application 1.0
' =============================================
'
' == Notes ====================================
'
' Requires QB 7.0 or better, and I hate that.
'
' If anyone could recreate a DIR$ or simular
' named function that does the same thing,
' porting it to QBasic or QB45 would not be
' difficult becuase 99% is allready
' compatible.
'
' I suppose you could substitute all the
' DIR$ calls for SHELL calls, but I hate the
' amount of memory SHELL uses now that DOS
' has gotten (*ahem*) a bit fatter.
'
' I was going to finish all of the search
' checking routines, but could never find
' information about checking leap year.
'
' If anyone wants to fix that, I would
' appreciate it.
'
' Oh well... it's a pretty good program
' anyway, so I'l slap my name on it:
'
' Created by Allan Davis (aka Nyaj2k1)
'
' QB.ForgiveMySpelling = TRUE
' QB.FixMajorErrorsForMe = TRUE
'
' == Declare Subroutines and Functions ========

DECLARE SUB ProcessFile (iStr AS STRING)
DECLARE FUNCTION DoCompares! ()
DECLARE SUB PrintFileInfo ()
DECLARE FUNCTION ReturnNumberOfDaysInYear! (iStr AS STRING)

' == Declare variables ========================

TYPE iDataFile
iDay AS STRING * 2
iMonth AS STRING * 2
iYear AS STRING * 4
iHour AS STRING * 2
iMinute AS STRING * 2
iSecond AS STRING * 2
iName AS STRING * 255
iDiscription AS STRING * 1024
iProductionSales AS STRING * 128
END TYPE
TYPE iCompareDataFile
iMinDay AS STRING * 2
iMinMonth AS STRING * 2
iMinYear AS STRING * 4
iMaxDay AS STRING * 2
iMaxMonth AS STRING * 2
iMaxYear AS STRING * 4
END TYPE
DIM FileNameRead AS STRING
DIM SHARED DataFile AS iDataFile
DIM SHARED CompareTo AS iCompareDataFile
DIM CompareSuccess AS INTEGER
CONST Anything = &quot;0&quot;

' == Program ==================================
'
' Clear the screen.

CLS

' Change the current directory to the drive
' that contains all of the data files.

CHDIR &quot;C:\DATFILES\&quot;

' I am assuming the format of the files is
' plain text, and in this format:
'
' DD/MM/YYYY
' HH:MM:SS
' NAME
' DISCRIPTION
' PRODUCTION SALES
'
' Now, we setup the search criteria.

CompareTo.iMinDay = Anything
CompareTo.iMaxDay = Anything
CompareTo.iMinMonth = &quot;2&quot;
CompareTo.iMaxMonth = Anything
CompareTo.iMinYear = &quot;2002&quot;
CompareTo.iMaxYear = Anything

' Assuming this is correct, we should now
' able to read and process the data.

FileNameRead = DIR$(&quot;*.dat&quot;)
DO
ProcessFile FileNameRead
CompareSuccess = DoCompares
IF CompareSuccess = 1 THEN
PrintFileInfo
END IF
FileNameRead = DIR$
IF FileNameRead = &quot;&quot; THEN
EXIT DO
END IF
LOOP
SYSTEM

' == End of Program ===========================

FUNCTION DoCompares
' This function performs a check on
' the current file's search paramiters.
' It was never finished, and does not
' work correctly.
DIM CompareResult AS INTEGER
DIM DaysInCompareYearA AS INTEGER
DIM DaysInCompareYearB AS INTEGER
CompareResult = 1
' Check...
DaysInCompareYearA = ReturnNumberOfDaysInYear(CompareTo.iMinYear)
DaysInCompareYearB = ReturnNumberOfDaysInYear(DataFile.iYear)
IF NOT VAL(CompareTo.iMinYear) = VAL(Anything) THEN
IF VAL(CompareTo.iMinYear) * ((VAL(CompareTo.iMinMonth) / 12) * (VAL(CompareTo.iMinDay) / DaysInCompareYearA)) > VAL(DataFile.iYear) * ((VAL(DataFile.iMonth) / 12) * (VAL(DataFile.iDay) / DaysInCompareYearB)) THEN
CompareResult = 0
END IF
END IF
DaysInCompareYearA = ReturnNumberOfDaysInYear(CompareTo.iMaxYear)
IF NOT VAL(CompareTo.iMaxYear) = VAL(Anything) THEN
IF VAL(CompareTo.iMaxYear) * ((VAL(CompareTo.iMaxMonth) / 12) * (VAL(CompareTo.iMaxDay) / DaysInCompareYearA)) < VAL(DataFile.iYear) * ((VAL(DataFile.iMonth) / 12) * (VAL(DataFile.iDay) / DaysInCompareYearB)) THEN
CompareResult = 0
END IF
END IF
DoCompares = CompareResult
END FUNCTION

SUB PrintFileInfo
PRINT &quot; >> This file met the search criteria.&quot;

END SUB

SUB ProcessFile (iStr AS STRING)
DIM Filenum AS INTEGER
DIM CurPos AS INTEGER
DIM Looper AS INTEGER
DIM CurProcess AS INTEGER
DIM Temp AS STRING
DIM Buffer AS STRING
DIM CurChr AS STRING * 1
DIM TempProcessArray(1 TO 3) AS STRING
Filenum = FREEFILE
OPEN iStr FOR INPUT AS #Filenum
INPUT #Filenum, Temp
' This first line is Month, Day, Year
' all on the same line. We need to
' process this line:
CurProcess = 0
FOR Looper = 1 TO LEN(Temp) + 1
CurChr = MID$(Temp, Looper, 1)
IF CurChr = &quot;/&quot; OR Looper = LEN(Temp) + 1 THEN
CurProcess = CurProcess + 1
TempProcessArray(CurProcess) = Buffer
Buffer = &quot;&quot;
ELSE
Buffer = Buffer + CurChr
END IF
NEXT
' We have our data in the TempProcessArray
' now, move it to the DataFile vars.
DataFile.iDay = TempProcessArray(1)
DataFile.iMonth = TempProcessArray(2)
DataFile.iYear = TempProcessArray(3)
' We now have the date information, time
' to get the time. It will also need
' processing.
CurProcess = 0
INPUT #Filenum, Temp
FOR Looper = 1 TO LEN(Temp) + 1
CurChr = MID$(Temp, Looper, 1)
IF CurChr = &quot;:&quot; OR Looper = LEN(Temp) + 1 THEN
CurProcess = CurProcess + 1
TempProcessArray(CurProcess) = Buffer
Buffer = &quot;&quot;
ELSE
Buffer = Buffer + CurChr
END IF
NEXT
' Put the time info into the DataFile
' variables.
DataFile.iHour = TempProcessArray(1)
DataFile.iMinute = TempProcessArray(2)
DataFile.iSecond = TempProcessArray(3)
' The remainder of the data is pretty
' straightforward...
INPUT #Filenum, Temp
DataFile.iName = Temp
INPUT #Filenum, Temp
DataFile.iDiscription = Temp
INPUT #Filenum, Temp
DataFile.iProductionSales = Temp
CLOSE #Filenum
' Finished returning the data.
END SUB

FUNCTION ReturnNumberOfDaysInYear (iStr AS STRING)
' This function calculates the number
' of days in a year while calculating
' leap year.
' Never finished and does not work correctly.
ReturnNumberOfDaysInYear = 365
END FUNCTION
 
I should have made it cearer for you. What you are doing is putting together a command string.

The DIR is the DOS command, it should include the directory where your data files reside, such as &quot;DIR c:\data\&quot;

The ? is a wildcard. It means substitute any character for this one. Suppose you named your files Jan, Feb, Mar, Apr etc. ??? means allow anything in these first three places.

* is the other wildcard. It means substitute any combination of characters for this and subsequent positions. An example of its use is JAN*.* Here the first * would include the files Jan, Jan12, January, Janabcde and so on. The second * would allow any file extension htm, txt, doc and so on.

They can be used in combination, so that ???07* would get Jan07abc, Jan07, Feb07rfg, bad07oop and so forth.

You can't use *??? as * means any characters in that position and following positions.

CharNum$ is the variable I used to store the dated file that you want to read, 07 in the examples I used.

The c:\ZFileDir.tmp is indeed the file where the directory listing will be stored.

> means send the output of a DOS command to a file. This works for any DOS command and can be used on the command line. Every time this is run the created file is overwritten with the new data. If you want to append to the output file use >>. This is also a DOS redirection command and can also be used at the command line. There is another redirect command that is used, and that is NUL. Using something like DIR > NUL means run the dir command and send the results to the NUL device driver (lost in outer space somewhere). It was useful in batch files to suppress any and all output messages from DOS commands.

So in the line

FindFile$ = &quot;dir ???&quot; + CharNum$ + &quot;*.dat > c:\ZFileDir.tmp&quot;

you are creating a command line for DIR which will include the file names you are trying to find, and send the results of dir to a file.

Something I should have mentioned in the original post is that depending on your version or Windows and QBasic the layout of the DIR command is not the same as if you run it at the command line. This is because QBasic runs a seperate version of Command.com. On my machine (Windows 2000, QBasic v1.1) DOS is run from QBasic using Cmd.exe not Command.com

I've explained and used this method in my program filedir.bas at You can use the &quot;find on this page&quot; to search for &quot;sub getcurr&quot; which will take you to the code which shows the DIR command line.

Ray
 
Nyaj2k1's program isn't that bad for what you want (apart from the unfinished routines). It shows you how to open data files and define the records using the TYPE command.

Using this method you can get the individual fields out of a database. I've included something similar in a short program I wrote at
A little while ago I was playing around with dates, in Nyaj2k1's program the date functions aren't finished, you can find some useful (well, I think they are) date routines at
Ray
 
Thanks... I would have totaly finished the program, but never could find a way to calculate the number of days in a year calculating leap year. Really, all I needed was a leap year date... I don't know when the last one was...

By using DIR$ insted of the filenames themselfs, you don't have to worry about keeping numbers in order and switching filenames on all the files when a file in the center is deleted.

This application I was trying to write ignores filenames totaly, and because of this, the is no need for record keeping. Simply drop a DAT file in the folder, or remove a DAT file from the folder.
 
The last leap year was 2000.

IF (Year MOD 4) = 0 THEN
ReturnNumberOfDaysInYears = 366
ELSE
ReturnNumberOfDaysInYear = 365
END IF

Nice work Nyaj2k1!! :)I
 
Thanks for the leap year info.

I never like to leave an unfinished program, no matter what it is, so I'll get to work on completing it.
 
Ther routine for leap year should be:
If (Year mod 4)=0 then
if (year mod 100)=0 then
if (year mod 400)=0 then
Nrofdaysinyear=366
else
Nrofdaysinyear=365
endif
else
Nrofdaysinyear=366
endif
else
Nrofdaysinyear=365
endif

if you don't do like this your program will suffer the Y2.1K effect!! :)) Antoni
 
Ummm... you sure? Because the one Oak gave me works with > 2000 years just fine.
 
' =============================================
' Data search application 1.1
' Created by Allan Davis (aka Nyaj2k1)
' =============================================
'
' == Notes ====================================
'
' ==== New ====================================
'
' Thanks for the feedback and the help that
' was offered to my simple prog here.
'
' Special thanks to Oak for providing the
' information on leap years, allthough when I
' sat back down to start working on this
' program, I soon realized that I would not
' need to do so... that a simple < or >
' would suffice.
'
' Thanks anyway though, I know I'll use leap
' years one day...
'
' That DoCompares routine is pretty dang
' complex... I wonder if anyone could
' simplify that. I didn't really spend
' much time on it, and it's just the first
' idea that sprang into my head.
'
' To run this program, you are going to need
' some &quot;.dat&quot; files somewhere... the format I
' assume they are in is:
'
' DD/MM/YYYY
' HH:MM:SS
' NAME
' DISCRIPTION
' PRODUCTION SALES
'
' ==== Old ====================================
'
' Requires QB 7.0 or better, and I hate that.
'
' If anyone could recreate a DIR$ or simular
' named function that does the same thing,
' porting it to QBasic or QB45 would not be
' difficult becuase 99% is allready
' compatible.
'
' I suppose you could substitute all the
' DIR$ calls for SHELL calls, but I hate the
' amount of memory SHELL uses now that DOS
' has gotten (*ahem*) a bit fatter.
'
' QB.ForgiveMySpelling = TRUE
' QB.FixMajorErrorsForMe = TRUE
'
' == Declare Subroutines ======================

DECLARE SUB PrintFileInfo ()
DECLARE SUB ProcessFile (iStr AS STRING)
DECLARE SUB WordWrap (iText AS STRING, X AS INTEGER, Y AS INTEGER, X2 AS INTEGER, Y2 AS INTEGER)

' == Declare Functions ========================

DECLARE FUNCTION Alltrim$ (iStr AS STRING)
DECLARE FUNCTION DoCompares% ()

' == Declare variables ========================

TYPE iColors
Highlight AS INTEGER
Normal AS INTEGER
Field AS INTEGER
Content AS INTEGER
END TYPE
TYPE iDataFile
iDay AS STRING * 2
iMonth AS STRING * 2
iYear AS STRING * 4
iHour AS STRING * 2
iMinute AS STRING * 2
iSecond AS STRING * 2
iName AS STRING * 255
iDiscription AS STRING * 1024
iProductionSales AS STRING * 128
END TYPE
TYPE iCompareDataFile
iMinDay AS STRING * 2
iMinMonth AS STRING * 2
iMinYear AS STRING * 4
iMaxDay AS STRING * 2
iMaxMonth AS STRING * 2
iMaxYear AS STRING * 4
END TYPE
DIM SHARED FileNameRead AS STRING
DIM SHARED DataFile AS iDataFile
DIM SHARED CompareTo AS iCompareDataFile
DIM SHARED Clr AS iColors
CONST Anything = &quot;-1&quot;

' == Program ==================================
'
' Setup the color vars.

Clr.Highlight = 15
Clr.Normal = 7
Clr.Field = 9
Clr.Content = 15

' Clear the screen.

'CLS

' Change the current directory to the drive
' that contains all of the data files.

CHDIR &quot;C:\DATFILES\&quot;

' I am assuming the format of the files is
' plain text, and in this format:
'
' DD/MM/YYYY
' HH:MM:SS
' NAME
' DISCRIPTION
' PRODUCTION SALES
'
' Now, we setup the search criteria.

CompareTo.iMinDay = &quot;2&quot;
CompareTo.iMaxDay = &quot;7&quot;
CompareTo.iMinMonth = Anything
CompareTo.iMaxMonth = &quot;4&quot;
CompareTo.iMinYear = Anything
CompareTo.iMaxYear = &quot;2007&quot;

' Assuming this is correct, we should now
' able to read and process the data.

FileNameRead = DIR$(&quot;*.dat&quot;)
DO
IF FileNameRead = &quot;&quot; THEN
EXIT DO
END IF
ProcessFile FileNameRead
IF DoCompares = 1 THEN
PrintFileInfo
END IF
FileNameRead = DIR$
LOOP
SYSTEM

' == End of Program ===========================

FUNCTION Alltrim$ (iStr AS STRING)
Alltrim$ = LTRIM$(RTRIM$(iStr))
END FUNCTION

FUNCTION DoCompares%
' This function performs a check on
' the current file's search paramiters.
DIM YearResult AS INTEGER, MonthResult AS INTEGER
DIM DayResult AS INTEGER, PassedMinTest AS INTEGER
DIM PassedMaxTest AS INTEGER
PassedMinTest = 0
PassedMaxTest = 0
IF NOT VAL(CompareTo.iMinYear) = VAL(Anything) THEN
IF VAL(DataFile.iYear) > VAL(CompareTo.iMinYear) THEN
YearResult = 1
ELSEIF VAL(DataFile.iYear) = VAL(CompareTo.iMinYear) THEN
YearResult = 2
ELSE
YearResult = 0
END IF
ELSE
YearResult = 1
END IF
IF YearResult = 2 THEN
IF NOT VAL(CompareTo.iMinMonth) = VAL(Anything) THEN
IF VAL(DataFile.iMonth) > VAL(CompareTo.iMinMonth) THEN
MonthResult = 1
ELSEIF VAL(DataFile.iMonth) = VAL(CompareTo.iMinMonth) THEN
MonthResult = 2
ELSE
MonthResult = 0
END IF
ELSE
MonthResult = 1
END IF
ELSE
MonthResult = 1
END IF
IF MonthResult = 2 THEN
IF NOT VAL(CompareTo.iMinDay) = VAL(Anything) THEN
IF VAL(DataFile.iDay) >= VAL(CompareTo.iMinDay) THEN
DayResult = 1
END IF
ELSE
DayResult = 1
END IF
ELSE
DayResult = 1
END IF
IF YearResult = 1 THEN
PassedMinTest = 1
ELSEIF YearResult = 2 THEN
IF MonthResult = 1 THEN
PassedMinTest = 1
ELSEIF MonthResult = 2 THEN
IF DayResult = 1 THEN
PassedMinTest = 1
END IF
END IF
END IF
IF PassedMinTest = 1 THEN
YearResult = 0
MonthResult = 0
DayResult = 0
IF NOT VAL(CompareTo.iMaxYear) = VAL(Anything) THEN
IF VAL(DataFile.iYear) < VAL(CompareTo.iMaxYear) THEN
YearResult = 1
ELSEIF VAL(DataFile.iYear) = VAL(CompareTo.iMaxYear) THEN
YearResult = 2
ELSE
YearResult = 0
END IF
ELSE
YearResult = 1
END IF
IF YearResult = 2 THEN
IF NOT VAL(CompareTo.iMaxMonth) = VAL(Anything) THEN
IF VAL(DataFile.iMonth) < VAL(CompareTo.iMaxMonth) THEN
MonthResult = 1
ELSEIF VAL(DataFile.iMonth) = VAL(CompareTo.iMaxMonth) THEN
MonthResult = 2
ELSE
MonthResult = 0
END IF
ELSE
MonthResult = 1
END IF
ELSE
MonthResult = 1
END IF
IF MonthResult = 2 THEN
IF NOT VAL(CompareTo.iMaxDay) = VAL(Anything) THEN
IF VAL(DataFile.iDay) <= VAL(CompareTo.iMaxDay) THEN
DayResult = 1
END IF
ELSE
DayResult = 1
END IF
ELSE
DayResult = 1
END IF
IF YearResult = 1 THEN
PassedMaxTest = 1
ELSEIF YearResult = 2 THEN
IF MonthResult = 1 THEN
PassedMaxTest = 1
ELSEIF MonthResult = 2 THEN
IF DayResult = 1 THEN
PassedMaxTest = 1
END IF
END IF
END IF
END IF
IF PassedMinTest = 1 THEN
IF PassedMaxTest = 1 THEN
DoCompares = 1
END IF
END IF
' Woah... glad that's over with...
END FUNCTION

SUB PrintFileInfo
' The title is pretty discriptive about
' what this routine does, just print
' some information about the current
' file in the DataFile var.
'
PRINT &quot; The item: '&quot;;
COLOR Clr.Highlight
PRINT FileNameRead;
COLOR Clr.Normal
PRINT &quot;' has met the search critera.&quot;: PRINT
COLOR Clr.Field: PRINT &quot; Name: &quot;;
COLOR Clr.Content: PRINT Alltrim$(DataFile.iName)
COLOR Clr.Field: PRINT &quot; Discription: &quot;;
COLOR Clr.Content
WordWrap Alltrim$(DataFile.iDiscription), 22, VAL(Anything), 70, VAL(Anything)
COLOR Clr.Field: PRINT &quot; Production Sales: &quot;;
COLOR Clr.Content: PRINT Alltrim$(DataFile.iProductionSales)
PRINT : COLOR Clr.Normal
END SUB

SUB ProcessFile (iStr AS STRING)
' Divide the current &quot;.dat&quot; file into
' seperate items that can more easly
' be worked with.
DIM Filenum AS INTEGER
DIM CurPos AS INTEGER
DIM Looper AS INTEGER
DIM CurProcess AS INTEGER
DIM Temp AS STRING
DIM Buffer AS STRING
DIM CurChr AS STRING * 1
DIM TempProcessArray(1 TO 3) AS STRING
Filenum = FREEFILE
OPEN iStr FOR INPUT AS #Filenum
LINE INPUT #Filenum, Temp
' This first line is Month, Day, Year
' all on the same line. We need to
' parse this line:
CurProcess = 0
FOR Looper = 1 TO LEN(Temp) + 1
CurChr = MID$(Temp, Looper, 1)
IF CurChr = &quot;/&quot; OR Looper = LEN(Temp) + 1 THEN
CurProcess = CurProcess + 1
TempProcessArray(CurProcess) = Buffer
Buffer = &quot;&quot;
ELSE
Buffer = Buffer + CurChr
END IF
NEXT
' We have our data in the TempProcessArray
' now, move it to the DataFile vars.
DataFile.iDay = TempProcessArray(1)
DataFile.iMonth = TempProcessArray(2)
DataFile.iYear = TempProcessArray(3)
' We now have the date information, time
' to get the time. It will also need
' parsing.
CurProcess = 0
LINE INPUT #Filenum, Temp
FOR Looper = 1 TO LEN(Temp) + 1
CurChr = MID$(Temp, Looper, 1)
IF CurChr = &quot;:&quot; OR Looper = LEN(Temp) + 1 THEN
CurProcess = CurProcess + 1
TempProcessArray(CurProcess) = Buffer
Buffer = &quot;&quot;
ELSE
Buffer = Buffer + CurChr
END IF
NEXT
' Put the time info into the DataFile
' variables.
DataFile.iHour = TempProcessArray(1)
DataFile.iMinute = TempProcessArray(2)
DataFile.iSecond = TempProcessArray(3)
' The remainder of the data is pretty
' straightforward...
LINE INPUT #Filenum, Temp
DataFile.iName = Temp
LINE INPUT #Filenum, Temp
DataFile.iDiscription = Temp
LINE INPUT #Filenum, Temp
DataFile.iProductionSales = Temp
CLOSE #Filenum
' Finished returning the data.
END SUB

SUB WordWrap (iText AS STRING, X AS INTEGER, Y AS INTEGER, X2 AS INTEGER, Y2 AS INTEGER)
DIM Looper AS INTEGER
DIM CurX AS INTEGER, CurY AS INTEGER
DIM CurChr AS STRING * 1
DIM Buffer AS STRING
CurX = X
CurY = Y
IF Y = VAL(Anything) THEN
CurY = CSRLIN
END IF
LOCATE CurY, CurX
FOR Looper = 1 TO LEN(iText) + 1
CurChr = MID$(iText, Looper, 1)
Buffer = Buffer + CurChr
IF CurChr = &quot; &quot; THEN
IF CurX + LEN(Buffer) > X2 THEN
CurX = X: CurY = CurY + 1
IF CurY >= Y2 THEN
IF NOT Y2 = VAL(Anything) THEN
EXIT FOR
END IF
END IF
END IF
IF CurY >= 24 THEN
CurY = 23
PRINT
END IF
LOCATE CurY, CurX: PRINT Buffer
CurX = CurX + LEN(Buffer)
Buffer = &quot;&quot;
ELSEIF Looper = LEN(iText) + 1 THEN
EXIT FOR
END IF
NEXT
END SUB
 
brisray, here is the DIR$() function you so long for:
[tt]
CONST farchive% = 32, fdirectory% = 16, fvolumelabel% = 8, fsystem% = 4
CONST fhidden% = 2, freadonly% = 1, fstandard% = 0
TYPE regtypex
ax AS INTEGER
bx AS INTEGER
cx AS INTEGER
dx AS INTEGER
bp AS INTEGER
si AS INTEGER
di AS INTEGER
Flags AS INTEGER
DS AS INTEGER
es AS INTEGER
END TYPE
TYPE
filetype
name AS STRING * 11
attr AS INTEGER
size AS LONG
sel AS INTEGER
END TYPE
DIM SHARED
DTA AS STRING * 44, regs AS regtypex

DEFINT A-Z
FUNCTION DIRR$ (filespec$, attr%) STATIC
regs.ax = &H1A00
regs.dx = VARPTR(DTA)
regs.DS = VARSEG(DTA)
CALL InterruptX(&H21, regs, regs)
IF LEN(filespec$) THEN
FileSpecZ$ = filespec$ + CHR$(0)
regs.ax = &H4E00
regs.cx = attr%
regs.dx = SADD(FileSpecZ$)
regs.DS = SSEG(FileSpecZ$)
ELSE
regs.ax = &H4F00
END IF
CALL
InterruptX(&H21, regs, regs)
IF regs.Flags AND 1 THEN
DIRR$ = &quot;&quot;
ELSE
DIRR$ = MID$(DTA, 31, INSTR(31, DTA, CHR$(0)) - 31)
attr% = ASC(MID$(DTA, 22, 1))
END IF
END FUNCTION

[/tt]
:) I wrote it a long time ago, so the code is a bit messy & clunky, but it works. It does, of course, require QB.QLB or QBX.QLB. Good luck!
 
Thanks for the code for the directory information. I've got to admit I rarely use interupts, peeks, pokes and some of the other goodies with QBasic, but they sometimes have their uses.

Here's a method that I've seen before and may be of interest to you. FILES in QBasic simply lists the files of a directory to the screen. You can then retrieve the displayed information (from inside a loop) using the SCREEN function. This isn't something I'd do myself, but I have seen programs that use the technique.

Ray
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top