Results 1 to 12 of 12

Thread: Error message coming up 3 times

  1. #1

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512

    Error message coming up 3 times

    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.

    Blobby

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    So you've got this ?

    VB Code:
    1. On Error Goto errHandle
    2.  
    3. '' my code goes here
    4. Exit Function
    5.  
    6. errHandle:
    7.     MsgBox "bleh!"
    8.     Exit Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Can you show what you got.

    It must be in your code.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  4. #4

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Hi guys,

    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
    Attached Files Attached Files
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  5. #5
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    At least you should have marked in the code where exactly the error is coming from .

  6. #6
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    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 ????

  7. #7
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456

    Re: Error message coming up 3 times

    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:
    1. If fName = "." Or fName = ".." Then
    2.             'do nothing
    3.         Else
    4.             If (WFD.dwFileAttributes And vbDirectory) = vbDirectory Then
    5.                 If Right(UCase(fPathName), 8) = "RECYCLED" And Len(fPath) = 3 Then 'We dont want the recycle bin so ignore it
    6.                     'do nothing
    7.                 ElseIf Level > 0 Then
    8.                     If CancelSearch = False Then
    9.                         Status = "Scanning " & fPathName
    10.                     End If
    11.                     [b]LoadFiles fPathName, NamePattern, Level - 1[/b]
    12.                 End If
    13.             End If
    14.         End If
    Last edited by techyspecy; Feb 26th, 2003 at 11:54 AM.

  8. #8

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    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.

    Blobby

  9. #9
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I would say that its reporting no more memory left available to the stack, not that there's no more memory left for the pc.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  10. #10

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    jamie, is it possible to use the rest of the memory instead of erroring out as it seems pointless having 500 meg of memory if you have a small stack?
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  11. #11
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    You can recurse about 6000 times on my machine with this code :

    VB Code:
    1. Private Sub Form_Load()
    2.     doSomething 1
    3. End Sub
    4.  
    5. Private Function doSomething(ByVal n As Long) As Long
    6.     Debug.Print n
    7.     doSomething = doSomething(n + 1)
    8. 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]

  12. #12

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    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.

    Blobby

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width