Thread: what is the difference between procedural and function in Visual basic?

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    18

    what is the difference between procedural and function in Visual basic?

    hi,A little explanation needs here for the question that i wanna?
    pls.....whoever knows the answer, thanks ))

  2. #2
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    if i understand the question, procedural means you're just putting line after line of code... with functions, you can call the function time and time again instead of rewriting all the code repeatedly. (ie. it's time saving and efficient)

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    I guess you mean the difference between a procedure and a function in VB. In general, a function is a block of code that gets parameters and after running it's code returns a value to the calling code. A procedure is just a block of code that can be called without returning a value.

    Note that you can call a function and not use it's value, but it will always return it and therefor is still considered a function.

    In VB, you have to use braces with functions that return a value if you use this value. If you don't use it or call a procedure that by definition has no return value, braces are not allowed.
    ( crazy concept )
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    yeah... i hate that... i always mess that up..

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    18

    Can u provide some sample code?

    hi,can u provide some sample code to differentiate the procedural and function in VB? plssssssssssss

  6. #6
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    Code:
    For a procedure you have:
    
    Sub swap(int a, int b)
    
        Dim c As Integer
        c = a
        a = b
        b = c
        
    End Sub
    
    For a function you have:
    
    Function sum(int a, int b) As Integer
    
        sum = a + b
    
    End Function
    To call a function you write:

    Dim result as integer
    result = sum(23,45)

    To call a procedure you write:

    Dim first as integer
    Dim second as integer
    first = 23
    second = 34
    swap first, second

    And it's not "procedural". It is "procedure". Procedural is a programming method on which VB relies heavily. Procedural programming is programming based on procedures and functions when opposed to Object Oriented Programming (OOP) where classes, property functions and methods are used.
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

Popular pages Recent additions subscribe to a feed