Я создаю калькулятор в приложении Windows на VB.NET.Все операторы (сложение и вычитание) работают нормально, однако, когда я пытаюсь вычислить с использованием деления или умножения, строка 39 выдает System.Data.SyntaxErrorException
.Это строка, которая вызывает исключение:
Dim result = New DataTable().Compute(equation, Nothing)
Кто-нибудь знает, почему это происходит?Вот остаток кода:
Public Class Form1
Private Sub ButtonClickMethod(sender As Object, e As EventArgs) Handles num0.Click, num1.Click, num2.Click, num3.Click, num4.Click, num5.Click, num6.Click, num7.Click, num8.Click, num9.Click, opdivision.Click, opmultiply.Click, opdecimal.Click, opclear.Click, opminus.Click, opadd.Click, opequal.Click
Dim button As Button = CType(sender, Button)
If button.Name = "num1" Then
TextBox1.Text = TextBox1.Text + "1"
End If
If button.Name = "num2" Then
TextBox1.Text = TextBox1.Text + "2"
End If
If button.Name = "num3" Then
TextBox1.Text = TextBox1.Text + "3"
End If
If button.Name = "num4" Then
TextBox1.Text = TextBox1.Text + "4"
End If
If button.Name = "num5" Then
TextBox1.Text = TextBox1.Text + "5"
End If
If button.Name = "num6" Then
TextBox1.Text = TextBox1.Text + "6"
End If
If button.Name = "num7" Then
TextBox1.Text = TextBox1.Text + "7"
End If
If button.Name = "num8" Then
TextBox1.Text = TextBox1.Text + "8"
End If
If button.Name = "num9" Then
TextBox1.Text = TextBox1.Text + "9"
End If
If button.Name = "num0" Then
TextBox1.Text = TextBox1.Text + "0"
End If
If button.Name = "opdecimal" Then
TextBox1.Text = TextBox1.Text + "."
End If
If button.Name = "opequal" Then
Dim equation As String = TextBox1.Text
Dim result = New DataTable().Compute(equation, Nothing)
boxresult.Text = result
End If
If button.Name = "opminus" Then
TextBox1.Text = TextBox1.Text + "-"
boxoperator.Text = boxoperator.Text + "-"
End If
If button.Name = "opmultiply" Then
TextBox1.Text = TextBox1.Text + "x"
boxoperator.Text = boxoperator.Text + "x"
End If
If button.Name = "opdivision" Then
TextBox1.Text = TextBox1.Text + "÷"
boxoperator.Text = boxoperator.Text + "÷"
End If
If button.Name = "opadd" Then
TextBox1.Text = TextBox1.Text + "+"
boxoperator.Text = boxoperator.Text + "+"
End If
If button.Name = "opclear" Then
TextBox1.Clear()
End If
End Sub
Private Sub opbackspace_Click(sender As Object, e As EventArgs) Handles opbackspace.Click
TextBox1.Text = TextBox1.Text.Remove(TextBox1.Text.Count - 1)
End Sub
End Class