Skip to content

Instantly share code, notes, and snippets.

@kewang
Created June 22, 2019 16:28
Show Gist options
  • Save kewang/646e6e2fbc586577b83534d82bc7064a to your computer and use it in GitHub Desktop.
Save kewang/646e6e2fbc586577b83534d82bc7064a to your computer and use it in GitHub Desktop.
Private Function calculate() As Double
Select Case Dropdown.SelectedItem
Case "+"
Return CDbl(TA.Text.Trim) + CDbl(TB.Text.Trim)
Case "-"
Return CDbl(TA.Text.Trim) - CDbl(TB.Text.Trim)
Case "*"
Return CDbl(TA.Text.Trim) * CDbl(TB.Text.Trim)
Case "/"
Return CDbl(TA.Text.Trim) / CDbl(TB.Text.Trim)
End Select
End Function
Public Sub TA_changed() Handles TA.TextChanged
LabelResult.Text = calculate()
End Sub
Public Sub TB_changed() Handles TB.TextChanged
LabelResult.Text = calculate()
End Sub
Public Sub Dropdown_changed() Handles Dropdown.SelectedIndexChanged
LabelResult.Text = calculate()
End Sub
Private Function calculate() As Double
Select Case Dropdown.SelectedItem
Case "+"
Return CDbl(TA.Text.Trim) + CDbl(TB.Text.Trim)
Case "-"
Return CDbl(TA.Text.Trim) - CDbl(TB.Text.Trim)
Case "*"
Return CDbl(TA.Text.Trim) * CDbl(TB.Text.Trim)
Case "/"
Return CDbl(TA.Text.Trim) / CDbl(TB.Text.Trim)
End Select
End Function
Public Sub LabelResult_Load() Handles LabelResult.Load
LabelResult.Text = calculate()
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment