Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011
    Posts
    1

    Angry 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
    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
    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. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •