VB6 isIn functionAuthor: Dave Date: 02.27.18 - 10:09pm So I have been coding up a bunch of these variant helper functions that operate generically on a bunch of different variable types for my dzrt library. Here is an isIn function that allows you to search strings, arrays, and collections for the needle you are looking for. It can optionally return the index of that item in an out variable. For strings index is string position. For arrays and collections it is the element index. collections also support object arguments. I think this will be handy alternative to having to search arrays and collections manually everytime. I will add this to my globals.cls which is a set of functions automatically added to the global namespace and accessible as a new language function as soon as you add a reference to the dzrt dll. Another example of this type of function is a readfile function which can load a file into either a byte array or string based on the variable type you pass it. MD5 functions which can automatically work on files, strings and byte arrays etc. Handy shortcuts all and really making the most of the vb variant datatype. Private Sub Form_Load() a = Array(1, 2, 3, 4, 5) Set b = New Collection b.Add 1 b.Add 2 b.Add 3 Dim index Debug.Print "Number variant array test: " & isIn(4, a, index) Debug.Print index Debug.Print "Number collection test: " & isIn(3, b, index) Debug.Print index Debug.Print "String test: " & isIn("test", "this is my test string!", index) Debug.Print index Set b = New Collection b.Add New Form1 b.Add Me Debug.Print "Object collection test: " & isIn(Me, b, index) Debug.Print index Debug.Print "double test: " & isIn(3.14, Array(7.15, 8, 3.14), index) Debug.Print index End Sub Comments: (0) |
About Me More Blogs Main Site |