WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Functions for Manipulating Arrays

 Keywords: Array Search Convert String ArraySearchLinear_WW ArrayBinarySearch_P6C ArrayToDlmStr_WW

Array Manipulation UDFs

ARRAYFUNCTIONS.ZIP

As part of a recent project, I created several new functions to manipulate arrays.

- ArraySearchLinear_WW is a simple function for performing a linear search of an array. In case you haven't taken a good Computer Science course in Algorithms, you should confine your use of this function to small arrays. Its original name was ArraySearchBruteForce_WW. Nevertheless, it's the only option if your array is unsorted.

- ArrayBinarySearch_P6C performs a classic binary search on any column of an array of two dimensions, returning the index (array subscript) of the matching row, or -1 (an invalid subscript) if there is no match. In order to use this function, your array must be sorted. This is a design limitation of the binary search algorithm, itself.

- ArrayToDlmStr_WW is the inverse of Arrayize(), with a twist. You can exclude one or more rows or columns. I added the capability to discard rows so that I can use this function to efficiently persist the array returned by FileInfoToArray() to a file, adding my own header row. BTW, I know that I could have also simply replaced the contents of the first row, and called ArrayFilePut(), but I didn't think of doing that until just now, as I was writing this message. At the time, I was thinking that I already had the headings, in another array, and that I didn't want to create a brand new array (potentially a very large one, at that!), to get the job done.

Two of the three functions have built-in error handlers, working off IntControl 73. Both of them display error messages. Since I use an extender function to call the MessageBoxA function, in the Windows API (the real message box, as the documentation for the WILx extender says), which you may not have at your disposal, I provided alternatives, as follows.

1) xMessageBox, from the aforementioned extender

2) My MessageBox_P6C UDF, which calls the real Message Box (MessageBoxA) via DLLCall.

3) Message, the native WinBatch function, which displays a plain box, without an icon.

I've rolled all three functions into a single Zip file, along with my MessageBox_P6C function, and a fifth include file, MsgBox_CONSTANTS_P6C.WIL, which defines all of the MessageBox constants documented in the Windows Platform SDK.

David Gray
WizardWrx
http://www.wizardwrx.com/
You are more important than any technology we may employ. 

Article ID:   W17674
Filename:   Functions for Manipulating Arrays .txt
File Created: 2019:08:14:09:06:18
Last Updated: 2019:08:14:09:06:18