Function that returns a value in Visual Basic .Net

Download
Download is available until [expire_date]
  • Version
  • Download 47
  • File Size 110.32 KB
  • File Count 1
  • Create Date March 8, 2016
  • Last Updated March 8, 2016

Function that returns a value in Visual Basic .Net

Function that returns a value in Visual Basic .Net

An example of self-defined function in vb.net that returns a value.

In this program we have created two functions, the first one is a function that returns a value of an integer type, and the second one is function that returns string type.

Kindly refer to the source code below or download the project for you to understand better.

Source code:

Public Class Form1

    Private Function ComputeSum(ByVal a As Integer, ByVal b As Integer) As Integer
        Dim result As Integer
        result = a + b
        ComputeSum = result
        MessageBox.Show(ComputeSum)
    End Function

    Private Function GetFullname(ByVal a As String, ByVal b As String) As String
        Dim result As String
        result = b & ", " & a
        GetFullname = result
        MessageBox.Show(GetFullname)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Or IsNumeric(TextBox1.Text) = False Then
            MessageBox.Show("Please enter a numeric value.")
            TextBox1.Focus()
        ElseIf TextBox2.Text = "" Or IsNumeric(TextBox2.Text) = False Then
            MessageBox.Show("Please enter a numeric value.")
            TextBox2.Focus()
        Else
            ComputeSum(TextBox1.Text, TextBox2.Text)
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox3.Text = "" Then
            MessageBox.Show("Please enter lastname.")
            TextBox3.Focus()
        ElseIf TextBox4.Text = "" Then
            MessageBox.Show("Please enter firstname.")
            TextBox4.Focus()
        Else
            GetFullname(TextBox3.Text, TextBox4.Text)
        End If
    End Sub

End Class
, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.