We help IT Professionals succeed at work.

Help understanding sub procedures

Frank Freese
Frank Freese asked
on
Experts,
I've search the Net and have books but to no avail in my understanding of naming sub procedures and the options with then and when to use them and how. The code between the sub and end sub I can handle (weird isn't it). It's a real senior moment for me and it is frustrating as well. Please point me in a direction to clear this up for me. Someplace that makes sense......
Thank you
Comment
Watch Question

Author

Commented:
It is the various arguments I'm having a problem with

Author

Commented:
Are there only two arguments to contended with in Visual Studio VB for a sub procedure:
ByVal and ByRef?
Most Valuable Expert 2012
Top Expert 2014

Commented:
> my understanding of naming sub procedures

You can give the stored procedure any name that you like. The only guideline is that it should a descriptive of what it does. For example, if you have code in a sub that saves customer information to database, you would usually name it SaveCustomer.

>the options with then and when to use them and how

Assuming that you are talking about Parameters (stuff inside parenthesis), these are the values/objects you want to pass to the function for its use. For example, if you have a function that loads a customer record, how would you tell it which customer record to load? By passing a customerID as parameter.
Most Valuable Expert 2012
Top Expert 2014

Commented:
>Are there only two arguments

Those are not arguments. Those are used to specify whether to pass the actual variable or its copy to the function.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Follow-up to CodeCruiser's comments:

    ByRef vs. ByVal
    Optional
    ParamArray

Author

Commented:
Arguments was the only term I saw used.

As I understand, in the example you gave for passing a customerID as a parameter it would look like this?

Sub CustomerNumber(ByRef CustomerID As Double)

Meaning that the CustomerNumber would be dynamic?

If I did this
Sub CustomerNname(ByVal CustName As String)
and had an input box that captured the CustName it would be static unless I entered in a new customer name? Am I that confused?
Most Valuable Expert 2012
Top Expert 2014
Commented:
In my understanding, a function/sub would be static if it returned/did the same thing everytime you called it. So whether you specify the Customer/Name as argument or ask the user to supply it, its not static.

>Sub CustomerNumber(ByRef CustomerID As Double)

Value types are usually passed as ByVal unless there is a good reason not to. If you were to change the CustomerID within the above function, the changes would be seen elsewhere as well where the same original value is being used.

Author

Commented:
ok...I'll have to work with them some more but I believe you all have helped me to move forward, Thanks

Author

Commented:
thank you