Fungsi in_array di Visual Basic ( VB6 )

[sourcecode language=”vb”]
Public Function in_array(kata, kumpulanKata) As Boolean
‘untuk variabel kumpulanKata harus Anda perhatikan tanda separasinya
‘disini saya menggunakan koma
Dim i As Integer, ret As Boolean
Dim haystack() As String
haystack() = Split(kumpulanKata, ",") ‘tanda separasi
ret = False ‘set nilai boolean awal
For i = LBound(haystack) To UBound(haystack)
If haystack(i) = needle Then ret = True
‘jika ada kata yang ditemukan boolean akan bernilai true
Next i
in_array = ret
End Function

Private Sub Form_Load()
Dim kumpulanKata as String
Dim cariKata as String

kumpulanKata = "rendra,kurniawan,ika,aku"
cariKata = "ika"

If in_array(cariKata, kumpulanKata) Then
MsgBox "Yaph kata ditemukan"
Else
MsgBox "Maaf, kata yang Anda cari tidak ada"
End If
End Sub