472,133 Members | 1,014 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

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

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command1_Click()
  3.  
  4. If Text1.Text = "DDRC" Then Form1.Show
  5.  
  6. Else: MsgBox = vbAbort
  7.  
  8. End If
  9.  
  10.  
  11. End Sub
  12.  
Dec 16 '11 #1
3 1405
Guido Geurs
767 Expert 512MB
not "Else:" but "Else"
Dec 16 '11 #2
kadghar
1,295 Expert 1GB
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.
Dec 16 '11 #3
Guido Geurs
767 Expert 512MB
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.
Expand|Select|Wrap|Line Numbers
  1. If (condition) then (action1) : (action2) else (action3) : (action4)
becomes:
Expand|Select|Wrap|Line Numbers
  1. If (condition) then 
  2.    (action1)
  3.    (action2)
  4. else 
  5.    (action3)
  6.    (action4)
  7. end if
  8.  
Dec 17 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Michael C | last post: by
4 posts views Thread by Charles | last post: by
2 posts views Thread by l46kok | last post: by
1 post views Thread by tshad | last post: by
3 posts views Thread by i80and | last post: by
4 posts views Thread by lafayettejohnson | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.