*Question by Aelfvine*: Problem with visual basic (Expected ‘end’?)?

Hey, I keep getting the same error in my code. I’ve tried for about an hour to figure wtf is wrong, but I’m stuck. The error says:

Line 27, Char 5 Expected ‘End”

I’ve tried the obvious, adding an end if, but to no avail. Please help.

Option Explicit

DIM num, counter, doublesquare, ways, wayscounter, doubletwo, a, b

num = inputbox(“Enter n: “)

ways = 0

wayscounter = 0

counter = 0

doubletwo = 0

a = 0

b = 0

do while cInt(counter) < cInt(num) counter = counter + 1 doublesquare = inputbox("Enter integer: ") if doublesquare = 0 then ways = 1 Document.write("The number of ways for " &doublesquare &"is " &ways &".") else if doublesquare = 1 then ways = 1 Document.write("The number of ways for " &doublesquare &"is " &ways &".") end if else if doublesquare = 3,7,11 then ways = 0 Document.write("The number of ways for " &doublesquare &"is " &ways &".") end if else if doublesquare > 1 then

do while cInt(doubletwo) = 0

wayscounter = wayscounter + 1

do until doubletwo = 0

doubletwo = doublesquare – cInt(a)^2 – cInt(b)^2

a = a + 1

b = b + 1

loop

loop

Document.write(“The number of ways for ” &doublesquare &”is ” &wayscounter &”.”)

end if

end if

loop

msgbox(“End Program”)

**Best answer:**

*Answer by Ratchetr*

Change else if

to

elseif ‘ Yeah, no space between else and if.

Get rid of all end end if’s , except the last one.

You have to fix this one too:

else if doublesquare = 3,7,11 then

You can’t do that.

Try:

elseif doublesquare = 3 or doublesquare = 7 or doublesquare = 11 then

When in doubt, comment out pieces of code until it works, then add back pieces at a time until you find what is causing the problem.

**What do you think? Answer below!**