Question Locked

Microsoft Visual Basic error: "expected: end of statement"

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm experiencing an issue with macros in Word 2007. I copied the following code verbatim from MSDN (URL at bottom) into Microsoft Visual Basic: -

Public Function GetScreenTip(ByVal control As IRibbonControl) As String
Return "This is a screen tip for the menu."
End Function

However, I get a compiler error, "expected: end of statement", referring to the return statement. Now I'm no expert programmer, but from what I understand, it's pretty well commonplace for a function to return a value. I don't have much of a clue when it comes to VB though. Could anyone help me out?

http://msdn.microsoft.com/en-us/library/bb462634.aspx

5 replies

by slayer_

Public Function GetScreenTip(ByVal control As IRibbonControl) As String
GetScreenTip = "This is a screen tip for the menu."
End Function

Try that

by mobil-d

Thanks for that, but now I get another error when I call the function, "Wrong number of arguments or invalid property assignment". Any ideas?

by mobil-d

Just to say that I've resolved this issue, like so: -

Sub GetScreenTipcallback(control As IRibbonControl, ByRef screentip)

End Sub

Thanks again. :)

by slayer_

both using byref and using a variant are both bad coding practicies.

Sub GetScreenTipcallback(control As IRibbonControl, ByRef screentip)

Is the same as

Sub GetScreenTipcallback(ByRef control As IRibbonControl, ByRef screentip as variant)

It would be better to, if possible, specify byval for the second argument, and specify what type of value it is (sounds like a string)
So it would look like this
Sub GetScreenTipcallback(ByRef control As IRibbonControl, Byval sScreenTip as String)

This discussion is closed to new replies.