Tal V
Tal V

Reputation: 41

Error - End of statement expected when doing math calculations in Visual Basic

This is my idea:

  1. You import a file with some basic math questions

  2. You read the file and copy what's written in it to a label

But when I try to calculate I am having a problem,

This is an example of the code I am having:

    Dim Five As Integer = 5
    Dim Six As Integer = 6
    Dim Plus As String = "+"
    If Five Plus Six = 9 then

    End If

When I move my mouse over the code it says:

End of statement expected

What can I do to fix it?

Upvotes: 1

Views: 108

Answers (1)

Andrew Mortimer
Andrew Mortimer

Reputation: 2370

You could try parsing for your operator. Something like this:

Private Function doCalcs() As String

    Dim Five As Integer = 5
    Dim Six As Integer = 6
    Dim Plus As String = "+"
    Dim result As Integer

    Select Case Plus
        Case "+"
            result = Five + Six
        Case "-"
            result = Five - Six
        Case Else
            result = -1 'or error handler
    End Select

    Return result

End Function

Upvotes: 3

Related Questions