Effettuare la ricerca lineare sugli elementi dell'array
<%@ Page Language="vb" %>
<HTML>
<HEAD>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myArray As String() = {"a", "b", "c", "d", "e", "f", "g"}
Dim posizione As Integer = RicercaLineare("d", myArray)
If posizione > -1 Then
Response.Write("Trovato in posizione " & posizione)
Else
Response.Write("Non trovato")
End If
End Sub
Function RicercaLineare(ByVal myValue As String, ByVal myArray As String()) As Integer
Dim i As Integer
For i = 0 To myArray.Length - 1
If myArray(i) = myValue Then
Return i
End If
Next
Return -1
End Function
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
</form>
</body>
</HTML>