How to Use a While Loop in Visual Basic.NET
1. Open a Microsoft Visual Studio.
2. Click File > New > Web Site.
3. Choose Visual Basic for installed templates and select ASP.NET Empty Web Site.
4. Right click on the project solution. Click Add New Item.
5. Choose Visual Basic for installed templates and select Web Form. Keep the file name as Default.aspx.
6. You will see code already in Default.aspx. There is a set of div tags. Inside, enter a new set of p tags to create a new paragraph.
We chose Server Intellect for its cloud hosting, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
<%@ 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>
<p>
</p>
</div>
</form>
</body>
</html>
7. Go to toolbox, click and drag a Button tool under the Label tool we just created. Change the Text of Button to “Use While Loop”
8. Go to toolbox, click and drag a Label tool inside the paragraph tag we created. Delete the Text in Label.
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.
<%@ 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>
<p>
<asp:Button ID="Button1" runat="server" Text="Use While Loop"/>
<asp:Label ID="Label1" runat="server"></asp:Label>
</p>
</div>
</form>
</body>
</html>
10. Click on Default.aspx and switch to Design view.
11. You will see an empty Label and a Button with the words “Use While Loop”. Double click on the button.
This will take you to Default.aspx.vb. This is where we enter coding specifically for Visual Basic.
12. You should see a method called Button1_Click.. Inside this method we will enter While Loop that has a number start at 0 and end until it is less than or equals to 10.
We stand behind Server Intellect and their support team. They offer dedicated servers, and they are now offering cloud hosting!
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim count = 0
While (count <= 10)
count = count + 1
End While Label1.Text = count
End Sub
End Class
The while loop is an important and simple function for keeping track of when an action should take place. Like I mentioned earlier, if you understand how to use the while loop, learning the other loops in visual basic and other various programming languages should be a breeze.
WebSite18.zip
