' =============================================
' 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 ".dat" 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 = "-1"
' == 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 "C:\DATFILES\"
' 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 = "2"
CompareTo.iMaxDay = "7"
CompareTo.iMinMonth = Anything
CompareTo.iMaxMonth = "4"
CompareTo.iMinYear = Anything
CompareTo.iMaxYear = "2007"
' Assuming this is correct, we should now
' able to read and process the data.
FileNameRead = DIR$("*.dat"

DO
IF FileNameRead = "" 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 " The item: '";
COLOR Clr.Highlight
PRINT FileNameRead;
COLOR Clr.Normal
PRINT "' has met the search critera.": PRINT
COLOR Clr.Field: PRINT " Name: ";
COLOR Clr.Content: PRINT Alltrim$(DataFile.iName)
COLOR Clr.Field: PRINT " Discription: ";
COLOR Clr.Content
WordWrap Alltrim$(DataFile.iDiscription), 22, VAL(Anything), 70, VAL(Anything)
COLOR Clr.Field: PRINT " Production Sales: ";
COLOR Clr.Content: PRINT Alltrim$(DataFile.iProductionSales)
PRINT : COLOR Clr.Normal
END SUB
SUB ProcessFile (iStr AS STRING)
' Divide the current ".dat" 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 = "/" OR Looper = LEN(Temp) + 1 THEN
CurProcess = CurProcess + 1
TempProcessArray(CurProcess) = Buffer
Buffer = ""
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 = ":" OR Looper = LEN(Temp) + 1 THEN
CurProcess = CurProcess + 1
TempProcessArray(CurProcess) = Buffer
Buffer = ""
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 = " " 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 = ""
ELSEIF Looper = LEN(iText) + 1 THEN
EXIT FOR
END IF
NEXT
END SUB