Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
inline functions and ALIASES fight evil together.
#1
Ok, we'll here's the story:

One of my subs uses a truncated version of Plasma's dir2$ to create a list of files in an array from a specific directory and filename structure (like "*.txt")


Code:
SUB load.filelist (path$, spec$)
option.amount% = 0
file$ = dir2$(path$ + spec$, &H27)
DO
IF LEN(file$) = 0 THEN EXIT DO
option.amount% = option.amount% + 1
file$ = dir2$("", &H27)
LOOP
IF option.amount% THEN
REDIM option.list$(1 TO option.amount%)
file$ = dir2$(path$ + spec$, &H27)
FOR i% = 1 TO option.amount%
option.list$(i%) = path$ + file$
file$ = dir2$("", &H27)
NEXT i%
END IF
END SUB

What I'd like to do, though, is be able to use TWO "spec$"s. One of the current easiest way in QB to do this is to remove "option.amount%=0" and make two more functions like this:

Code:
SUB load.filelist1 (path$, spec$)
option.amount% = 0
load.filelist path$, spec$
END SUB

SUB load.filelist2 (path$, spec1$, spec2$)
option.amount% = 0
load.filelist path$, spec1$
load.filelist path$, spec2$
END SUB

The other way is to create another piece of code that does the same thing as most of filelist2$, except twice as much of it. That comes out to more work as the previous method, though.

SO!
Remember the COLOR command?

Quote:COLOR [foreground][,[background][,border]]

Ideally, you want to have 3 different functions that do:
"COLOR a"
"COLOR a, b"
"COLOR a, b, c"

But you CAN'T do that in the QB of today! My first (real) example is different, though, because you're just repeating the same task in slightly different ways.

So, I offer a solution. IMHO, the BEST way (in terms of both space, size, and programming time efficiency) to program the first example is like this:

Code:
INLINE SUB load.filelist (path$, spec$)
option.amount% = 0
load.filelist path$, spec$
END SUB

INLINE SUB load.filelist (path$, spec1$, spec2$)
option.amount% = 0
load.filelist path$, spec1$
load.filelist path$, spec2$
END SUB

The (non-existent) program would go through the code and change all instances of "load.filelist (path$, spec$)" to the first piece of code and all instances of "load.filelist (path$, spec1$, spec2$)" to the second piece of code.

I haven't programmed it yet. I will though. Now. It's going to take some fancy footwork..

Comments?
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)