Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Compile error: Expecte function or variable
Message
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00394670
Message ID:
00394684
Views:
12
Hi Roi,
WAG, but you are assigning the results of oApp.Test to lReturn but you aren't defining return type of Test.

Functions are handled differently in VB. There is no Return somevalue at the end of a function. You define a function is this way:
Public Function test(arg1 As String, arg2 As String) as Boolean
    Debug.Print arg1
    Debug.Print arg2
    test = True
End Function
You assign the value to the function itself. If you don't want a return value then don't assign it to anything; just call it (e.g. oApp.Test("test1","test2").

Also, I believe (although I'm not sure about this) that Subs and Functions are different in VB. While they are exactly the same in VFP, the old rule of thumb that functions return values and subs (procedures) don't is enforced in VB.

HTH.

>Hi Everyone,
>
>I'm learning vb so this is probably a lame problem, but I can't figure it out.
>
>I created a module with the following code:
>
>
Public Sub Main()
>    Dim oApp As BMD_Application
>    Dim lReturn As String
>
>    Set oApp = New BMD_Application
>
>    lReturn = oApp.test("test1", "test2")
>
>End Sub
>
>And a have the BMD_Application as a class with this code:
>
>
Public Sub test(arg1 As String, arg2 As String)
>    Debug.Print arg1
>    Debug.Print arg2
>
>End Sub
>
>When I try to run the code I get the error: Compiler error: Expected function or variable. on the oApp.test line? What does that mean? How do I fix it?
>
>Also, I don't really want a return from .test but when I try to type the line a get another compile error: Expected: =
>
>Any help would be appreciated. Thanks.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform