Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Function Return Value

Function Return Value

Scheduled Pinned Locked Moved Visual Basic
question
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    momooomooomomo
    wrote on last edited by
    #1

    good day again... how does a function return two value? thanks

    nothing is impossible.....

    T C J 3 Replies Last reply
    0
    • M momooomooomomo

      good day again... how does a function return two value? thanks

      nothing is impossible.....

      T Offline
      T Offline
      Tamimi Code
      wrote on last edited by
      #2

      dim intTest as Integer = GetNumber() ... ..... ....... function GetNumber() as Integer dim i as Integer = 1+2 GetNumber = i ' or return i end function

      When you get mad...THINK twice that the only advice Tamimi - Code

      M L 2 Replies Last reply
      0
      • M momooomooomomo

        good day again... how does a function return two value? thanks

        nothing is impossible.....

        C Offline
        C Offline
        coolestCoder
        wrote on last edited by
        #3

        Hi, To return multiple values from a function, you will have to pass the arguments ByRef, not ByValue. The values you want to return will only be set to the arguments and these will be refelected outside the function. Search MSDN for ByRef keyword for more details !


        "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


        coolestCoder

        M 1 Reply Last reply
        0
        • T Tamimi Code

          dim intTest as Integer = GetNumber() ... ..... ....... function GetNumber() as Integer dim i as Integer = 1+2 GetNumber = i ' or return i end function

          When you get mad...THINK twice that the only advice Tamimi - Code

          M Offline
          M Offline
          momooomooomomo
          wrote on last edited by
          #4

          thanks, your function does involves to values, but return one result.. ... i mean to ask, how does a function return to result.. ex: textbox1.text = getNumber(1) textbox2.text = getNumber(2) the code you provided was a great help, but it only returns 1 result... does anyone here knows how a function return two results?... thank you.. ;)

          nothing is impossible.....

          M 1 Reply Last reply
          0
          • M momooomooomomo

            thanks, your function does involves to values, but return one result.. ... i mean to ask, how does a function return to result.. ex: textbox1.text = getNumber(1) textbox2.text = getNumber(2) the code you provided was a great help, but it only returns 1 result... does anyone here knows how a function return two results?... thank you.. ;)

            nothing is impossible.....

            M Offline
            M Offline
            momooomooomomo
            wrote on last edited by
            #5

            Correction i mean "two results":laugh:

            nothing is impossible.....

            1 Reply Last reply
            0
            • C coolestCoder

              Hi, To return multiple values from a function, you will have to pass the arguments ByRef, not ByValue. The values you want to return will only be set to the arguments and these will be refelected outside the function. Search MSDN for ByRef keyword for more details !


              "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


              coolestCoder

              M Offline
              M Offline
              momooomooomomo
              wrote on last edited by
              #6

              thank you sir... your help is highly appreciated...

              nothing is impossible.....

              K 1 Reply Last reply
              0
              • T Tamimi Code

                dim intTest as Integer = GetNumber() ... ..... ....... function GetNumber() as Integer dim i as Integer = 1+2 GetNumber = i ' or return i end function

                When you get mad...THINK twice that the only advice Tamimi - Code

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                {{ A7WAL }} :omg:FLOAT LIKE A BUTTERFLY STING LIKE A BEE

                Mohamad A. Flefel mflefel@hotmail.com +962 79 5963865 C#.net & VB.net Developer

                T 1 Reply Last reply
                0
                • M momooomooomomo

                  thank you sir... your help is highly appreciated...

                  nothing is impossible.....

                  K Offline
                  K Offline
                  Kevin McFarlane
                  wrote on last edited by
                  #8

                  An alternative is to define a structure that has two values and return that. In .NET 2 you could use one of those libraries that has a Pair generic class, e.g., see the free PowerCollections library. In C++ the Standard Library also defines a Pair class precisely for situations where you want to return two values - which is quite a common scenario in fact. I try to avoid ByRef when possible because it makes code less clear. But often you can't avoid it. Unfortunately, I'm not using .NET 2.0 yet, so can't use libraries such as PowerCollections.

                  Kevin

                  1 Reply Last reply
                  0
                  • L Lost User

                    {{ A7WAL }} :omg:FLOAT LIKE A BUTTERFLY STING LIKE A BEE

                    Mohamad A. Flefel mflefel@hotmail.com +962 79 5963865 C#.net & VB.net Developer

                    T Offline
                    T Offline
                    Tamimi Code
                    wrote on last edited by
                    #9

                    your comment does not help any one !!!! whats wrong with you ?? :mad::mad::mad:

                    When you get mad...THINK twice that the only advice Tamimi - Code

                    1 Reply Last reply
                    0
                    • M momooomooomomo

                      good day again... how does a function return two value? thanks

                      nothing is impossible.....

                      J Offline
                      J Offline
                      Johan Hakkesteegt
                      wrote on last edited by
                      #10

                      Hi, Alternatively you can simply work with arrays. I managed to do it like this: Private Function Amounts(ByVal SomeByValIfNecessary As String) As Integer() Dim AMarray(2) As Integer Try AMarray(0) = 1 AMarray(1) = 2 AMarray(2) = 3 Return AMarray Catch Ex As Exception msgbox(Ex.message) End Try Elsewhere you can then call upon the different returned values like this: SomeIntegerVariable1 = Amounts(SomeValueForTheByref).GetValue(0) SomeIntegerVariable2 = Amounts(SomeValueForTheByVal).GetValue(1) SomeIntegerVariable3 = Amounts(SomeValueForTheByVal).GetValue(2) Hope this helps, Johan -- modified at 7:30 Friday 24th November, 2006

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups