Array Class Set For Dynamic Arrays

This is a class I wrote for creating dynamic arrays. It's very easy to use and provides a flexable way of using...

arrays. I don't know why more people don't use classes in script. It makes all code much easier and reusable. 'Past the class in your Declarations Class ArraySets Public Value() As String Public TotalElements As Integer Sub Init TotalElements = 0 Redim Value(1 To 1) As String End Sub Sub AddElement(NewValue As String) TotalElements = TotalElements + 1 Redim Preserve Value(1 To TotalElements) As String Value(TotalElements) = NewValue End Sub Function Search(SearchFor As String) As Integer Dim CurrentLabelEntry As Integer CurrentLabelEntry = 1 'a Forall is faster Forall c In Value If Ucase(c) = Ucase(SearchFor) Then Exit Forall CurrentLabelEntry = CurrentLabelEntry + 1 End Forall Search = CurrentLabelEntry End Function End Class '--------- END DECLARATION SECTION ---------- 'Paste this code in your Sub or Function Dim WhereIs As Integer Dim Names As ArraySets 'Declare your Class Set Names = New ArraySets 'Set your class 'Init your class array Call Names.Init 'Add elements to the array Names.AddElement("Kevin") Names.AddElement("Wally") Names.AddElement("Peter") 'Search for a element WhereIs = Names.Search("Wally") Print Names.Value(WhereIs) + " is in position nr : " + Cstr(WhereIs) 'Display the values in the array For CurrentName = 1 To Names.TotalElements Print Names.Value(CurrentName) Next 'Reset the array Call Names.Init

This was first published in November 2000

Dig Deeper



Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...