Consulting

Results 1 to 5 of 5

Thread: Solved: Wrong Argument Syntax

  1. #1
    VBAX Regular
    Joined
    Jun 2004
    Location
    New Jersey
    Posts
    52
    Location

    Solved: Wrong Argument Syntax

    Hi all

    I want to create a procedure and pass two arguments to it. I have done this in the past, but for some reason now I keep getting the same error message in the vba editor ( Compiler Error, Expected =). Below is just a macro I was using to debug this problem (not the actual macro I will us it in).
    As always your help will be appreciated.
    Thanks
    russ

    Dim HI As String
    Dim gregg As String
    gregg = vbCr & "Gregg"
    HI = "Russell says Hello"
    sayhi(hi, gregg)

    End Sub

    Private Sub sayHi(verbage As String, FAN As String)
    MsgBox verbage & FAN
    End Sub
    Russ

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,892
    Location
    Hi Russ, welcome!

    I'm not sure what your Private Sub is for, but for the first one you could change your syntax to something like this:


    [vba]Sub testoosie()

    Dim HI As String
    Dim gregg As String
    Dim sayhi As String
    gregg = vbCr & "Gregg"
    HI = "Russell says Hello"
    sayhi = HI & gregg
    MsgBox sayhi

    End Sub[/vba]

    It works for me. You can call it from another sub like this:


    [vba]Call testoosie[/vba]


    But if it's private, you've gotta call it from the same module, else I'd just take that private off of there. Does that help any?

  3. #3
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Russ,

    Your problem is the syntax of the line

    sayhi(hi, gregg)

    It is a single element, not a complete statement. To call the function as you want you should not have the parentheses ..

    sayhi hi, gregg
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  4. #4
    VBAX Regular
    Joined
    Jun 2004
    Location
    New Jersey
    Posts
    52
    Location
    Tony
    Thanks, that is exactly what I wanted. The procedure I am using requires 3 separate strings passed to it. I never realized I didn't need the parenthesis.
    Now how do I mark this Solved.
    and Thanks again.
    island17 (Russ)
    Russ

  5. #5
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Hey, Russ. We even mark it solved for ya.
    Way to go, Tony.
    ~Anne Troy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •