Delete an Element from an array
Traversed by index:
For j As Integer = i To UBound(MyArray) MyArray(j) = MyArray(j + 1) Next j ReDim Preserve MyArray(UBound(MyArray) - 1)
Traversed by element ('for each' loop):
Public Function RemoveElementFromArray(ByVal objArray As System.Array, ByVal objElement As Object, ByVal objType As System.Type) Dim objArrayList As New ArrayList(objArray) objArrayList.Remove(objElement) Return objArrayList.ToArray(objType) End Function
Add an element to an array
Private Sub AddElementToStringArray(ByRef OriginalStringArray As String(), ByVal stringToAdd As String) ReDim Preserve OriginalStringArray(OriginalStringArray.Count) OriginalStringArray(OriginalStringArray.Count - 1) = stringToAdd End Sub
Convert a control to it's HTML equivalent
Public Function RenderMe(ctrl As Control) As String Dim sb As New StringBuilder() Dim tw As New System.IO.StringWriter(sb) Dim hw As New HtmlTextWriter(tw) ctrl.RenderControl(hw) Return sb.ToString() End Function
Combine two arraylists
ArrayList list1 = new ArrayList(); ArrayList list2 = new ArrayList(); list1.Add("HTML"); list1.Add("XML"); list2.Add("CSS"); list2.Add("PHP"); list1.AddRange(list2);
Use the System.Threading.Tasks
Imports System.Threading.Tasks ... Dim t1 = New Task(Sub() BGWorker(bargs)) t1.Start()
Read an XML Configuration file
Dim reader As XmlTextReader = New XmlTextReader("Construct_AD_DB.config") Dim entry As New Hashtable Dim categoryName As String = "" Do While reader.Read If reader.NodeType = XmlNodeType.Element Then If reader.Name <> "add" And reader.Name <> "configuration" Then categoryName = reader.Name ElseIf reader.Name = "add" Then If reader.AttributeCount > 0 Then Dim content As New Hashtable While reader.MoveToNextAttribute content.Add(reader.Name, reader.Value) End While entry.Add(content("name"), content) End If End If ElseIf reader.NodeType = XmlNodeType.EndElement Then If entry.Count > 0 Then vars.Add(categoryName, entry) entry = New Hashtable End If End If Loop
<?xml version="1.0"?> <configuration> <Domains> <add name="Australia" FQDN="australia.centigo.com"/> <add name="Europe" FQDN="europe.centigo.com"/> <add name="Asia" FQDN="asia.centigo.com"/> <add name="USA" FQDN="usa.centigo.com"/> </Domains>
Iterate a hashtable
Dim entry As Hashtable = vars("Domains") For Each element As DictionaryEntry In entry AddElementToStringArray(RDM, element.Value("FQDN")) Next