Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 766503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:03:29+00:00 2026-05-14T17:03:29+00:00

How do I return a result from a function? For example: Public Function test()

  • 0

How do I return a result from a function?

For example:

Public Function test() As Integer
    return 1
End Function

This gives a compile error.

How do I make this function return an integer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T17:03:30+00:00Added an answer on May 14, 2026 at 5:03 pm

    For non-object return types, you have to assign the value to the name of your function, like this:

    Public Function test() As Integer
        test = 1
    End Function
    

    Example usage:

    Dim i As Integer
    i = test()
    

    If the function returns an Object type, then you must use the Set keyword like this:

    Public Function testRange() As Range
        Set testRange = Range("A1")
    End Function
    

    Example usage:

    Dim r As Range
    Set r = testRange()
    

    Note that assigning a return value to the function name does not terminate the execution of your function. If you want to exit the function, then you need to explicitly say Exit Function. For example:

    Function test(ByVal justReturnOne As Boolean) As Integer
        If justReturnOne Then
            test = 1
            Exit Function
        End If
        'more code...
        test = 2
    End Function
    

    Documentation: Function Statement

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Starting from this example: http://support.microsoft.com/kb/828736 I have tried to add a test function in
I have associative array: Model public function selectArticle(){ $sql = $this->db->query(SELECT * FROM articles);
I would like to handle a return result from an AsyncTask outside of the
Can anyone explain why this query returns an empty result. SELECT * FROM (`bookmarks`)
I have an odd problem when using the return result of a function and
I'm modifying polymorphism example from here to test multiple inheritance. When I run the
I'm following Steve Sanderson's example from this ASP.NET MVC book on creating a model
I have a simple code from controller public ActionResult CreatePage() { return PartialView( APage
I'm create AJAX Service with JSON and XML from this example . In service.cs
For example, if I run one query in model: public function list_users() { $q

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.