We Recommend

Visual Basic 2008 Programmer's Reference Visual Basic 2008 Programmer's Reference
Visual Basic Orcas Programmer's Reference is a language tutorial and a reference guide to the upcoming Orcas release of Visual Basic. The tutorial provides basic material suitable for beginners but also includes in-depth content for more advanced developers.


Posted By

eeppeliteloop on 03/23/08


Tagged

array arrays push


Versions (?)


Array push


Published in: Visual Basic 


(VB6) Will push a given value to a given array.


  1. Public Sub array_push(ArrayName() As String, Element As String)
  2. ' Make Sure The Variable Passed Is An Array
  3. If IsArray(ArrayName) = False Then Exit Sub
  4. ' If We Get An Error Here, it's Probably Because the Array
  5. ' is dimensioned with no values set, so just make the first element
  6. On Error GoTo make_it
  7. ' Allocate A New Array Slot
  8. ReDim Preserve ArrayName(UBound(ArrayName()) + 1)
  9. ' Set The Value Of The New Array Indice To Element
  10. ArrayName(UBound(ArrayName())) = Element
  11. Exit Sub
  12.  
  13. make_it: ' Code Will Only Jump Here "on error"
  14. ReDim ArrayName(0)
  15. ArrayName(0) = Element
  16. End Sub

Report this snippet 

You need to login to post a comment.