+ Reply to Thread
Results 1 to 3 of 3

Correct Syntax for Calling other Subs

  1. #1
    Andibevan
    Guest

    Correct Syntax for Calling other Subs

    Hi All,

    What do I need to change in order to get the following to work. Should I be
    using a function for this sort of routine?

    I get the error "expected function or variable"

    Sub TestSub(var1 As Integer)

    TestSub = var1 + 2

    End Sub

    Sub testsub2()
    Dim var1

    var1 = TestSub(2)
    MsgBox var1

    End Sub



  2. #2
    K Dales
    Guest

    RE: Correct Syntax for Calling other Subs

    When your code returns a value it needs to be a Function, not a Sub:
    Function TestSub(var1 As Integer) as Integer

    TestSub = var1 + 2

    End Function

    Sub testsub2()
    Dim var1

    var1 = TestSub(2)
    MsgBox var1

    End Sub

    "Andibevan" wrote:

    > Hi All,
    >
    > What do I need to change in order to get the following to work. Should I be
    > using a function for this sort of routine?
    >
    > I get the error "expected function or variable"
    >
    > Sub TestSub(var1 As Integer)
    >
    > TestSub = var1 + 2
    >
    > End Sub
    >
    > Sub testsub2()
    > Dim var1
    >
    > var1 = TestSub(2)
    > MsgBox var1
    >
    > End Sub
    >
    >
    >


  3. #3
    Andibevan
    Guest

    Re: Correct Syntax for Calling other Subs

    Thanks - didn't realise that

    "K Dales" <[email protected]> wrote in message
    news:[email protected]...
    When your code returns a value it needs to be a Function, not a Sub:
    Function TestSub(var1 As Integer) as Integer

    TestSub = var1 + 2

    End Function

    Sub testsub2()
    Dim var1

    var1 = TestSub(2)
    MsgBox var1

    End Sub

    "Andibevan" wrote:

    > Hi All,
    >
    > What do I need to change in order to get the following to work. Should I

    be
    > using a function for this sort of routine?
    >
    > I get the error "expected function or variable"
    >
    > Sub TestSub(var1 As Integer)
    >
    > TestSub = var1 + 2
    >
    > End Sub
    >
    > Sub testsub2()
    > Dim var1
    >
    > var1 = TestSub(2)
    > MsgBox var1
    >
    > End Sub
    >
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1