Define page level variables (VB.net) : Variable Scope « Language Basics « ASP.Net






Define page level variables (VB.net)

<%@ Page Language="VB" %>
<script runat="server">
    Dim myFirstNumber, mySecondNumber As Integer
    
    Sub SetVarsToInitialValues()
      myFirstNumber = 7
      mySecondNumber = 8
    
      Label1.Text = myFirstNumber
      Label2.Text = mySecondNumber
    End Sub
    
    Sub Button1_Click(sender As Object, e As EventArgs)
      SetVarsToInitialValues()
      Label3.Text = myFirstNumber + mySecondNumber
    End Sub
    
    Sub Button2_Click(sender As Object, e As EventArgs)
      SetVarsToInitialValues()
      Label3.Text = myFirstNumber - mySecondNumber
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            <asp:Label id="Label1" runat="server">Label</asp:Label>
            &nbsp;+ 
            <asp:Label id="Label2" runat="server">Label</asp:Label>
            &nbsp;= 
            <asp:Label id="Label3" runat="server">Label</asp:Label>
        </p>
        <p>
            <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Add"></asp:Button>
            <asp:Button id="Button2" onclick="Button2_Click" runat="server" Text="Subtract"></asp:Button>
        </p>
    </form>
</body>
</html>

           
       








Related examples in the same category

1.Local variable inside a function (VB.net)
2.Page level variable and function level variable (VB.net)
3.Function Level variables (C#)
4.Page Level Variable (C#)
5.block-level variables (C#)