Results 1 to 12 of 12

Thread: -=[Resolved]=- vb6: Exit If statement?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    47

    Resolved -=[Resolved]=- vb6: Exit If statement?

    Name says it all.
    Is there an Exit If type statment? Like break out of the current If statement without using exit sub?

    Thanks in advance, oz.
    Last edited by OzMa77; Nov 25th, 2007 at 09:47 AM.

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    47

    Re: vb6: Exit If statement?

    Alright, thanks for the quick reply by the way =)

  4. #4
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: vb6: Exit If statement?

    Try to use goto

    vb Code:
    1. Dim i as integer
    2.  
    3. i = InputBox("Key In a Value")
    4.  
    5. if i < 5 Then
    6.     Goto GoHere
    7. else
    8.     Goto GoThere
    9. End if
    10.  
    11. gohere:
    12. Msgbox "Here"
    13. goThere:
    14. Msgbox "There"
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: vb6: Exit If statement?

    I purposely avoided mentioning the GoTo but ...

    It has been discussed million and one times so here we go again - other than error handling the goto should not be used.
    For more detailed information search forum - there are plenty of discussions on this topic.

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    47

    Re: vb6: Exit If statement?

    Yeah I thought of GoTo also..it should be used for error handling and such like he said, nothin else.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: vb6: Exit If statement?

    The only thing you need to "break out of" is a loop. An If statement either executes or it doesn't.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: vb6: Exit If statement?

    GoTo should only be used for On Error statements.

    To break out of a loop:

    Exit Do
    Exit While
    Exit For

    Any other evaluations like an If or Select code blocks dont need an "exit".
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    47

    Re: vb6: Exit If statement?

    Alright, I suppose I can mark this resolved now.
    Thanks for the help.

  10. #10
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: vb6: Exit If statement?

    Thanks for advice, i try search from forums why not recommend to use goto unless error handle.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: -=[Resolved]=- vb6: Exit If statement?

    Because it create an ill effect called "speggetti code" where you end up jumping all over the code processing all the gotos etc. Its bad design logic and most difficult to track when debugging. I remember something about resource usage too but its been a long time since I seen a GoTo being used. Using GoTos is reminescent or the early 1980s BASIC coding
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: -=[Resolved]=- vb6: Exit If statement?

    Thanks Roddog your explaination is good :-)
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

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