Results 1 to 2 of 2

Thread: functions VS procedure

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    60

    Angry functions VS procedure

    I have an assignment for my VB.NET class to compare functions and procedures and it has me completely confused. I wrote a program that does a bunch of math, etc. and I am required to change the following to a procedure, but all it does is mess up the whole program. Can someone please help me out a little here? Thanks,

    Andrew

    Private Function GetFwtTax(ByVal sngWeekPay As Single) As _ Single

    -When I change Function to "Sub", the "As Single" shows erros.



    What all do I need to change in the code? I am thoroughly confused about the difference between a function and procedure. HELP!!!!!!!! Thanks!

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    A function returns a value (or CAN) where as a sub (procedure) doesn't (at least not directly). In a function the As blah blah blah is declaring the return type or the type of the value that it will return. Since a sub can't return a value like that it gives you an error. A sub can however change the value of an argument and expose those changes to the rest of the program if the argument is passed in ByRef.

    VB Code:
    1. 'function way
    2. Private Function GetFwtTax(ByVal sngWeekPay As Single) As Single
    3.    Return 1.1
    4. End Function
    5.  
    6. dim ret as Single=GetFwtTax(1) 'returns 1.1
    7.  
    8. 'sub way
    9. Private Sub GetFwtTax(ByVal sngWeekPay As Single,[b]ByRef[/b] sngReturn as Single)
    10.    sngReturn=1.1
    11. End Sub
    12.  
    13. dim ret as Single
    14. GetFwtTax(1,ret) 'ret now equals 1.1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width