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 AppendToArray(strAr() As String, str1 As String, Optional str2) ' Procedure : AppendToArray ' Description: Increase an array by one element identified as a (pair of) value(s) ' By: Chris Greaves Inc. ' Inputs: Array of items to fit, pair describing an element. ' Returns: None. ' Assumes: The items exist within the source array ' Side Effects: None. ' Tested: By the calls shown below. ' This procedure operates on both 1- and 2-dimensional arrays, ' but if you try with any other dimension you'll get a MsgBox error! If intRank(strAr) = 1 Then ' append the first supplied string to the end of the array. ReDim Preserve strAr(UBound(strAr) + 1) strAr(UBound(strAr)) = str1 Else If intRank(strAr) = 2 Then ' append both supplied strings to the end of the array. ReDim Preserve strAr(UBound(strAr, 1), UBound(strAr, 2) + 1) strAr(0, UBound(strAr, 2)) = str1 strAr(1, UBound(strAr, 2)) = str2 Else MsgBox "catastrophic failure in ""AppendToArray""" End If End If 'Sub TESTAppendToArray() 'Dim strAr() As String ' '' test of 1-dimensional array 'ReDim strAr(2) 'strAr(0) = "a" 'strAr(1) = "b" 'strAr(2) = "c" 'Call AppendToArray(strAr, "alpha", "beta") 'MsgBox strAr(UBound(strAr)) ' alpha ' '' test of 2-dimensional array 'ReDim strAr(1, 2) 'strAr(0, 0) = "a" 'strAr(0, 1) = "b" 'strAr(0, 2) = "c" 'strAr(1, 0) = "1" 'strAr(1, 1) = "2" 'strAr(1, 2) = "3" 'Call AppendToArray(strAr, "alpha", "beta") 'MsgBox strAr(0, UBound(strAr, 2)) ' alpha 'MsgBox strAr(1, UBound(strAr, 2)) ' beta ' '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