Functions are a very useful tool to know. It can make coding a lot easier, especially for long time consuming coding. When I first started coding, I did not like the idea of functions because I felt it was hard and a waste of my time. Needless to say I’ve changed my mind since then. I’ve learned that functions are very useful and not hard at all, you just have to know where to write it and how to call it. For example, if I wanted to find out the square root of a number, multiply it by 2 and divide it by 3. What if we needed to do this for three different numbers, what do you think would be faster, calculating it in a function once and calling the function all three times or manually coding the answers all three times? I hope you said doing the calculation in a function because that is correct.

1. Open Microsoft Visual Studio.

2. Click File > New > Web Site.

3. Choose Visual Basic in installed templates, select ASP.NET Empty Web Site and click OK.

You will be in the Source View of Default.aspx.

4. From the toolbox, click and drag a Button and place it in the space between the div tags. In the toolbox click and drag a Label tool and repeat, but this time place it right under the button you just placed.

Yes, it is possible to find a good web host. Sometimes it takes a while to find one you are comfortable with. After trying several, we went with Server Intellect and have been very happy thus far. They are by far the most professional, customer service friendly and technically knowledgeable host we’ve found so far.

Code Block
Default.aspx
Change the text of button to “Click for Function”. Delete the text entirely from the label.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Click for Function" />
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>
5. Click on Default.aspx and switch to Design view.

6. Double click on the button “Click for Function”. This will open Default.aspx.vb and you will see a protected sub Button1_Click.

After the End Sub of  the Button1_Click method but before the End class we will write a function called GetString() that will return the string ”I’m from the Function.”

Need help with cloud hosting? Try Server Intellect. We used them for our cloud hosting services and we are very happy with the results!

Code Block
Default.aspx.vb
We set the text of Label1 to call the function GetString() which returns “I’m from the Function”.
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgsHandles Button1.Click
        Label1.Text = GetString()
    End Sub

    Function GetString() As String

        Return "I'm from the Function"

    End Function

End Class
Run the application and you will see a blank page with the Click for Function button. When you click on the button, Label1.Text calls the GetString() function, the function returns the string I’m from the Function, which becomes the text for Label1 and outputs it.



This is a simple example of a function, but if you understand how a function is formed and called, you can make a function that takes care of some very heavy code and it will be available to call whenever you need. Look over it more than once if you have to, its better to put time in and understand it than to dismiss it.

WebSite34.zip