User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 397,698 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,517 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser:
Feb 22nd, 2006
Views: 4,891
The Relative of push is pop. Pop removes the last item in an Array, and returns the value into a single (scalar) variable. Again, due To VB Limitations, this one works on strings.
visualbasic Syntax
  1. Public Function spop(ArrayName() As String) as string
  2. ' /* Make Sure the Variable Passed Is An array */
  3. If IsArray(ArrayName) = False Then spop = "not array"
  4.  
  5. ' /* Get The Last Value In The Array */
  6. RetVal = ArrayName(UBound(ArrayName()))
  7.  
  8. ' /* Set The Last Element Of The Array To Nothing */
  9. ArrayName(UBound(ArrayName())) = vbNullString
  10.  
  11. ' /* Check If We Are Working With The Only Element In The Array */
  12. If UBound(ArrayName()) = 0 Then
  13. ' /* If So, Remove The Array */
  14. Erase ArrayName()
  15. Else
  16. ' /* Reset the size of the array to 1 less than it was */
  17. ReDim Preserve ArrayName(UBound(ArrayName()) - 1)
  18. End If
  19.  
  20. ' /* return The Value Of The last element of the array before we removed it */
  21. spop = RetVal
  22.  
  23. End Function
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 1:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC