Tips in VB.NET - Tip #4
How to get more than one value from a function or sub routine - Part III
In my previous article we have seen using the array and collection object to get more than one processed value from a function.
In this section, we will see one more method of getting the processed data from the function.
I believe most of you will be familer with structure. If not take a quick look at my previouse article Sturcture in VB.NET Part I, Part II, Part III, Part IV, Part V.
Now Let see how to implement the structure to get more than one processed data from the function.
As we all know structure is a collection of one or more variable, possibly of different data types, grouped together under a single name for convenient handling.
So, we can group all the data which needs to be returned by the function, into a Structure and then we can return the structure object.
So, using the structes we can indirectly get more than one processed data from the function.
Now, lets see how the function which we built in our previous article can be changed to use the structure.
I need a function which will return me the day of the week, month in words, Hour, minutes and seconds in Integer.
Structure DateData Public strday As String Public intmon As Integer Public inthour As Integer Public intmin As Integer Public intsec As Integer End Structure
Public Function ReturnDateInfo() As DateData Dim dd As New DateData() dd.strday = Format(DateTime.Today, "dddd") dd.intmon = Month(DateTime.Today) dd.inthour = Hour(DateTime.Now) dd.intmin = Minute(DateTime.Now) dd.intsec = Second(DateTime.Now) Return dd End Function
Is that not simple.
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.
|