VB.NET - Calling a method within method - Asked By Elvin Pena on 31-Jul-13 01:00 PM

Having issue with when I am basically having an app that when a textbox enters a email address from array, array is iterated to search for condition if true then displays the other information like Hair, Language, and Gender (also in array). Now if there is nothing then display "No data found". Now my issue here is that I have the following code, but cannot be able to call a function from button click to another function, which that function calls another function to have the data displayed  or show message.
My code is below: 
Imports System.Collections
Imports System.Web.Mail
Imports System
Imports System.Net.Sockets
Imports System.Text
Imports System.IO

Public Class WebForm1
    Inherits Global.System.Web.UI.Page

 Private Function DetectServerSettings(ByRef emailaddress As String, ByRef Hair As String, ByRef Age As Integer,ByRef Language As String, ByRef USCitizen As Boolean)
        'Should have no knowledge of test cases and controls used. here is as email address entered, display data.
        Return Hair
        Return Language
        Return Age
        Return USCitizen
    End Function

'error happens here converting label type to string when data is integer.
    Overloads Sub btn_Click(sender As Object, e As EventArgs) Handles btnCheckList.Click, btnCheckList.Click
        DetectServerSettings(emailaddress:=lblMessage1.ToString(), Hair:=lblMessage3.ToString(), Language:=lblMessage4.ToString(), Age:=lblMessage5.ToString(), USCitizen:=lblMessage6.ToString())
    End Sub

    Private Sub GetInfo(ByRef emailaddress As String, ByRef pwd As String, ByRef HairAs String, ByRef Language As String, ByRef Age As Integer, ByRef USCitizen As Boolean)
        Dim arrProperties As Array = { {"sample@sample.com", "Black", "Spanish", 2000, No},
                                   {"sample2@sample2.com", "Blonde", "English", 25, True}}

        Dim i As Integer
        For i = 0 To arrProperties.Length - 1
            If arrProperties.Equals(emailaddress) Then ' And arrProperties.Equals(pwd)
                Console.WriteLine("Hair: " + Hair+ "/n" + "Language: " + Language+ "/n" + "Age: " + Age+ "/n" + "US Citizen? : " + USCitizen+ "/n")
            ElseIf arrProperties Is Nothing Then
                Console.WriteLine("Sorry, No Data Found.")
            End If
    End Sub
End Class
Robbe Morris replied to Elvin Pena on 31-Jul-13 01:06 PM

USCitizen parameter is defined as a Boolean but you are passing in a string.

DetectServerSettings can only return one value.  Methods cannot return multiple types.  You'd have to create a container for all of these other results and return the container from the method instead.
Elvin Pena replied to Robbe Morris on 31-Jul-13 05:05 PM
Can you provide an example of this creation of container to be used as Parameter for contents in method?
Robbe Morris replied to Elvin Pena on 31-Jul-13 05:51 PM
Create a class called "MyContainer" and add public instances of your other classes that hold results.  In this case, you set MyClassType1 property values equal to whatever goes there.  Same thing with MyClassType2.  This enables you to pass around everything in a single instance of MyContainer.  Now, you'd want to use realistic class types and not the bs ones I've used here.  This is C# of course.  You'd want to do the same thing in VB.NET.

public class MyContainer
    public ClassType1 MyClassType1 = new ClassType1();
    public ClassType2 MyClassType2 = new ClassType2();