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. How to pass a ADO object as a parameter to a function?

How to pass a ADO object as a parameter to a function?

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
8 Posts 4 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    I defined a function like this: func(byref x as ADODB.Connection) then i : Dim conn as New ADODB.Connection afterwards i: func(conn) but when i compiled it, i met a error. How to write correctly?thanks much X|

    N 1 Reply Last reply
    0
    • A Anonymous

      I defined a function like this: func(byref x as ADODB.Connection) then i : Dim conn as New ADODB.Connection afterwards i: func(conn) but when i compiled it, i met a error. How to write correctly?thanks much X|

      N Offline
      N Offline
      Nick Seng
      wrote on last edited by
      #2

      What does the error say? what about the error code? Notorious SMC


      The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
      Get your facts first, and then you can distort them as much as you please Mark Twain

      A 1 Reply Last reply
      0
      • N Nick Seng

        What does the error say? what about the error code? Notorious SMC


        The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
        Get your facts first, and then you can distort them as much as you please Mark Twain

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        type mismatch:(

        N 1 Reply Last reply
        0
        • A Anonymous

          type mismatch:(

          N Offline
          N Offline
          Nick Seng
          wrote on last edited by
          #4

          Try this:- call func(conn) or func conn Notorious SMC


          The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
          Get your facts first, and then you can distort them as much as you please Mark Twain

          A 1 Reply Last reply
          0
          • N Nick Seng

            Try this:- call func(conn) or func conn Notorious SMC


            The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
            Get your facts first, and then you can distort them as much as you please Mark Twain

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            thanks,i solved the type mismatch by your advice. :laugh:

            R 1 Reply Last reply
            0
            • A Anonymous

              thanks,i solved the type mismatch by your advice. :laugh:

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

              But do you understand WHY this worked? I think that is more important. Using parens in VB mandates that your function RETURN something. For example:

              Public Function AddNumbers(numOne As Integer, numTwo As Integer) As Ineteger

              Dim retVal as Integer

              retVal = numOne + numTwo

              AddNumbers = retVal

              End Function

              This function would be called like so:

              Dim answer As Integer

              answer = AddNumbers(1, 2)

              If you have a Subroutine they generally don't return anything. This is afterall the main difference between a Function and a Subroutine. Functions do soemthing AND return something. Given a Subroutine as such:

              Public Sub DisplaySomething(something As String)
              Debug.Print something
              End Sub

              Because this does not return anything it has to be called one of the following ways:

              DisplaySomething "Hello World."

              -or-

              Call DisplaySomething("Hello World.")

              This is one of the reasons that alot of people don't like VB. They feel confused by needing to rememebr if they have to use parens or not. Generally speaking i think that using the Call keyword is bad form though. Simply don't use parens and all is fine.


              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."


              N J 2 Replies Last reply
              0
              • R Ray Cassick

                But do you understand WHY this worked? I think that is more important. Using parens in VB mandates that your function RETURN something. For example:

                Public Function AddNumbers(numOne As Integer, numTwo As Integer) As Ineteger

                Dim retVal as Integer

                retVal = numOne + numTwo

                AddNumbers = retVal

                End Function

                This function would be called like so:

                Dim answer As Integer

                answer = AddNumbers(1, 2)

                If you have a Subroutine they generally don't return anything. This is afterall the main difference between a Function and a Subroutine. Functions do soemthing AND return something. Given a Subroutine as such:

                Public Sub DisplaySomething(something As String)
                Debug.Print something
                End Sub

                Because this does not return anything it has to be called one of the following ways:

                DisplaySomething "Hello World."

                -or-

                Call DisplaySomething("Hello World.")

                This is one of the reasons that alot of people don't like VB. They feel confused by needing to rememebr if they have to use parens or not. Generally speaking i think that using the Call keyword is bad form though. Simply don't use parens and all is fine.


                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."


                N Offline
                N Offline
                Nick Seng
                wrote on last edited by
                #7

                Ray Cassick wrote: rememebr if they have to use parens or not. Tell me about it ! ;) And for someone like me who alternates between .net and vb6, it can get even more confusing! Thank god for .net's intellisense. I just don't bother with parens at all. :) Notorious SMC


                The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
                Get your facts first, and then you can distort them as much as you please Mark Twain

                1 Reply Last reply
                0
                • R Ray Cassick

                  But do you understand WHY this worked? I think that is more important. Using parens in VB mandates that your function RETURN something. For example:

                  Public Function AddNumbers(numOne As Integer, numTwo As Integer) As Ineteger

                  Dim retVal as Integer

                  retVal = numOne + numTwo

                  AddNumbers = retVal

                  End Function

                  This function would be called like so:

                  Dim answer As Integer

                  answer = AddNumbers(1, 2)

                  If you have a Subroutine they generally don't return anything. This is afterall the main difference between a Function and a Subroutine. Functions do soemthing AND return something. Given a Subroutine as such:

                  Public Sub DisplaySomething(something As String)
                  Debug.Print something
                  End Sub

                  Because this does not return anything it has to be called one of the following ways:

                  DisplaySomething "Hello World."

                  -or-

                  Call DisplaySomething("Hello World.")

                  This is one of the reasons that alot of people don't like VB. They feel confused by needing to rememebr if they have to use parens or not. Generally speaking i think that using the Call keyword is bad form though. Simply don't use parens and all is fine.


                  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."


                  J Offline
                  J Offline
                  Jason McBurney
                  wrote on last edited by
                  #8

                  Ray Cassick wrote: Generally speaking i think that using the Call keyword is bad form though. Simply don't use parens and all is fine. Really, humm, I prefer to use the parens because, I like to make it more blatently obvious that I am calling a function ( the keyword "call" helps with that blatentness) With default functions sometimes it is not immeadly obvious what one was thinking when they wrote their code.

                  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