user2932587
user2932587

Reputation:

End of Statement Expected Error in Visual Basic

I keep getting this error on several lines of code for a program that I am working on. I don't know what I'm doing wrong, or how to fix it.

Here is the section of code that is giving me the trouble.

    If lstRecipe.Text = "Eggs(each)" Then
        dblTotalCalories = dblTotalCalories += dblQuantity * 72
    ElseIf lstRecipe.Text = "Flour(cups)" Then
        dblTotalCalories = dblTotalCalories += dblQuantity * 455
    ElseIf lstRecipe.Text = "Milk(cups)" Then
        dblTotalCalories = dblTotalCalories += dblQuantity * 86
    ElseIf lstRecipe.Text = "Sugar(cups)" Then
        dblTotalCalories = dblTotalCalories += dblQuantity * 774
    ElseIf lstRecipe.Text = "Butter(tablespoons)" Then
        dblTotalCalories = dblTotalCalories += dblQuantity * 102
    End If

The error is specifically taking place at the += dblQuantity * ... portion of each line. Any help would be greatly appreciated.

Upvotes: 1

Views: 356

Answers (3)

Revan
Revan

Reputation: 1144

If lstRecipe.Text = "Eggs(each)" Then
     dblTotalCalories += dblQuantity * 72
ElseIf lstRecipe.Text = "Flour(cups)" Then
    dblTotalCalories += dblQuantity * 455
ElseIf lstRecipe.Text = "Milk(cups)" Then
    dblTotalCalories += dblQuantity * 86
ElseIf lstRecipe.Text = "Sugar(cups)" Then
     dblTotalCalories += dblQuantity * 774
ElseIf lstRecipe.Text = "Butter(tablespoons)" Then
    dblTotalCalories += dblQuantity * 102
End If

Upvotes: 1

peterG
peterG

Reputation: 1641

You are mixing up two different ways of doing the same thing. Your code should be either dblTotalCalories += dblQuantity * 72

or

 dblTotalCalories = dblTotalCalories + dblQuantity * 72

Upvotes: 3

Ken White
Ken White

Reputation: 125689

Your syntax is invalid:

dblTotalCalories = dblTotalCalories += dblQuantity * 72

This should be

dblTotalCalories += dblQuantity * 72

The same applies to every other instance.

Upvotes: 2

Related Questions