| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Recursion |
Okay, so I have a sub randPic. It calls sub getfiles once, then calls
sub recurseDirs. recurseDirs is recursive, and also calls getfiles. (The
example code is clearer, I think.) recurseDirs steps through a branch of
the file system; getFiles collects names of images it finds. They all
use a long integer variable c that's declared in sub randPic, which
counts the files, and is also use to redim a string array fileLs()
(declared at the module level). (The whole purpose of this code is to
populate fileLs().)
The question is, besides possibly overflowing c and running out of stack
space, do I need to worry about anything? Is there a "better" way to do
this?
(I have to ask this stuff because this kind of thing is *very* unusual
for me - usually I don't need to touch the FS or recursion...)
Here's (basically) what the code looks like:
Private fileLs() As String
Public Sub randPic(folder As String)
Dim x As String, c As Long
c = -1
If Right(directory, 1) "\" Then directory =
directory & "\"
getFiles folder, c
x = Dir(folder & "*", vbDirectory)
Do Until x = ""
recurseDirs folder & x, c
x = Dir
Loop
End Sub
Private Sub recurseDirs(folder As String, c As Long)
Dim x As String
getFiles folder, c
x = Dir(folder & "*", vbDirectory)
Do Until x = ""
recurseDirs folder & x, c
x = Dir
Loop
End Sub
Private Sub getFiles(folder As String, c As Long)
Dim x As String
1 = Dir(folder & "*.bmp") 'repeat this for 4 other image formats
Do Until x = "" ' |
c = c + 1 ' |
ReDim Preserve fileLs(c) ' |
fileLs(c) = folder & x ' |
x = Dir ' |
Loop ' V
End Sub
--
auric underscore underscore at hotmail dot com
*****
Please quit mocking the lord.
---
þ RIMEGate(tm)/RGXPost V1.14 at BBSWORLD * Info{at}bbsworld.com
---
* RIMEGate(tm)V10.2áÿ* RelayNet(tm) NNTP Gateway * MoonDog BBS
* RgateImp.MoonDog.BBS at 6/5/04 9:51:12 AM
* Origin: MoonDog BBS, Brooklyn,NY, 718 692-2498, 1:278/230 (1:278/230)SEEN-BY: 633/267 270 @PATH: 278/230 10/345 106/1 2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.