End if

Discussion in 'Software' started by ClaretAlan, Sep 16, 2004.

  1. ClaretAlan

    ClaretAlan Private E-2

    What is the matter with this code from VB4?
    I get the error message block if without end if

    Sub commandequals_click()
    n2 = Textanswer.Text
    If opt = "+" Then
    Textanswer.Text = n1 + n2
    Else
    If opt = "-" Then
    Textanswer.Text = n1 - n2
    Else
    If opt = "/" Then
    Textanswer.Text = n1 / n2
    Else
    If opt = "*" Then
    Textanswer.Text = n1 * n2
    End If
    End Sub
     
  2. Wookie

    Wookie Sergeant Major

    Try this


    Sub commandequals_click()
    n2 = Textanswer.Text
    If opt = "+" Then
    Textanswer.Text = n1 + n2
    Elseif opt = "-" Then
    Textanswer.Text = n1 - n2
    Elseif opt = "/" Then
    Textanswer.Text = n1 / n2
    Elseif opt = "*" Then
    Textanswer.Text = n1 * n2
    End If
    End Sub
     
  3. ClaretAlan

    ClaretAlan Private E-2

    Thank You
     
  4. Kodo

    Kodo SNATCHSQUATCH

    a faster version would be this


    Sub commandequals_click()
    n2 = Textanswer.Text

    select case opt

    case "+"
    Textanswer.Text = n1 + n2

    case "-"
    Textanswer.Text = n1 - n2

    case "/"
    Textanswer.Text = n1 / n2

    case "*"
    Textanswer.Text = n1 * n2

    End select

    End Sub
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds