Results 1 to 7 of 7

Thread: Else Without If

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    51

    Else Without If

    i know this is a really easy thing to fix, but i cant figure it out

    I keep getting the method Else Without If, how can i fix it

    VB Code:
    1. If showf.Text = "" Then MsgBox ("You Cannot Leave The Show Command Empty")
    2. ElseIf Hidef.Text = "" Then MsgBox ("You Cannot Leave The Hide Command Empty")
    3. ElseIf Endf.Text = "" Then MsgBox ("You Cannot Leave The End Program Command Empty")
    4. ElseIf Hidef.Text = "" Then MsgBox ("You Cannot Leave The Open Command Empty")
    5. Else: Big Mess of Code
    6. End If

    Thanks

    ParadoX

  2. #2
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Re: Else Without If

    VB Code:
    1. If showf.Text = "" Then
    2.   MsgBox ("You Cannot Leave The Show Command Empty")
    3. ElseIf Hidef.Text = "" Then
    4.   MsgBox ("You Cannot Leave The Hide Command Empty")
    5. ElseIf Endf.Text = "" Then
    6.   MsgBox ("You Cannot Leave The End Program Command Empty")
    7. ElseIf Hidef.Text = "" Then
    8.   MsgBox ("You Cannot Leave The Open Command Empty")
    9. Else
    10.   'Big Mess of Code
    11. End If
    When there's a statement on the same line as the Then, that means something different to VB.

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

    Re: Else Without If

    Also, the colon character ':' when used that way is designating a carraige return, or such.
    VB Code:
    1. For i = 1 to 10 : MsgBox i : Next
    But its bad coding to use that style.
    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

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Else Without If

    Better is:

    VB Code:
    1. Select Case True
    2.     Case showf.Text = ""
    3.         MsgBox ("You Cannot Leave The Show Command Empty")
    4.     Case Hidef.Text = ""
    5.         MsgBox ("You Cannot Leave The Hide Command Empty")
    6.     Case Endf.Text = ""
    7.        MsgBox ("You Cannot Leave The End Program Command Empty")
    8.     Case Hidef.Text = "" 'BTW do you realize this is the same as the one above
    9.        MsgBox ("You Cannot Leave The Open Command Empty")
    10.     Case Else
    11.       'Big Mess of Code
    12. End Select
    Also a user of your program could type a couple of spaces in one of your textboxes and that would pass your edit so you might want to change all of them like this one
    VB Code:
    1. Case Trim(showf.Text) = ""

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

    Re: Else Without If

    There is one very interesting thing I noticed recently:

    this sort of coding style (single line with colon) appears on our forum very frequently - I wonder if people that ask are all having the same instructor ???

    Just curious ...

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Else Without If

    teacher being slick, so he can find copycats, prolly. could be he doesn't know the difference, but in this day and age, I would hope that isn't the case. (it was almost 30 years ago when I was in school)

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Else Without If

    iParadox


    Try changing

    Else: Big Mess of Code

    to


    Else
    Big Mess of Code

    or better yet

    Else
    Call Big Mess of Code


    But for better coding I would suggest MartinLiss's Case Statement.

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