Results 1 to 5 of 5

Thread: I cant place an End If !!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83

    I cant place an End If !!!

    For some reason or another whith all of the if statements below
    when I put an End If after them I get an error saying: End if must be preceeded by a matching If... The code works fine exept its causing bugs in the rest of the code. Any ideas? Besides a select case.. Cause I cant put an end if inside a Select case either!

    Code:
    Public Function Todo()
            System.Console.WriteLine(">--------------------------------------------<")
            System.Console.Write("What do you think we should do?")
            sInput = System.Console.ReadLine()
    
            If sInput = "look" Then Call Locations()
            If sInput = "orders please" Then Call Locations()
    
            If sInput = "Drop Badge" Then Badge = False
            Console.WriteLine("OK, I droped the badge!") : Call Start()
    
    
    
    
        End Function
    12/32/84 - I need some code to make me a sandwhich.

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    To save yourself some heartache, just use a select statement, or just put the end if after each if statement.
    Dont gain the world and lose your soul

  3. #3
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Try this:

    Code:
    Public Function Todo()
            System.Console.WriteLine(">--------------------------------------------<")
            System.Console.Write("What do you think we should do?")
            sInput = System.Console.ReadLine()
    
            Select sInput
                  Case "look", "orders please"
                         Call Locations()
                  Case "Drop Badge"
                          Badge = False
                          Console.WriteLine("OK, I droped the badge!") 
                          Call Start()
                   Case else
                           Console.WriteLine("Invalid data entered"
            End Select
    End Function
    Dont gain the world and lose your soul

  4. #4
    New Member
    Join Date
    Feb 2002
    Location
    UK
    Posts
    3
    You do not need an End If when the the statement(s) to be executed are on the same line as the If.

    You could do something like:

    Dim li_Var As Int16 = 1

    If li_Var = 1 Then Call Locations()

    or multiple statements:

    If li_Var = 1 Then Call Locations() : Call Start()

    Which is perfectly valid, but not very readable.

    When the Statement(s) is not on the same line then you require the End If:

    If li_Var = 1 Then
    Call Locations()
    End If

    As for your other bugs, then you _have_ other bugs and this is not your problem.

    As DevGrp has shown above though, would be better in a case.

    Hope this helps,

    Mike

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    Thanks for the help. I converted it to select case.
    And I found the bug. After searching for about an
    hour, I noticed that one of the room names had
    the first letter in lowercase while the rest had
    the first letter in uppercase! All that work for
    on single charactor.....
    12/32/84 - I need some code to make me a sandwhich.

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