web 2.0

VB.NET & Array

VB.NET & Array - Array() : This a learn and example script how to use Array data types (Static Array , Dynamic Array , Session and Array). This example code can to Applied for .NET  Technology all Application , Eg : ASP.NET Web Application , Windows Form Application , Console Application   , etc…

ShotDev Focus:
- ASP.NET(vb.net) & Array , Static Array , Dinamic Array , Session and Array.

Example 1. How to use Static Array and Dynamic Array

Static Array

AspNetStaticArray.aspx

<%@ Import Namespace="System.Data"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim myArr(3) As String
myArr(0) = "Weerachai Nukitram"
myArr(1) = "Surachai Sirisart"
myArr(2) = "Adisorn Bunsong"
myArr(3) = "Surapong Chunsiripun"

Dim i As Integer
For i = 0 To UBound(myArr)
Me.lblText.Text = Me.lblText.Text & "(" & i & ")" & myArr(i) & "<br>"
Next
End Sub
</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="server"></asp:Label>
</form>
</body>
</html>

Screenshot

 ASP.NET(vb.net) & Array
.
.
Dynamic Array

AspNetDynamicArray.aspx

<%@ Import Namespace="System.Data"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim myArr() As String

Dim intCount  As Integer = 3
ReDim myArr(intCount)

myArr(0) = "Weerachai Nukitram"
myArr(1) = "Surachai Sirisart"
myArr(2) = "Adisorn Bunsong"
myArr(3) = "Surapong Chunsiripun"

Dim i As Integer
For i = 0 To UBound(myArr)
Me.lblText.Text = Me.lblText.Text & "(" & i & ")" & myArr(i) & "<br>"
Next
End Sub
</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText"    runat="server"></asp:Label>
</form>
</body>
</html>

Screenshot

 ASP.NET(vb.net) & Array
.
.

Example 2. How to use Split function and Convert string to array

AspNetArraySplit.aspx

<%@ Import Namespace="System.Data"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

Dim myString As String = "Weerachai Nukitram,Surachai Sirisart,Adisorn Bunsong,Surapong Chunsiripun"
Dim myArr As Array = Split(myString,",")

Dim i As Integer
For i = 0 To UBound(myArr)
Me.lblText.Text = Me.lblText.Text & "(" & i & ")" & myArr(i) & "<br>"
Next
End Sub
</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="server"></asp:Label>
</form>
</body>
</html>

Screenshot

 ASP.NET(vb.net) & Array
.
.

Example 3. How to use Session and array

AspNetArraySession1.aspx

<%@ Import Namespace="System.Data"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim myArr(3) As String
myArr(0) = "Weerachai Nukitram"
myArr(1) = "Surachai Sirisart"
myArr(2) = "Adisorn Bunsong"
myArr(3) = "Surapong Chunsiripun"

Session("mySession") = myArr

Me.lblText.Text = "Array & Session Created <a href=AspNetArraySession2.aspx>click here</a> to view"
End Sub
</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText"    runat="server"></asp:Label>
</form>
</body>
</html>

AspNetArraySession2.aspx

<%@ Import Namespace="System.Data"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim myArr As Array

myArr = Ctype(Session("mySession"),Array)

Dim i As Integer
For i = 0 To UBound(myArr)
Me.lblText.Text = Me.lblText.Text & "(" & i & ")" & myArr(i) & "<br>"
Next
End Sub
</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText"    runat="server"></asp:Label>
</form>
</body>
</html>

Screenshot

 ASP.NET(vb.net) & Array

 ASP.NET(vb.net) & Array
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (2 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.