Visual Basic (VB6 and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

Visual Basic Library

This page was last updated on Saturday, November 24, 2001

Public Function AllBut(intItemList() As Integer, intI As Integer, intJtemlist() As Integer) ' Procedure : AllBut ' Description: Reduce a list by one element identified as a fixed index. ' By: Chris Greaves Inc. ' Inputs: Array of items to fit, index to an element. ' Returns: None. ' Assumes: The given index is within limits of the source array. ' Side Effects: None. ' Tested: By the calls shown below. ' Typical use for this is in removing one element of a listbox array. ' I load the listbox to an array to perfrom data manipulation. ' Later I load the array back to the list box. ' If I need to delete an item, this routine does the trick. ' The result ought to be one item shorter than the source. ReDim intJtemlist(1, UBound(intItemList, 2) - 1) ' Need to loop only on the items that will be returned, not on all the source items. Dim intJ As Integer For intJ = 0 To UBound(intItemList, 2) - 1 If intJ >= intI Then ' we continue to skip past the unused item intJtemlist(0, intJ) = intItemList(0, intJ + 1) intJtemlist(1, intJ) = intItemList(1, intJ + 1) Else ' we pass these items right across intJtemlist(0, intJ) = intItemList(0, intJ) intJtemlist(1, intJ) = intItemList(1, intJ) End If Next intJ 'Sub TESTAllBut() 'Dim intItemList() As Integer 'Dim intJtemlist() As Integer 'ReDim intItemList(1, 3) 'intItemList(0, 0) = 10 'intItemList(0, 1) = 20 'intItemList(0, 2) = 30 'intItemList(0, 3) = 40 'Call AllBut(intItemList, 2, intJtemlist) '' intJtemlist will be like intItemList except item(3)=30 will be missing. 'MsgBox intJtemlist(0, 0) ' 10 'MsgBox intJtemlist(0, 1) ' 20 'MsgBox intJtemlist(0, 2) ' 40 'End Sub End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Monday, November 19, 2001

 

 

Hosted by www.Geocities.ws

1