Expected expression

The Expected: expression compile error means that while trying to compile the line, things went haywire because the compiler was expecting to find an expression but found nothing. This error happens if you leave one or more dangling commas at the end of a statement.

For example, the MsgBox statement in Figure 12-5 generated the compile error shown in that same figure. If you look closely, you might also notice that the closing parenthesis in the code is highlighted. The compile error is trying to help out by highlighting the place where it ran into the problem.

Figure 12-5:

Sample Expected: expression compile error.

Figure 12-5:

Sample Expected: expression compile error.

The problem with the line of code is that last comma, just to the left of the closing parenthesis. You use a comma only when you're about to type another expression into the list of arguments. In other words, while compiling that line of code, the compiler saw that last comma, expecting to find some expression after that comma, but instead found a closing parenthesis.

One solution to the problem would be to get rid of that last comma, as follows:

Answer = MsgBox("Hello World", vblnformation)

Or, you can leave the comma but add the argument that belongs in that spot. For example, in the MsgBox statement, the third argument is the title to show in the message box. To make that title read as Test, just go ahead and make that word the third argument (after the last comma), as follows:

Answer = MsgBox("Hello World", vbInformation,"Test")

0 0

Post a comment