# Thread: end if without block if

1. Registered User
Join Date
May 2011
Posts
1

## Unanswered: end if without block if

Okay i have some problem at Vba and i can't figure it out
the code goes like this, and when i run it it start crying about end if without block if
If Val(yli) > 0 And Val(yli) < 2 Then Val (yli) * 1.5 Else Val (yli) * 2
End If
palkka = Val(tuntipalkka) * (Val(ma) + Val(ti) + Val(ke) + Val(tor) + Val(pe) + Val(la) + Val(su) + Val(yli))
End Sub
it's still in progress but i need to get trought this before i can continue.
and the program should calculate my salary

btw im starter so do not laugh
Last edited by nasse993; 05-26-11 at 06:17.

2. Registered User
Join Date
Nov 2003
Location
Christchurch, New Zealand
Posts
1,619
from memory...

VB syntax has some basis in line returns etc....

Your code is technically incorrect as your else statement is not on a different line to your if statement. The following are valid versions of your code
Code:
```Private Sub laske_Click()

If Val(yli) > 0 And Val(yli) < 2 Then
Val (yli) * 1.5
Else
Val (yli) * 2
End If

palkka = Val(tuntipalkka) * (Val(ma) + Val(ti) + Val(ke) + Val(tor) + Val(pe) + Val(la) + Val(su) + Val(yli))

End Sub```
or alternatively...

Code:
```Private Sub laske_Click()

If Val(yli) > 0 And Val(yli) < 2 Then Val (yli) * 1.5 Else Val (yli) * 2

palkka = Val(tuntipalkka) * (Val(ma) + Val(ti) + Val(ke) + Val(tor) + Val(pe) + Val(la) + Val(su) + Val(yli))

End Sub```
Pretty sure that is correct.