Tips in VB.NET - Tip #5
How to get more than one value from a function or sub routine - Part IV
In this section, we will use the other way of getting more than one processed data from a function and a sub routine.
As you all know a sub routine can never return a value. But I can get some useful data from the sub routine also. I am, not kidding, you can get the data from a sub routine also.
Do you know anything about Call by Value and Call by Reference. If not read the article, click here to read the article.
In .Net it is done by ByVal and ByRef keyword. where if the parameter as passed using ByVal actually a copy of that is passed so any changes to the object will not affect the original. In the case of using ByRef the refernce of the object is sent to the function. so any changes to the parameter inside the function, will affect the original object also.
So, I can pass the objects using ByRef keyword to get the processed data from the function.
Now, lets modify the function we defined in the last article.
I need a function which will return me the day of the week, month in words, Hour, minutes and seconds in Integer.
Public Sub GetDateInfo(ByRef strday As String, _ ByRef intmon As Integer, _ ByRef inthour As Integer, _ ByRef intmin As Integer, _ ByRef intsec As Integer)
strday = Format(DateTime.Today, "dddd") intmon = Month(DateTime.Today) inthour = Hour(DateTime.Now) intmin = Minute(DateTime.Now) intsec = Second(DateTime.Now)
End Sub
Try using the above function.
If any one of you know any way other than this ways. Please Mail me. Note This hold good for both C#, VB.Net
Please send me your suggestion and feedback to sadhasivam1981@yahoo.com.
Please vist http://sadhasivam.t35.com
Every Features has a purpose Finding it leads to great benefits
|
No responses found. Be the first to respond and make money from revenue sharing program.
|