Results 1 to 10 of 10

Thread: What are the different ways to exit a sub?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    10
    For whatever reason the program I am designing does not want to let me exit the sub, every time I try it gives me an error that says "Runtime Error 5: Invalid procedure or call argument". I have tried using an error trapping routine and it doesnt catch the error, I tried creating a line name and saying "if ... then goto skipsub" and I tried just saying "if ... then exit sub" but nothing works, by the way, here is the line of code that I can't exit the sub with, Does anyone have any idea what is causing this error??? I would really appriciate some suggestions, thanks!

    If UCase(Trim(Mid(d$, 23, 25))) <> userlevel$ Then Close: Exit Sub

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    1. Do you have an file open?
    2. IS d$ longer than 23?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    10

    Yes

    A file is open, and d$ is not longer than 25, but I have similar if ... then statements in the program, and I have no problem with those, if you think it would help, I will e-mail you the whole sub, thanks for your help.

  4. #4
    Guest
    Try removing the colon and poutting them on seperate lines.
    Also, instead of Close you could also try Close #1 (or whatever file you have open.

    Can you post up your whole code?

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    10

    Nope

    Unfortunately, neither of those work, in fact I have similar lines of code in other parts of the program that work perfectly, I am really stumped, how else can you exit a sub, that is always when the crash occurs, just as the program exits the sub?

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You can't use Exit Sub in a function or Property, go check that also. If it's not that, either post the whole sub here or send it to me
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The code did run, i've just tested it, i removed the on error, caused me much erros but that one exiting the sub worked. What version are you using?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    I would say that you are trying to exit sub before file is closed. I mean that file is closed by OS asynchronicaly and then OS returns message about completing file operation, but there is no Sub running any more. And this is what triggered Error 5, I beleive.
    You should try Empty loop with DoEvents for a second or so, or check if file is closed as a loop condition. only after this you can exit sub.

  9. #9
    Guest
    Post your code up.

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    That's not the case LG, i've tested his code. I suppose i need the whole project and the files attached to it to know where the problem is
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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