Important alert: (current site time 7/15/2013 8:46:14 AM EDT)
 

VB icon

Array Dump (Alias of PHP's var_dump()) Version 1

Email
Submitted on: 12/26/2005 9:38:44 PM
By: Stephen Mason  
Level: Intermediate
User Rating: By 1 Users
Compatibility: VB.NET
Views: 17074
 
     When working with arrays, there is no easy way, that i have found, to easily display a dump of the array while debugging. So this function dumps, an easy-to-read string version of all the objects in the array.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code 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 code (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 code 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 code or code's description.
				
//**************************************
// Name: Array Dump (Alias of PHP's var_dump()) Version 1
// Description:When working with arrays, there is no easy way, that i have found, to easily display a dump of the array while debugging. So this function dumps, an easy-to-read string version of all the objects in the array.
// By: Stephen Mason
//
// Inputs:Example:
Msgbox(var_dump(array))
//
// Returns:The code returns a string dump of the array
//
// Assumes:Make sure you dont just call the function other nothing will happen you need to use either:
Dim dump as string = var_dump(array)
or:
msgbox(var_dump(array))
Etc...
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=4340&lngWId=10//for details.//**************************************

'========================================================
 'Mason Solutions 
 'Stephen Mason
 'http://mason-solutions.co.uk
 'steve@mason-solutions.co.uk
 '$id = var_dump() V1
 '=========================================================
 Public Function var_dump(ByVal ar As Array)
Dim rm As String
Dim i As Integer = 0
If ar.GetType.IsArray = True Then
 rm &= "array(" & ar.Length & ") {" & vbCrLf
 For Each var As String In ar
rm &= Space(2) & "[" & i & "]=>" & vbCrLf
rm &= TypeName(var).Replace("()", "") & "(" & len(var) & ") "
If TypeName(var) = "array()" Then
 Dim v() As String
 v = var.Split("")
 rm &= var_dump(v) & vbCrLf
Else
 rm &= Chr(34) & var & Chr(34) & vbCrLf
End If
i += 1
 Next
 rm &= "}"
Else
 rm = "Error: Given array is not an array!!!"
 Throw New System.Exception("Given array is not an array!!!")
End If
Return rm
 End Function


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 code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

8/21/2007 10:49:50 AMSalem Al Shekaili

This is the translation to VB .Net. I made correactions to the second function.

Function beforefirst(ByVal sdata As String, ByVal before As String) As String
Return sdata.Substring(0, sdata.IndexOf(before))
End Function
Function afterfirst(ByVal sdata As String, ByVal after As String) As String
Return sdata.Substring((sdata.IndexOf(after) + after.Length), ((sdata.Length - after.Length) - sdata.IndexOf(after)))
End Function

(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 code, please click here instead.)
 

To post feedback, first please login.