Important alert: (current site time 5/22/2013 2:34:22 PM EDT)
 

article

Quick and easy Array Constructor for VB5/6

Email
Submitted on: 4/27/2012 5:22:28 PM
By: Rde 
Level: Intermediate
User Rating: By 2 Users
Compatibility: VB 5.0, VB 6.0
Views: 4298
author picture
 
     Quick and easy Array Constructor for VB5 and 6. Substitutes the VB6 Array() function.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				
' Quick and easy String Array Constructor for VB5/6
' StrArray sArr(), 0, "A", "B", "C", "D"
' This subroutine is a string substitute for the VB6 variant Array constructor.
' The paramarray argument is still an array of variants, but is temporary and
' is a valid argument for VB5.
' StrArray sArr(), lb, paramarray
' The sArr() argument is any declared string array - empty or otherwise.
' The lb argument specifies the desired lower-bound of the first element.
' The paramarray argument is a comma-delimited list of strings that
' are assigned to the elements of the passed array. If no string
' arguments are specified, an un-initialized array is returned.
' Dim sArr() As String
' StrArray sArr(), 1, "A", "B", "C"
' Debug.Print sArr(2) ' "B"
Sub StrArray(sArr() As String, ByVal lb As Long, ParamArray Strings())
Dim i As Long, ub As Long
Erase sArr()
ub = UBound(Strings)
If ub = -1 Then Exit Sub
ReDim sArr(lb To lb + ub) As String
Do Until i > ub
 sArr(i + lb) = Strings(i)
 i = i + 1
Loop
End Sub
' Quick and easy Long Array Constructor for VB5/6
' LongArray lArr(), 0, 100, 200, 300, 400
' This sub is a long integer substitute for the VB6 variant Array constructor.
' The paramarray argument is still an array of variants, but is temporary and
' is a valid argument for VB5.
' LongArray lArr(), lb, paramarray
' The lArr() argument is any declared long array - empty or otherwise.
' The lb argument specifies the desired lower-bound of the first element.
' The paramarray argument is a comma-delimited list of whole numbers that
' are assigned to the elements of the passed long array. If no paramarray
' arguments are specified, an un-initialized array is returned.
' Dim lArr() As Long
' LongArray lArr(), 1, 181, 182, 183
' Debug.Print lArr(2) ' 182
Sub LongArray(lArr() As Long, ByVal lb As Long, ParamArray Longs())
Dim i As Long, ub As Long
Erase lArr()
ub = UBound(Longs)
If ub = -1 Then Exit Sub
ReDim lArr(lb To lb + ub) As String
Do Until i > ub
 lArr(i + lb) = Longs(i)
 i = i + 1
Loop
End Sub


Other 52 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/28/2012 2:31:40 AMDave Carter

Gonna be real handy, Thanks Rohan :)
(If this comment was disrespectful, please report it.)

 
4/29/2012 7:09:22 AMKenneth Buckmaster

I usually use a string and split eg

LongArray lArr(), 1, "181*182*183"
(If this comment was disrespectful, please report it.)

 
4/30/2012 4:52:28 AMJM Amaro

Wow! what a easy array logics and formulas you've done, but it is usable and enable in array & logical statement lessons in programming:)Nice Work, GodBlessYou:)
(If this comment was disrespectful, please report it.)

 
5/6/2012 8:58:18 AMRde

Thanks guys

Yes Kenneth your way is brilliant - simple to code and does not create a variant array. I may update this...

Happy coding,
Rd :)
(If this comment was disrespectful, please report it.)

 
5/30/2012 11:56:23 PMLex

Умно, умно ... мне очень понравилась функция ...
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.