Another VB question

Status
Not open for further replies.

sandeepa

New Member
Hello everyone

I am having a problem with this small piece of code in vb-

Case "1"
ch1(ch1i) = stemperature
If ch1i = 100 Then
ch1i = 0
Else: ch1i = ch1i + 1
End If


however I am getting an error saying "Complie error:Else without If"

I completely fail to see what is this supposed to mean.Why does it say "Else without if" when the If is right there?
Thanks.
 
Code:
Option Explicit  ' Please use option explicit

Dim ch1 As Integer   ' Then define some variables
Dim ch1i As Integer
Dim stemperature As Integer

ch1i = stemperature   ' this is asignment

If ch1i = 100 Then   ' this is IF THEN ELSE 
  ch1i = 0
Else
  ch1i = ch1i + 1
End If
 
Thanks.
But dont understand why writing on different lines should make a difference.Isnt that strange?
Thanks.
 
your else statement is wrong

you have

else:

lose the colon, as in the example - and pay attention to the option explicit - it WILL SAVE YOU HEADACHES IF YOU USE IT!!!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…