Return string type value from function : Function « Class Module « VB.Net Tutorial






Public Class Tester

    Shared Sub Main()
        Dim iFirstDay As Integer
        Dim iLastDay As Integer
        Dim iCurrentDay As Integer

        iFirstDay = 2
        iLastDay = 6
        For iCurrentDay = iFirstDay to iLastDay
            System.Console.WriteLine(WeekdayName(iCurrentDay))
        Next iCurrentDay

    End Sub

    Shared Function WeekdayName(ByVal iDayNumber As Integer) As String
        Dim sWeekdayName As String

        Select Case iDayNumber
            Case 1
                sWeekdayName = "Sunday"
            Case 2
                sWeekdayName = "Monday"
            Case 3
                sWeekdayName = "Tuesday"
            Case 4
                sWeekdayName = "Wednesday"
            Case 5
                sWeekdayName = "Thursday"
            Case 6
                sWeekdayName = "Friday"
            Case 7
                sWeekdayName = "Saturday"

            Case Else
                sWeekdayName = "Invalid Day Number"
        End Select
        Return sWeekdayName
    End Function
End Class
Monday
Tuesday
Wednesday
Thursday
Friday








6.2.Function
6.2.1.Define function in a Module
6.2.2.Pass Double to a function
6.2.3.Calculates the power of a value, defaults to square
6.2.4.Assign function return value to variables
6.2.5.Call function as a statement
6.2.6.Use function in If statement
6.2.7.Function procedure to square a number.
6.2.8.Finds the maximum of three numbers input
6.2.9.Function with string return
6.2.10.Return double type value from Function
6.2.11.Define function and call it in a Module
6.2.12.Functions with different parameter number
6.2.13.Return string type value from function