I have a loop that adds rows to a listview. If while loading we run out of memory i have an error trap that displays an appropriate message. I also have an Exit function statement following it but the code refuses to exit at that point, insteda the code loops round various areas in the same function another twice before finally exiting and in doing so causes the errortrap to be called an extra twice. Why is it doing this and how d i get it to exit the function immediately after i get the error? Thanks
There are 3 types of people in this world.........those that can count, and those that can't.
Yep heres the code If had to post it as an attachment as its over 1000 characters
Out of memory error comes up 3 times even tho ive said 'exit function' the program refuses to, presumably because it has to tidy up the loop gracefully.
Altho Im testing for error message 17, its actually 7 for an out of memory but i set it to 17 just to test the else leg of the If
There are 3 types of people in this world.........those that can count, and those that can't.
Moreover you are recursively calling the loadfile function which can be the source of the problem. Recursive functions call themselves as long as they do not match some terminating condition. If the function is getting executed more than once it probably is encountering the same error and thats why you are getting more than one error message boxes. Try and debug your code line by line and it will take you to the solution.
PS: try and name your variables with proper naming convention. For instance you declared variable "MaxFileSize" as currency type. How in the hell am i suppose the understand the data type and scope of the variable by just looking at it ????
Originally posted by Blobby I have a loop that adds rows to a listview. If while loading we run out of memory i have an error trap that displays an appropriate message. I also have an Exit function statement following it but the code refuses to exit at that point, insteda the code loops round various areas in the same function another twice before finally exiting and in doing so causes the errortrap to be called an extra twice. Why is it doing this and how d i get it to exit the function immediately after i get the error? Thanks
Thats why your code does not exit the function cause you are calling it recursively .....
VB Code:
If fName = "." Or fName = ".." Then
'do nothing
Else
If (WFD.dwFileAttributes And vbDirectory) = vbDirectory Then
If Right(UCase(fPathName), 8) = "RECYCLED" And Len(fPath) = 3 Then 'We dont want the recycle bin so ignore it
Marc, first off, I am declaring the MaxFileSize variable as currency because it is the only damn variable large enough to handle a gigabyte as expressed in bytes so i can do a comparison on the Filelen(Filename) to a user entered filesize.
I see now why its not exiting the function but i have discovered that i am getting a memory error when i still have 320 meg left!!! It looks like the mem error comes up at about 8000 rows even tho i still have 50% system resources free. Question is.......is my rogram correctly detecting out of memory or is the windows System resource tool crap!? I would put my money on the microsoft tool cos everything MS do is sh***
There are 3 types of people in this world.........those that can count, and those that can't.
You can recurse about 6000 times on my machine with this code :
VB Code:
Private Sub Form_Load()
doSomething 1
End Sub
Private Function doSomething(ByVal n As Long) As Long
Debug.Print n
doSomething = doSomething(n + 1)
End Function
And regarding using main memory.
Yes you could, but you'd have to write your own call stack and using a combination of AddressOf() and CallWindowsProc()...
... it would be very difficult...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
well, seeing as the recursion on happens each time the code meets a directory, as i dont have that many folders i can only think the problem is size related rather than number of recursions. hmmmmmmm will have to just put a limit on the number of files to a sensible number despite what the customer wants. Thanks for the help folks
There are 3 types of people in this world.........those that can count, and those that can't.