having problems with else if error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pjishere
    New Member
    • Dec 2011
    • 1

    having problems with else if error

    hi
    i am a novice programer and i am having trouble with vb already
    it is showing COMPILE ERROR :ELSE WITHOUT IF
    please help me

    Code:
    Private Sub Command1_Click()
    
    If Text1.Text = "DDRC" Then Form1.Show
    
    Else: MsgBox = vbAbort
    
    End If
    
    
    End Sub
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    not "Else:" but "Else"

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      actually "Else:" is fine, since it's a line change mark.

      The real error is that IF has two forms

      1)IF condition THEN ActionA [ELSE ActionB]
      2)Multiline for multi actions. (IF THEN / ELSE / END IF)

      Your IF statement is of the first form... and then you put other lines. So just put "Form1.Show " into the next line, and you're done.

      Comment

      • Guido Geurs
        Recognized Expert Contributor
        • Oct 2009
        • 767

        #4
        Of course, sorry I did not see this one.
        I never use ":" because I always indent my code: it's easier to read and easier to detect code errors.
        Code:
        If (condition) then (action1) : (action2) else (action3) : (action4)
        becomes:
        Code:
        If (condition) then 
           (action1)
           (action2)
        else 
           (action3)
           (action4)
        end if

        Comment

        Working...