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. Functions - Parameter Passing

Functions - Parameter Passing

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
5 Posts 3 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.
  • X Offline
    X Offline
    xBlitzerx
    wrote on last edited by
    #1

    Is there a tutorial on this somewhere? I'm going nuts here.... how many different variables do i need? i'm writing a program that uses a function to accept a number as a parameter. make some calculations to it, and return it.. then sub main will output the results... don't give me code please...i just want some pointers... "I'm not me when I dream...anymore." - TRUSTcompany

    X M 2 Replies Last reply
    0
    • X xBlitzerx

      Is there a tutorial on this somewhere? I'm going nuts here.... how many different variables do i need? i'm writing a program that uses a function to accept a number as a parameter. make some calculations to it, and return it.. then sub main will output the results... don't give me code please...i just want some pointers... "I'm not me when I dream...anymore." - TRUSTcompany

      X Offline
      X Offline
      xBlitzerx
      wrote on last edited by
      #2

      thanks for the help! NOT! ______________________________________________ "I'm not me when I dream...anymore." -TRUSTcompany

      R 1 Reply Last reply
      0
      • X xBlitzerx

        Is there a tutorial on this somewhere? I'm going nuts here.... how many different variables do i need? i'm writing a program that uses a function to accept a number as a parameter. make some calculations to it, and return it.. then sub main will output the results... don't give me code please...i just want some pointers... "I'm not me when I dream...anymore." - TRUSTcompany

        M Offline
        M Offline
        mikasa
        wrote on last edited by
        #3

        Ummm...pass it "ByRef"? Or make your Function return the Value? Function should ALWAYS Return something. So if you want the ByRef method, make it a Sub Routine. Your question isn't really clear, so I hope this Helps. 'Pass ByRef Example Public Sub Test(ByRef MyValue as Integer) MyValue = 5 End Sub 'Return a Variable Public Function Test(ByRef MyValue as Integer) As Integer Return 5 'VB.NET Test = 5 'VB6 / VB.NET End Sub

        X 1 Reply Last reply
        0
        • M mikasa

          Ummm...pass it "ByRef"? Or make your Function return the Value? Function should ALWAYS Return something. So if you want the ByRef method, make it a Sub Routine. Your question isn't really clear, so I hope this Helps. 'Pass ByRef Example Public Sub Test(ByRef MyValue as Integer) MyValue = 5 End Sub 'Return a Variable Public Function Test(ByRef MyValue as Integer) As Integer Return 5 'VB.NET Test = 5 'VB6 / VB.NET End Sub

          X Offline
          X Offline
          xBlitzerx
          wrote on last edited by
          #4

          i asked the professor what i forgot was that when u call the function you have to store the value somewhere: thanks though :) ex: Sub Main() Dim int as integer int = MyFunction(5) End Sub Private Function MyFunction(ByVal int as integer) as integer Dim sum as integer sum = int * 10 return sum End Function ---------------------------------------------------------------------------- This works right? ______________________________________________ "I'm not me when I dream...anymore." -TRUSTcompany

          1 Reply Last reply
          0
          • X xBlitzerx

            thanks for the help! NOT! ______________________________________________ "I'm not me when I dream...anymore." -TRUSTcompany

            R Offline
            R Offline
            Ray Cassick
            wrote on last edited by
            #5

            Sorry for not responding dude, but really now.... There are examples on how to create/call functions in VB everywhere. Just download just about any sample VB code and you will see a sample of how to write and consume a function. I did not answer this question because I felt that it was asked by someone that clearly needed to do some looking around themselves on the subject. Sorry... Looking at the responses that you did get and what you found on your own you got the concept. Just please remember that no one here OWES anyone an answer. Just as a personal note… I hate function that have byref arguments. They are used alot in the Windows world and I still hate them. IMHO functions take in arguments and return a value. That is the pure way of thinking about it. When you use a function you always think of it as:

            returnValue = FunctionName(arg1, arg2, … argn)

            And the function looks as follows:

            <scope> Function FunctionName(arg1 As Type, arg2 As Type, … argn As Type) As ReturnType

            'define the return value to use
            Dim retVal as ReturnType

            'perform what ever calculations you need to do

            'set the return value
            retVal = answerToCalculation

            Return ReturnType 'if you are using VB.NET
            FunctionName = answerToCalulation 'if you are using VB6

            End Function

            The number of input args are up to what you need, and it is very clear as to what is being returned and where. Using ByRef is called output arguments. I don't like them at all. X| As I see it, if the returned values does not end up on the left side of a function call then it is not a function, it is a Subroutine.


            Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
            George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things."


            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