Recursive Function
here is what am trying to do let say i have a directory called c:ARTISTS
thats the root in that directory there is let say 30 different artits and in those artists SOME can have more than one album those that dont have more than one album the songs are located in just the name of the artist
so if artst1 had one album all the songs would be located in c:Artistsartist1
and if artist2 had 2 albums it would be like c:artistsartist2album1 (songs for this album go here) c:artistsartist2album2 (songs for album2 go here)
so i would like someone to help me out with making a function that when given c:artist it will go into every directory and copy artist name(directory), album name( sub directory), and song names (filenames) into a table..
thank you
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Ackerman Function - Recursive Function Help Needed
I recently had to write the following function in maple known as the Ackerman function. However I need to write a function in VBA to calculate it.
The function in maple was the following.
a:=proc(n,m)
if n=0 then RETURN(m+1) fi;
if m=0 then RETURN(a(n-1,1)) fi;
RETURN(a(n-1,a(n,m-1)));
end;
The problem I am having is getting the function to stop iterating. It wont calculate a result even for simple results like T(1,1).
The code I have written in VB is as follows.
Function T(n As Integer, m As Integer)
If m = 0 Then
T(n, m) = T(n - 1, 1)
End If
If n = 0 Then
T(n, m) = m + 1
End If
T(n, m) = T(n - 1, T(n, m - 1))
End Function
Any Ideas? Is it possible
Cheers
Rich
Recursive Function
ok i need to create a recursive fuction that goes through an aray of 25 and finds the highest vallue, help?
Recursive Function
I am trying to write a simple recursive function in Visual Studio Express 2005. Any help would be greatly appriciated:
I am receiving the following error when I try to execute the below code:
Error: 61837 - Unable to write read-only property.
VB Code:
Public Function RemoveUserFromUserClasses(ByRef objUserClass As Object, ByRef objUser As Object) As Boolean On Error GoTo Err_RemoveUserFromUserClasses 'Counter Dim I As Long 'Hold the current User Class Dim objCurUserClass As Object ' For each UserClass remove the user. If objUserClass.Count > 0 Then For I = 1 To objUserClass.Count objCurUserClass = objUserClass.Item(I) objCurUserClass.Users.Remove(objUser) RemoveUserFromUserClasses(objCurUserClass.UserClasses, objUser) Next I End If Exit_RemoveUserFromUserClasses: Exit Function Err_RemoveUserFromUserClasses: If fLogFileOpen Then PrintLine(intLogFileNumber, Str(Now.ToOADate) & ": * * * RemoveUserFromUserClasses Error: " & Err.Number & " - " & Err.Description) End If Resume Exit_RemoveUserFromUserClasses End Function
Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack
Recursive Function Help
Last night I spent forever trying to figure out how to do this. Could somebody tell me how to get started, maybe provide some example code?
Thanks
Recursive Function
Urgent!! I wrote a recursive function. This recursive function will start when I click on the 'Start' button. I need to stop this recursive function when I click on the 'Stop' button, but the 'Stop' button only responce after the recursive function finish, how can I always listen to the 'Stop' button event so I can terminate the recursive function any time as I want? Thanks.
Recursive VB Function?
Hi all,
I am looking for a recursive function to step through a tree like structure. What make this difficult is that each child node in the tree only knows if it has a child. It does not know about its parent. My problem is that I can recurse through the tree, moveing to each child nodes child, but I can not return to the previous levels. I do not know how many level deep I need to go, so it must be recursive.
Below is a typical tree structure I will need to recurse. I start at A, then I can get to ABC1. But how to I return to AB1 and continue the process? As you can see, the tree can be many levels deep and I only know if the node has a child and how to get to that child.
A
l
A1------->A1.1
l l
A2 AB1-------->AB1.1
l l l
A3 l ABC1
l AB2----------------------->AB2.1
A4 l l
l AB3 D1---------------->D1.1
A5 l l
l D2 F1
A6------->A6.1 l
l F2
B1---------->B1.1----------->C1
l l
B2.1 C2
l
B3.1
Thanks
Edited by - skyodyssey on 7/30/2004 12:12:31 PM
Problem With Recursive Function
Hi
I have a problem with the following code:
VB Code:
Private scanData() As String Private Sub Form_Load()List1.AddItem "c:My Documents"List1.AddItem "e:"End Sub Private Sub Command1_Click()scanfolders3End Sub Public Sub scanfolders3()Dim startTime, elapTime As DoubleDim startFolder As StringDim scanResult As BooleanscanResult = FalseForm1.MousePointer = vbHourglassstartTime = CDbl(Timer)ReDim scanData(4, 0)startFolder = List1.TextscanResult = scanFolders(startFolder)elapTime = CDbl(Timer) - startTimeForm1.MousePointer = vbNormalText1.Text = elapTimeEnd Sub Public Function scanFolders(fpath As String) As BooleanDim x As DoubleSet fso = CreateObject("Scripting.FileSystemObject") For Each fl In fso.GetFolder(fpath).Files x = UBound(scanData, 2) + 1 ReDim Preserve scanData(4, x) scanData(0, x) = fl.Name scanData(1, x) = fpath scanData(2, x) = fl.Size scanData(3, x) = fl.Type DoEvents x = x + 1 Next fl For Each fldr In fso.GetFolder(fpath).SubFolders scanFolders fldr.Path Next fldrSet fso = NothingSet fldr = NothingSet fl = NothingscanFolders = TrueEnd Function
The main aim of the code is to populate an array with the details of files in a given directory. The form has been added to assess the performance for various drives/directories.
The problem is that subsequent runs of the code take relatively longer each time. Given that "e:" is a 512mb pendrive with about 300mb used and that "c:My Documents" contains about 4GB typical results with times in seconds are:
e: 4.56
e: 4.63
e: 4.45
c:My Documents 17.68
e: 18.11
c:My Documents 86.45
e: 77.5
I can't see where the resources are leaking or what is causing this build up after the larger directory is scanned.
Things I've tried are:
1. Not using Preserve - although this wouldn't work as needed anyway it was no quicker.
2. Commenting out DoEvents - Didn't help
Any ideas?
Thanks
Mouse
Making A Recursive Function
Hi, I need help making a recursive function for the code listed
below.
I posted here previously for solution to listing all subkeys
and values of a registry key. I got the code to do it, but
it only lists on level, so it needs to be put in a recursive
function in order to go through the entire branch.
I've tried to do this but I never worked with recursion before
and I can't get it to work.
I just need to add all the keys and values to a list in this
format:
Key
if it is a key or if it is a value:
Key,value=data
This code does that all but only one step. Can someone
help me with this, it is a one minute job for someone who
worked with recursion before. Thanks in advance.
VB Code:
Const ERROR_NO_MORE_ITEMS = 259&Const HKEY_CURRENT_CONFIG = &H80000005Const HKEY_LOCAL_MACHINE = &H80000002Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As LongPrivate Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As LongPrivate Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As LongPrivate Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As LongPrivate Sub Form_Load() Dim hKey As Long, Cnt As Long, sName As String, sData As String, Ret As Long, RetData As Long Const BUFFER_SIZE As Long = 255 'Set the forms graphics mode to persistent Me.AutoRedraw = True Me.Print "RegEnumKeyEx" Ret = BUFFER_SIZE 'Open the registry key If RegOpenKey(HKEY_LOCAL_MACHINE, "Hardware", hKey) = 0 Then 'Create a buffer sName = Space(BUFFER_SIZE) 'Enumerate the keys While RegEnumKeyEx(hKey, Cnt, sName, Ret, ByVal 0&, vbNullString, ByVal 0&, ByVal 0& ) <> ERROR_NO_MORE_ITEMS 'Show the enumerated key Me.Print " " + Left$(sName, Ret) 'prepare for the next key Cnt = Cnt + 1 sName = Space(BUFFER_SIZE) Ret = BUFFER_SIZE Wend 'close the registry key RegCloseKey hKey Else Me.Print " Error while calling RegOpenKey" End If 'This part below lists the values and their data of selected key Me.Print vbCrLf + "RegEnumValue" Cnt = 0 'Open a registry key If RegOpenKey(HKEY_LOCAL_MACHINE, "SoftwareMicrosoftWindowsCurrentVersion", hKey) = 0 Then 'initialize sName = Space(BUFFER_SIZE) sData = Space(BUFFER_SIZE) Ret = BUFFER_SIZE RetData = BUFFER_SIZE 'enumerate the values While RegEnumValue(hKey, Cnt, sName, Ret, 0, ByVal 0&, ByVal sData, RetData) <> ERROR_NO_MORE_ITEMS 'show data If RetData > 0 Then Me.Print " " + Left$(sName, Ret) + "=" + Left$(sData, RetData - 1) 'prepare for next value Cnt = Cnt + 1 sName = Space(BUFFER_SIZE) sData = Space(BUFFER_SIZE) Ret = BUFFER_SIZE RetData = BUFFER_SIZE Wend 'Close the registry key RegCloseKey hKey Else Me.Print " Error while calling RegOpenKey" End IfEnd Sub
How To Write A Recursive Function?
Hi,
I'm trying to write a recursive function but in vain... thus i sincerely hope you could help me... Actually my purpose of this recursive search is to search for all children, grandchildren, great grandchildren...etc of a particular record. Suppose in my table, I have two fields, Parent and Child.
For example,
Parent Child
===== ====
May - John
Jess - Mike
Jess - Nick
John - Peter
John - Jess
John - Watson
Peter - Carrie
........ etc
Suppose I start with a name John. My aim is to 1st search thru the parent field for all records with parent, John. In this case, the records will be those of children Peter, Jess, and Watson.
For each of these children, I will search thru the table again, for their children (aka John's grandchildren)..
Thus I need a recursive method to traverse thru the records.
Can anyone help?
Thank you very very much.
Recursive Function Calls
In order to generate a unique number I wrote the following simple Function. It fails to do the job because there is no recursive Function call. However, using an analogous Subroutine works because the desired recursive call to the Sub _does_ happen.
Is this a VB feature, and, if so, why?
Public gcollUniqNum as New Collection
Public glUniqNum as Long
Public Function UniqueNum() As Long
Dim lNum As Long
lNum = GenRan(1)
If InColl(gcollUniqNum, CStr(lNum)) = True Then
'NO recursive call to UniqueKey.
'Function exited with UniqueKey = 0
lNum = UniqueKey
Else
gcollUniqNum.Add lNum, CStr(lNum)
UniqueNum = lNum
End If
End Function
Public Sub GenerateUniqueNumber()
Dim lNum As Long
lNum = GenRan(1)
If InColl(gcollUniqNum, CStr(lNum)) = True Then
'DOES result in recursive call
GenerateUniqueNumber
Else
gcollUniqNum.Add lNum, CStr(lNum)
glUniqNum = lNum
End If
End Sub
Public Function InCollection(collDesignated As Collection, Key As String) As Boolean
On Error GoTo NotThere
'VB generates a run-time error if Key is not in collDesignated
If collDesignated.Item(Key) <> "" Then
InCollection = True
Exit Function
End If
NotThere:
End Function
Need Help With Treeview Vb6 Recursive Function
Hi ,
What I am trying to achieve is the ability to limit the checked nodes to 1 only.
Within the London's node there are 2 children (show1,show2) only one perfomance can be checked
In my attempt I set all to false and then the selected one to true.But i m failing to recursely loop.
Can you help?
Scenario
Country
City
London
show 1
Cinderella 20/06/06 performance
Cinderella 21/06/06 performance
show 2
Phantom 20/06/06 performance
Phantom 21/06/06 performance
My failed attempt
Code:
Private Sub ValidateNodes(ByVal ndParent As MSComctlLib.Node)
dim oChild as MSComctlLib.Node
Set oChild = ndParent .Child
For iIndex = 0 To ndParent .Children - 1
oChild.Checked =false
Set oChild = oChild.Next
Next
tvw.SelectedItem.Checked=true
End Sub
Thanks in advance
Recursive Function In Formula Not Working?
I am trying to use a recursive function to return the number of levels for a specific parent but once I put the function in an equation it doesn't work. I receive a "ByRef Argument type mismatch error" for Level(Temp) which is fine when on a stand alone line.
Code:
Function Level(Parent As String) As Integer
Dim Temp As Variant
Temp = DLookup("[Component]", "TestData", "[ItemNo] = '" & Parent & "'")
If IsNull(Temp) Then
MsgBox ("Found NULL")
Level = 1
Debug.Print "ItemNo Component", "Level"
Debug.Print Parent; " "; Temp; " "; Level; Chr$(13)
'Done
Else
MsgBox ("Found ItemNo")
Debug.Print "ItemNo Component", "Level"
Debug.Print Parent; " "; Temp; " "; Level; Chr$(13)
'**** This Works Fine
Level (Temp)
'**** This Doesn't Work, Why?
'Level = Level + Level(Temp)
End If
End Function
Any help would be appreciated. Thanks.
Recursive File List Function
I have a function that will return any files in a given folder. But in order to make it also return files in subfolders, i was told i would have to make it recursive. Recursive functions are something ive never had to use yet...and quite frankly i dont understand them. Could someone tell me what modifications i would have to make to this function to make it return subfolder files as well?
VB Code:
Function DirList(strDir As String) As String() 'returns a 0 based array with the files in strDir 'Can contain a pattern such as "*.*" Dim Count As Integer Dim sFiles() As String Dim sFile As String sFile = Dir$(strDir) Count = -1 Do Count = Count + 1 ReDim Preserve sFiles(Count) sFiles(Count) = sFile sFile = Dir$ Loop DirList = sFilesEnd Function
thanks,
Nishant
Fully Kill Recursive Function
Hi all,
I have a bit of a problem with a recursive function. Basically what the function does is search for files, I used some code from an FAQ or post here on vbcity and it works very well. Below is the definition, you may know the funciton i mean from it.
Code:
Function GetAllFiles(ByVal path As String, ByVal filespec As String, _
Optional RecurseDirs As Boolean) As Collection
Basically in my program you click a button on the main form and a dialog box pops up, with a listview and 2 buttons on it. You then choose to browse for a file (common dialog box etc...) or search for a file. The search for a file button opens another dialog box with a listview and search buttons and you type your search in and then the search begins. It prints any matching files into a listview. You then select which files you want and click another button, which adds the selected items to the first dialog box's listview. You can click OK and the dialog will close and you will see all the files you picked. This works fine.
The problem occurs when you dont wait for the search to end. There are DoEvents commands in parts of the recursive search function so the listview will show a file as it is found. This also means you can select it and add it whilst the search is still running (which is good, i want this). However you can also click ok and go back to see the files you've selected, but the search is still running. If you quit the program, it will still remain in task manager. I want the search to stop the minute OK is clicked (the only code for ok at the moment is unload me). Any ideas how you can do this, if at all?
One other thing, if I click ok whilst a search is running, and the dialog closes, and then I click search again to open the dialog back up, it will display any matches it finds as the previous search runs (ie ones that were not shown before, new ones that the halfway through search finds)
All help much appreciated
Dan
Calling A Recursive Function/sub From Itself Sends Nothing
first :thank you delcom5 for your reply.
i built a recursive function (tried calling it a sub as well - same problem)
that should builds nodes from DB to be added to a treeview.
and when i call the function from itself the node is sent as nothing (i do add byval of course).
don't have a clue why this shold happen, other parameters are sent just fine.
Recursive Function Fails To Return The Correct Value
Hi,
I'm fairly new to VB. Just tried to implement a recursive function with Tree Class. The function is as follow:
Code:
Private Function bTreeSearch(ByRef tmpx As Node, _
ByVal result As Integer, _
ByVal expr As String) As Boolean
Dim isFound As Boolean
If (tmpx Is Nothing) Then
isFound = False
Else
isFound = (tmpx.result = result)
If Not isFound Then
If result < tmpx.result Then
bTreeSearch tmpx.Left, result, expr
Else
bTreeSearch tmpx.Right, result, expr
End If
End If
End If
bTreeSearch = isFound
End Function
When I ran through debug mode, I found out that when the function found the node with the same result and set isFound = True, on the way returning to the stack, ie. back to its previous copy, where isFound is False, it returns FALSE as the value of the first copy of the function rather then TRUE value of the second copy - I hope you understand what I am talking about.
My question is, how to make this recursive function to return the TRUE value (from the second copy of the function) as the function rolls back on the stack?
(still N00b) Recursive Function Doesn't Work
Hi,
For some obscure reason an recursive function I build doesn't work:
Code:
Public Function D()
Dim TD As Integer
Dim XD As Integer
XD = 0
TD = D10
If TD = 10 Then
XD = TD + D
Else
XD = TD
End If
D = XD
End Function
D10 is a function that gives a random number between 1 and 10
What it must do is:
When D10 results in 10, then another D10 must be added:
If TD = 10 Then XD = TD + D
but for some reason VB doesn't 'step into' D and just gives the result '0'
At first I used If TD = 10 Then D = TD + D, which is shorter, but same result.
Any clue anyone?
Problem With Recursive Function To Build XML Dom Tree
I have the following recursive function
Private xmldoc As DOMDocument30
Private Sub BuildTree(ByRef parentElement As IXMLDOMElement)
Dim aElement as IXMLDOMElement
...
Set aElement = xmldoc.createElement("something")
parentElement.appendChild aElement
...
BuildTree aElement
...
End Sub
Running the code results in: "Compile error: ByRef argument type mismatch"
Could anybody help identify the problem and suggest a solution for it?
Search File In Folder An Recursive Folder With Dir Function
Hi,
I want to search ActiveX .dll in a expecific folder and in all his recursive folders.
I´ve made a recursive function using dir statement. But dir returns error when it finish in one folder and I want that dir function search in the recursive folders too.
This is my code:
Private Sub search(sFolder As String)
Dim sName As String
sName = Dir(sFolder & "", vbDirectory) ' Retrieve the first entry.
Do While sName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If sName <> "." And sName <> ".." Then
' Use bitwise comparison to make sure sName is a directory.
If (GetAttr(sFolder & "" & sName) And vbDirectory) = vbDirectory Then
' sName is a directory.
Debug.Print sFolder & "" & sName ' Display entry only if it
search sFolder & "" & sName
ElseIf LCase$(Right$(sName, 3)) = "dll" Then
' sNAme is a ActiveX.dll
Debug.Print sFolder & "" & sName
End If
End If
sName = Dir ' Get next entry. <= Here happens an error when the function end searching in 1 recursive folder
Debug.Print sName
Loop
End Sub
What can I do????
Thanks and regards
Tel
Recursive Function &"out Of Bounds Error&"
I got that function from here but I get ann error "subscript out of range" what`s up with that ??
'recursive folder adding
Public Sub ProcessFiles(d As String)
Playlist.files.AddItem Playlist.files.ListCount + 1 & ". " & d
End Sub
Public Sub ProcessDir(strDir As String)
Dim i
Dim iCount As Integer
Dim Result As String
Dim FileList() As String
iCount = 0
Result = Dir(strDir & "*.*", vbDirectory)
Do While Result <> "" ' Start the loop.
If Result <> "." And Result <> ".." Then
iCount = iCount + 1
ReDim Preserve FileList(1 To iCount)
FileList(iCount) = strDir & "" & Result
End If
Result = Dir
Loop
For i = 1 To UBound(FileList)
If (GetAttr(FileList(i)) And vbDirectory) = vbDirectory Then
ProcessDir (FileList(i))
Else
ProcessFiles (FileList(i))
End If ' it represents a directory.
Next
End Sub
Non-recursive Into Recursive
I am going to start to wrok on a project that converts a non-recursive procedure into a recursive one and the opposite.
Any ideas, links ,books ref, anything that would help ?
I could use either pseudocode,vb,c++, or any other stuff .
Thanx in advance
Recursive Help
Does anyone have any examples on how to use recursion or any tutorials. Thanks
Recursive SQL
Hi,
I want to know how to create a recursive SQL in MS-SQL Server 6.5. The table contains PATH_ID, PATH_NM, PARENT_ID as columns.
The row look like this
PATH_ID PATH_NAME PARENT_ID
1 C: 0
2 WINNT 1
3 SYSTEM32 2
If i give 3 ie PATH_ID, then the query should me the output as follows C:WINNTSYSTEM332
Your help is much appreciated
FTP Recursive Properties
Hi, I'm using API calls to wininet.dll to connect to a FTP server, creating an effective FTP Client. The one thing I can't seem to find any information on is how to get Recursive properties from a file. You know, stuff like 0644 and 0777. File permissions, I guess. I've searched around, and there's either no information or I don't know what the correct term for it is. Anybody know how to get these numbers?
Recursive Use Of Forms
Is there a way to use the same form more than once at the same time?
EXAMPLE:
A VB Project has two forms: Form A and Form B.
Form A has a listview control that lists a bunch of items.
Form B is the editor for the items in which you can add and update items.
The double click event on the listview on Form A calls the public LoadItem() function on Form B and then makes Form B visible. (Because I encountered some errors in the past, I actually unload form B from Form A first before calling the public LoadItem() function on Form B.)
User can then edit the item on Form B and click save to update the DB.
Then Form B is unloaded and that brings us back to form A.
Another scenario is the user double clicks the listview in Form A which again brings up the item in Form B. Then the user double clicks on another listview item. This then reloads Form B with the most recent item selected in the listview on Form A.
Using this logic, I can only have one item (Form B) at a time. I would like to be able to allow users to open multiple items at a time (one Form A that spawns many Form Bs)
Is that possible?
Otherwise,
My initial thought is to just re-create the form a few time and impose a finite limit (N) on the number of items that can be simultaneously opened where N= the number of replicated forms in my VB project. Of course this would alos mean a little extra logic to see which is the lowest numbered Form B available.
So I would then have FormB_1, FormB_2, FormB_3,...etc
Recursive Sub Times Out
While the code is ASP.NET, I suspect the problem is not strictly a .NET issue. As I didn't get any response in the XML forum on the .NET sister site, I'm trying here.
Can anyone tell me why this code is timing out? I assume it has something to do with the ShowTree subprocedure, but I don't see exactly what that could be. I copied most of the code out of a book Sams Teach Yourself ASP.NET in 21 Days, 2nd Ed.
Code:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server">
Dim i As Integer
Dim strOutput As String = ""
Sub Page_Load (Sender As Object, e As EventArgs)
Dim xmlDoc As New XMLDocument()
Try
xmlDoc.Load(Server.MapPath("servers.xml"))
ShowTree(xmlDoc.DocumentElement)
Catch ex As Exception
strOutput = "Error accessing XML file"
End Try
lblOutput.Text = strOutput
End Sub
Sub ShowTree (node As XMLNode)
Dim attrnode As XmlNode
Dim map As XmlNamedNodeMap
If Not(node.HasChildNodes)
strOutput += " <b>" & node.Name & "</b> <" & _
node.Value & "><br>" & vbCrLf
Else
strOutput += "<b>" & node.Name & "</b>"
If node.NodeType = XmlNodeType.Element Then
map = node.Attributes
For Each attrnode In map
strOutput += " <b>" & attrnode.Name & "</b> <" & _
attrnode.Value & ">" & vbCrLf
Next
End If
strOutput += "<br>"
End If
If node.HasChildNodes Then
node = node.FirstChild
While Not IsNothing(node)
ShowTree(node)
node = node.NextSibling
End While
End If
End Sub
</script>
<html>
<head>
<title>Dark Age of Camelot : Servers Status</title>
</head>
<body>
<asp:label id="lblOutput" runat="server" />
</body>
</html>
Getting Permutations, Recursive?
Hello, nice forum, I registered a year or so back but forgot all my details so rejoined.
I dont do much coding and have hit a problem which is beyond my grasp and am requesting help.
I need something to output every permutation of a variable set of inputs. Let me give some examples of the inputs.
4-6N 1-3A 5-6A
This means 4 to six A's, followed by 1 to 3 N's, followed by 5 to 6 A's.
I could also have any number of input chunks.
So, 5-5A 2-3N 3-3N 1-3N 3-3A is also a valid input.
I have prepared this input by putting the information into a collection of collections. So if we take the first example input, 4-6N 1-3A 5-6A, I have a 3 element collection of collections, the sub collections containing:
in collection 1:
AAAA
AAAAA
AAAAAA
in collection 2:
N
NN
NNN
in collection 3:
AAAAA
AAAAAA
So. From there I want to output every permutation of the above into another collection, thats where my puny mind breaks down. I suspect it requires some sort of recursive sub routine which moniters the positions in the sub collections and header collection but I just cant work it out. Help?
Recursive Error
I'm trying to make a recursive procedure that will list all files in a folder (including its subfolders). The dir function returns an error .... It seems that it loose its argument...
Code:
Private Sub listFile(inPath As String)
Dim fn As String
fn = Dir(inPath, vbDirectory)
While fn <> ""
If fn <> "." And fn <> ".." Then
If GetAttr(inPath & fn) = vbDirectory Then
listFile (inPath & fn & "")
Else
Debug.Print fn
End If
End If
fn = Dir 'Invalid procedure call or argument
Wend
End Sub
Help Please With Recursive Functions
I'm trying to learn Visual Basic and have this project to complete, Can someone help please?
I have an algorithm for the function called Mystery and the recursive function Search which is called by Mystery:
Mystery(N)
Output The answer is: Search(1, N, N)
END of Mystery
Search(First, Last, N)
Output “First = “, First, “Last = “, Last
Mid = (First + Last) DIV 2
IF (Mid * Mid <= N) AND (N < (Mid + 1) * (Mid + 1)) THEN
ReturnValue Mid
ELSE
IF Mid * Mid> N THEN
ReturnValue = Search(First, Mid - 1, N)
ELSE
Return Value = Search(Mid + 1, Last, N)
END IF
END IF
Search = ReturnValue
END Search
I have to work out the exact output when the function is called with Mystery(9) and Mystery(15). I thought the easiest way was to write the function as a VB program, but I'm haivng trouble with that, I'm just not sure where to start and then how to find theoutput with regard with the Mystery(9) and Mystery(15) input.
Anyone help plz? Much appreciated.
Recursive Scan
G'day!
Does anybody know how I could list all files from a directory and its subdirectories in a ListBox, and all the directories and subdirectories to another (one listbox contains all files and their paths, the other one only the folders)?
Thanks!
Iterative > Recursive
In this thread, BillSoo states that "A key concept in recursion is that any recursive function can be rewritten as an iterative function and likewise any iterative function can be written recursively.".
I am attempting to write a recursive function that will cycle through all possible permutations of a set of comboboxes. That is: I have a webpage with 4 comboboxes. Each combobox has N number of possible selections. I would like to, sequentially, select each and every possible combination and submit the form.
I have written an iterative function that works (below). However, I cannot seem to grasp how to convert this into a recursive function. I have searched here and elsewhere (as evidenced by my thread reference), but have not yet found a solution. Any ideas?
(I'm writing this in Segue's SilkPerformer. It's an automated performance test tool that uses a pseduo basic language. sPageData is the source from the entire webpage. The sub-functions parse the source data and return strings, numbers, etc.)
Code:
function fncLoop(sPageData:string)
var
nCB1:number;
nCB2:number;
nCB3:number;
nCB4:number;
sCB1:string;
sCB2:string;
sCB3:string;
sCB4:string;
sCB1S:string;
sCB2S:string;
sCB3S:string;
sCB4S:string;
begin
sCB1 := fncComboboxName(sPageData, 1);
sCB2 := fncComboboxName(sPageData, 2);
sCB3 := fncComboboxName(sPageData, 3);
sCB4 := fncComboboxName(sPageData, 4);
for nCB1 := 1 to fncNumberOfComboboxSelections(sPageData, sCB1) do
for nCB2 := 1 to fncNumberOfComboboxSelections(sPageData, sCB2) do
for nCB3 := 1 to fncNumberOfComboboxSelections(sPageData, sCB3) do
for nCB4 := 1 to fncNumberOfComboboxSelections(sPageData, sCB4) do
sCB1S := fncComboboxSelectionName(sPageData, sCB1, nCB1);
sCB2S := fncComboboxSelectionName(sPageData, sCB2, nCB2);
sCB3S := fncComboboxSelectionName(sPageData, sCB3, nCB3);
sCB4S := fncComboboxSelectionName(sPageData, sCB4, nCB4);
SubmitForm(sCB1S, sCB2S, sCB3S, sCB4S);
end;
end;
end;
end;
end fncLoop;
Recursive Programming
Hello. I am kinda in a bind right now and I was wondering if any of you out there might be able to help me.
I am writing a FloodFill function for Lord Helmut's (yes, that guy) Level Editor. The current one he has just replaces every tile in the level with the selected tile. I am trying to write a true fill function. Here is the code I have so far.
Code:
Private Function FloodFill2(ByVal fillX As Integer, ByVal fillY As Integer, ByVal tileX As Byte, ByVal tileY As Byte, ByVal targetTileX As Byte, ByVal targetTileY As Byte) As Boolean
If (Map(fillX, fillY).tileX <> targetTileX) And (Map(fillX, fillY).tileY <> targetTileY) Then Exit Function
Map(fillX, fillY).tileX = tileX
Map(fillX, fillY).tileY = tileY
If fillX > 0 Then Call FloodFill2(fillX - 1, fillY, tileX, tileY, targetTileX, targetTileY)
If fillX < 63 Then Call FloodFill2(fillX + 1, fillY, tileX, tileY, targetTileX, targetTileY)
If fillY > 0 Then Call FloodFill2(fillX, fillY - 1, tileX, tileY, targetTileX, targetTileY)
If fillY < 63 Then Call FloodFill2(fillX, fillY + 1, tileX, tileY, targetTileX, targetTileY)
FloodFill2 = True
End Function
What I do is check if the tile can filled. If it cannot, I exit the function. If it can, I fill it, then call the function again, this time at different coordinates.
This function works fine in C, but when ran in VB, I get an "Out of Stack Space" message.
Is there any way that I can get a function to call itself many times? Recursive programming hates me X_X
Recursive Mishap
I am designing an application to search and compare 2 text files. To do so, I am creating a recursive function that passes 2 text streams as its parameters (one for each text file). My problem happens when I set a temp variable within the function to the value of the param. I want to be able to set the temp var equal to a new occurence of the text stream. The way I have it setup now, it is only pointing my temp to the param. This throws off the whole function because the idea is to change the temp without affecting the param. I know this sounds confusing, but I have added some of the code below to clarify a little. Does anyone know how to create a new instance of a text stream (my temp var) without having it point to the original?
Private Sub Process(tsA As Scripting.TextStream, _
tsB As Scripting.TextStream)
Dim tempA As Scripting.TextStream
Dim tempB As Scripting.TextStream
Dim textA As String, textB As String
tempA = tsA <-- error: pointing to tsA/ tsB instead of
tempB = tsB <-- creating a new instance
textA = tempA.ReadLine
textB = tempB.ReadLine
Recursive Subroutine
Hello everyone! I'm in a bit of a bind. I hate recursive logic and I am not very good at it. For the most part I think I can do what I want in this case, except for a file access issue.
Here's what I want to do, in psuedocode:
Code:
Private Sub File_Trace (Filename as String)
Open a LST file 'initial is specified by the user
while not EOF
Read in a new filename
If file extension is LST
add filename to a tree
Call File_Trace (filename)
else
insert filename into a list box
end if
loop
close file
End Sub
The thing I am worried about is the file I/O numbers, and being able to correctly set the heirarchy of the files (this file goes under that one...). The tree portion I think I can manage, but what are your thoughts on the file access?
Thanks for looking at it.
Recursive Programming
can anyone help me with recursive proggin in visual basic, im seriously desperate cuz my book doesnt go over it to well and my boss wants me to make an app to test my skill on it
Recursive Renaming
Hey
What I wanted to do was make an application that would allow you to enter a directory (the root DIR of your music folder) and have the program go through all the files, and captilize the first letter of every word in the file's name.
NewFileName = StrConv(FileName, vbProperCase)
Name FileName As NewFileName
will rename it for me, and it works perfectly... however, I don't know how to loop through a folder and apply that line of code to every file found within...
Can anybody point me in the right direction?
Thanks in advance.
SQL Recursive Call?
The below table is a table of employees titled "tblPeople". The "B" column represents who that person's boss is (from the exact same table) with an integer code of that person's ID.
OK stay with me here, as shown in the below table both Bill Smith and Don Walton's boss is Bob Davis (whose boss is Ed Harris (who does not have a boss.))
Code:
IDLASTFIRSTB
1SmithBill4
2WaltonDon4
3HarrisEd0
4DavisBob3
My question is this: Is there an SQL statement that will allow you to extract the people into a Recordset who have bosses (B>0) and list both their name and their bosses name?
So, the desired outcome would be:
Code:
SmithBillDavis Bob
WaltonDonDavis Bob
DavisBobHarris Ed
...meaning that I could us something like RST.Fields("tblPeople.Last") to print column#1 and RST.Fields("tblPeopleAlias.Last") to print column#3
I know that "SELECT * FROM [tblPeople] WHERE [b]=4" would give you:
Code:
SmithBill4
WaltonDon4
.... but I don't want just a "4" -- I want to get the boss's entire name (*without* having to refer to a secondary recordset)
Thanks in advance,
Recursive Database
i have a table with item information and an ID for each ITEM. Some item have parents. some parents have parents to
I want to search an item through all the item and its parent. the table Parent (Child, Parent)
I'm using ms Access .mdb table with data environment and connection.
how can i search through all the parents ? somebody can help me with code, links or anything please ?
thanx in advance.
Stauf's Game Isn't Over
Recursive Query ?
Guys,
I am a bit of a db newbie so here goes:
I need to perform a query on a table, then depending upon the results of this query (ie user choice), perform another query on the results of the first...
How is this best accomplished ? I understand I cannot query directly a recordset results, so would it be a case of a temporary table ?
Any advice seriously appreciated
Recursive Floodfill
Dear Expert
I am trying to find the area recltangle a point or maker within and image covers, useing a recursive floodfill Can anyone help.
tom
Recursive Combinations [please Help]
How do I make the code below recursive? I'm trying to create all combination of the array. This gives all combinations where the length is exactly 5. I want it to give all combinatoin where the length is 1 to the ubound of array s. So for a length of 3 there would be 3 nested loops, for length of 8 there would be 8 nested loops and so on.
Ultimately what I want to accomplish is to have an array filled with numbers and find the sum of every possible combination and pick the combination that has a sum that is closet to a target number without going under, but I thought I'd start here first.
VB Code:
Sub CreateCombos() Dim s(8) s(1) = "A" s(2) = "B" s(3) = "C" s(4) = "D" s(5) = "E" s(6) = "F" s(7) = "G" s(8) = "H" lLen = 5 For i1 = 1 To (UBound(s) - lLen) + 1 For i2 = i1 + 1 To (UBound(s) - lLen) + 2 For i3 = i2 + 1 To (UBound(s) - lLen) + 3 For i4 = i3 + 1 To (UBound(s) - lLen) + 4 For i5 = i4 + 1 To (UBound(s) - lLen) + 5 Debug.Print s(i1) & s(i2) & s(i3) & s(i4) & s(i5) Next i5 Next i4 Next i3 Next i2 Next i1 End Sub
Any help?
Recursive Sub... Im No Good At Em!
Basically I need this to be recursive... so
Start a folder "A" that is passed in...
and loop through all Mailitems.. then do the same for each subfolder
this will get 1st level of subfolders..
VB Code:
Private Sub PrintSubjects(oFLD As Outlook.MAPIFolder)For z = 1 To oFLD.Folders.Count Set ssFld = oFLD.Folders(z) For x = 1 To ssFld.Items.Count If TypeOf ssFld.Items(x) Is MailItem Then Set oMail = ssFld.Items(x) Debug.Print ssFld.Name & ": " & oMail.Subject End If NextNextEnd Sub
thanks!
Recursive Filling
Making good progress with my map editor, but I've hit a bit of a hurdle.
I want to include a tool that will fill an area of the map with a particular tile (ie. as in arrays, not bitmaps). I already have a recursive function for doing so, which works with small areas and maps. However, my program allows for huge maps - as big as 999 x 999 tiles even - and so on these larger maps I run out of stack space.
Anyone have any ideas how I can rewrite the function, so I don't run out of stack space?
Recursive Loop
I have written a program which runs a recursive loop. I have used sleep to let it sleep for 5 minutes. What it does is it checks another program state and changes it if it is not in the desired state. It does this every 5 minutes. Program works fine except when the computer goes into stand by mode. It doesn't work after that. I have to kill the process and start it again. Can any one help me with this? Also, is there any way I can change the program such that I don't have to use recursive loop but still have the purpose of checking the state of the other program after every 5 minutes.
Recursive Sorting
I need help with some ideas about recursion please. I have been asked to create a football league program. someone said that because of the leagues, team positions, goal differences, scores etc they said that repeated sorting would be needed, like recursion.
It is fairly easy to handle sorting the teams by the "points", based upon the games won, lost etc but I am not quite sure how to handle successive sorting ie
sorting on points AND goal diff
then by
points AND goals for
etc etc
can anyone please suggest a technique for this type of successive sorting based upon multiple data columns etc
Recursive Problem
I want to search number and if I go to the number 6 than it return something that I will know that I got 6. Here is the code if you doesn't understand me. It only need something something at the line in comment...How can I leave the function or return something that will told me that I have pass there?
VB Code:
Option ExplicitConst MIN = 0Const MAX = 8Const OUT = 6 Private Sub Form_Load()Text1.Text = ""Facto (MIN)End Sub Public Function Facto(i As Integer) As IntegerIf (i = MAX) Then Facto = MAXElseIf i = OUT Then 'STOP ALL and leave the function |||||!!!!!||||!!!!!|| Else Facto = (i + Facto(i + 1)) Text1.Text = Text1.Text & iEnd If End Function
Recursive Sub Dirs Using Dir()
hello all.
ive done a search on this one and come up with various results but nothing solid. most of them are using the api, i just want to write a simple recursive function to retrieve all subdirs and their subdirs etc and return their paths in a string array, thats all....
only problem is that you cant use the Dir() function in a recursive...
i also dont want to use the filesytemobject as its way too much overhead...
any advice would be lovely..
|