C# Snippets
Array_Combine2SingleArrays
Public Shared Function Combine2SingleArrays(ByVal sArray1Name As String, _
ByVal sngArrayName1() As Single, _
ByVal sArray2Name As String, _
ByVal sngArrayName2() As Single, _
Optional ByVal ilower As Integer = -1, _
Optional ByVal iupper As Integer = -1) _
As Single()
Try
If gbEND_GENERAL = True Then Exit Function
Dim iarraycount As Integer
Dim sngArrayNameSum() As Single
If ilower = -1 Then ilower = 0
If iupper = -1 Then iupper = sngArrayName1.Length - 1
ReDim sngArrayNameSum(iupper)
If iupper = sngArrayName2.Length - 1 Then
For iarraycount = ilower To iupper
sngArrayNameSum(iarraycount) = sngArrayName1(iarraycount) + sngArrayName2(iarraycount)
Next iarraycount
End If
Combine2SingleArrays = sngArrayNameSum
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("Combine2SingleArrays", msCLASSNAME, _
"combine the two single dimensional arrays " & _
"'" & sArray1Name & "' and '" & sArray2Name & "'" & _
gsCRLF & "and return the array which is the total of the two arrays.", _
mobjCOMException, mobjException)
End If
End Try
End Function
Array_Combine2StringArrays
Public Shared Function Combine2StringArrays(ByVal sArray1Name As String, _
ByVal asArrayName1() As String, _
ByVal sArray2Name As String, _
ByVal asArrayName2() As String) _
As String()
Try
If gbEND_GENERAL = True Then Exit Function
Dim iarraycount As Integer
Dim icombinationcount As Integer
Dim asCombination() As String
ReDim asCombination(asArrayName1.GetUpperBound(0) + asArrayName2.GetUpperBound(0) - 1)
For iarraycount = 0 To asArrayName1.Length - 1
If asArrayName1(iarraycount).Length > 0 Then
asCombination(icombinationcount) = asArrayName1(iarraycount)
icombinationcount += 1
End If
Next iarraycount
For iarraycount = 0 To asArrayName2.Length - 1
If asArrayName2(iarraycount).Length > 0 Then
asCombination(icombinationcount) = asArrayName2(iarraycount)
icombinationcount += 1
End If
Next iarraycount
Combine2StringArrays = asCombination
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("Combine2StringArrays", msCLASSNAME, _
"combine the two string dimensional arrays " & _
"'" & sArray1Name & "' and '" & sArray2Name & "'" & _
gsCRLF & "and return the array which is a concatenation of the two arrays.", _
mobjCOMException, mobjException)
End If
End Try
End Function
Array_CountSingleMatch
Returns the total number of rows in a single dimensional array that match a particular string or value.Public Function Array_CountEntriesSingle(ByVal sArrayName As String, _
ByVal vArrayName As Variant, _
ByVal sText As String) As Long
Dim larraycount As Long
Dim lnooftimes As Long
On Error GoTo AnError
lnooftimes = 0
For larraycount = 1 To UBound(vArrayName) - 1
If vArrayName(larraycount) = sText Then lnooftimes = lnooftimes + 1
Next larraycount
Array_CountEntriesSingle = lnooftimes
If gbDEBUG = False Then Exit Function
AnError:
Array_CountEntriesSingle = -1
Call Error_Handle("Array_CountEntriesSingle", msMODULENAME, 1, _
"count the total number of entires in the single dimensional array " & _
"""" & sArrayName & """" & vbCrLf & _
"that match """ & sText & """")
End Function
Array_DimensionExists
Public Function Array_DimensionExists(ByVal vArray As Variant, _
ByVal iDimension As Integer) As Boolean
Dim ltotal As Long
On Error GoTo AnError
Array_DimensionExists = True
ltotal = UBound(vArray, iDimension)
Exit Function
AnError:
Array_DimensionExists = False
End Function
Array_ItemAddAfter
Public Shared Sub ItemAddAfter(ByVal sText As String, _
ByVal sArrayName As String, _
ByRef vArrayName As System.Array)
Dim iarraycount As System.Int32
Try
If gbEND_GENERAL = True Then Exit Sub
If vArrayName Is Nothing Then
Else
For iarraycount = 0 To vArrayName.Length - 1
vArrayName.GetValue(iarraycount) = vArrayName.GetValue(iarraycount) & sText
Next iarraycount
End If
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("ItemAddAfter", msCLASSNAME, _
"add the entry '" & sText & "'" & _
"to end of the single dimensional array '" & sArrayName & "'", _
mobjCOMException, mobjException)
End If
End Try
End Sub
Array_ItemExists
Public Function Array_ItemExists(ByVal arStringArray As String(), _
ByVal sItemToFind As String) As Boolean
Dim icount As Integer
Dim bfound As Boolean
Try
bfound = False
For icount = 0 To arStringArray.GetUpperBound(0)
If (arStringArray(icount) = sItemToFind) Then
bfound = True
Exit For
End If
Next icount
Return bfound
Catch ex As System.Exception
Call modMessages.ErrorMessage(System.Reflection.MethodBase.GetCurrentMethod, ex.Message)
End Try
End Function
Array_ItemGetLargestSingle
Public Shared Function ItemGetLargestSingle(ByVal sArrayName As String, _
ByVal sngArrayName As System.Array, _
Optional ByVal sngPreviousLargest As Single = -1.0E+20) _
As Single
Dim iarrayno As System.Int32 = 0
Dim snglarge As Single
Try
If gbEND_GENERAL = True Then Exit Function
Do Until (sngArrayName.GetValue(iarrayno) <> 0)
iarrayno = iarrayno + 1
Loop
snglarge = sngArrayName.GetValue(iarrayno)
For iarrayno = iarrayno + 1 To sngArrayName.Length - 1
If (sngArrayName.GetValue(iarrayno) <> 0) And _
(sngArrayName.GetValue(iarrayno) > snglarge) Then snglarge = sngArrayName.GetValue(iarrayno)
Next
If sngPreviousLargest <> -1.0E+20 Then
If sngPreviousLargest > snglarge Then snglarge = sngPreviousLargest
End If
ItemGetLargestSingle = snglarge
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("ItemGetLargestSingle", msCLASSNAME, _
"return the largest number in the " & _
"single dimensional array '" & sArrayName & "'", _
mobjCOMException, mobjException)
End If
End Try
End Function
Array_ItemGetSmallestSingle
Public Shared Function ItemGetSmallestSingle(ByVal sArrayName As String, _
ByVal sngArrayName() As Single, _
Optional ByVal sngPreviousSmallest As Single = 1.0E+20, _
Optional ByVal iupper As Integer = -1, _
Optional ByVal ilower As Integer = -1) _
As Single
Dim iarrayno As Integer = 0
Dim sngsmall As Single
Try
If gbEND_GENERAL = True Then Exit Function
Do Until (sngArrayName(iarrayno) <> 0)
iarrayno = iarrayno + 1
Loop
sngsmall = sngArrayName(iarrayno)
For iarrayno = iarrayno + 1 To sngArrayName.Length - 1
If (sngArrayName(iarrayno) <> 0) And _
(sngArrayName(iarrayno) < sngsmall) Then sngsmall = sngArrayName(iarrayno)
Next
If sngPreviousSmallest <> 1.0E+20 Then
If sngPreviousSmallest < sngsmall Then sngsmall = sngPreviousSmallest
End If
ItemGetSmallestSingle = sngsmall
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("ItemGetSmallestSingle", msCLASSNAME, _
"return the smallest number in the " & _
"single dimensional array '" & sArrayName & "'", _
mobjCOMException, mobjException)
End If
End Try
End Function
Array_OfArray
Public Function Array_OfArray(ByVal vArray As Variant) As Boolean
Dim vvalue As Variant
On Error GoTo AnError
vvalue = vArray(0)(0)
Array_OfArray = True
Exit Function
AnError:
Array_OfArray = False
End Function
Array_ParamArray1Dimension
Public Function Array_ParamArray1Dimension(ByVal vArray2Dimension As Variant) As Variant
Dim svalue As String
Dim larraycount As Long
Dim vtemp As Variant
On Error GoTo AnError
If Array_OfArray(vArray2Dimension) = False Then
Array_ParamArray1Dimension = vArray2Dimension
Exit Function
End If
ReDim vtemp(UBound(vArray2Dimension(0), 1))
For larraycount = 0 To UBound(vArray2Dimension(0), 1)
vtemp(larraycount) = vArray2Dimension(0)(larraycount)
Next larraycount
Array_ParamArray1Dimension = vtemp
Exit Function
AnError:
Call Error_Handle(Err.Number & " " & Err.Description, "Array_ParamArray1Dimension")
End Function
Array_Redim1
Public Function Array_Redim1(ByVal vaArrayName As Variant, _
ByVal lUpper As Long) As Variant
ReDim vaArrayName(lUpper)
Array_Redim1 = vaArrayName
End Function
Array_RemoveChars
Public Shared Sub RemoveChars(ByVal sArrayName As String, _
ByRef vArrayName As System.Array, _
ByVal iNoOfCharsLeft As Integer, _
ByVal iNoOfCharsRight As Integer)
Try
If gbEND_GENERAL = True Then Exit Sub
Dim iarraycount As System.Int32
Dim iopenbracketpos As System.Int32
Dim stemp As String
For iarraycount = 0 To vArrayName.Length - 1
stemp = vArrayName.GetValue(iarraycount)
'stemp = Right(stemp, stemp.Length - iNoOfCharsLeft)
stemp = stemp.Substring(iNoOfCharsLeft)
'stemp = Left(stemp, stemp.Length - iNoOfCharsRight)
stemp = stemp.Substring(0, stemp.Length - iNoOfCharsRight)
vArrayName.GetValue(iarraycount) = stemp
Next iarraycount
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("RemoveChars", msCLASSNAME, _
"remove the '" & iNoOfCharsLeft & "' characters from the left" & _
gsCRLF & "and the '" & iNoOfCharsRight & "' characters from the right" & _
" of every element in the single dimensional array '" & sArrayName & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Sub
Array_RemoveCriteriaSingle
Removes all the entries from a single dimensional array that match a particular criteria. Normally used for filtering on numerical data. The slightly smaller single dimensional array is returned.Public Function Array_RemoveCriteriaSingle() As Variant
On Error GoTo AnError
' Copy from Multi
If gbDEBUG = False Then Exit Function
AnError:
Call Error_Handle("Array_RemoveCriteriaSingle", msMODULENAME, 1, _
"")
End Function
Array_RemoveCRsMulti
Removes all the carriage returns from the text entries in a multi dimensional array.Public Function Array_RemoveCRsMulti(ByVal sArrayName As String, _
ByVal vArrayName As Variant) As Variant
Dim lrowcounter As Long
Dim icolumncounter As Integer
On Error GoTo AnError
For icolumncounter = LBound(vArrayName, 1) To UBound(vArrayName, 1)
For lrowcounter = LBound(vArrayName, 2) To UBound(vArrayName, 2)
'REMOVE Str_Chars1013HasAny
If Str_Chars1013HasAny(vArrayName(icolumncounter, lrowcounter, 0)) = True Then
vArrayName(icolumncounter, lrowcounter, 0) = _
Str_Chars1013Remove(vArrayName(icolumncounter, lrowcounter, 0))
vArrayName(icolumncounter, lrowcounter, 1) = "1"
Else
vArrayName(icolumncounter, lrowcounter, 0) = _
Str_Chars1013Remove(vArrayName(icolumncounter, lrowcounter, 0))
vArrayName(icolumncounter, lrowcounter, 1) = "0"
End If
Next lrowcounter
Next icolumncounter
Array_RemoveCRsMulti = vArrayName
If gbDEBUG = False Then Exit Function
AnError:
Array_RemoveCRsMulti = vArrayName
Call Error_Handle("Array_RemoveCRsMulti", msMODULENAME, 1, _
"remove all carriage returns from all entrie in the multi dimensional array " & _
"""" & sArrayName & """")
End Function
Array_RemoveCRsSingle
Removes all the carriage returns from the text entries in a single dimensional array.Public Function Array_RemoveCRsSingle(ByVal sArrayName As String, _
ByVal vArrayName As Variant) As Variant
Dim lrowcount As Long
On Error GoTo AnError
For irowcounter = LBound(vArrayName) To UBound(vArrayName)
If Str_Chars1013HasAny(vArrayName(irowcount, 0)) = True Then
vArrayName(lrowcount, 0) = Str_Chars1013Remove(vArrayName(irowcount, 0))
vArrayName(lrowcount, 1) = "1"
Else
vArrayName(lrowcount, 0) = Str_Chars1013Remove(vArrayName(irowcount, 0))
vArrayName(lrowcount, 1) = "0"
End If
Next lrowcount
Array_RemoveCRsSingle = vArrayName
If gbDEBUG = False Then Exit Function
AnError:
Call Error_Handle("Array_RemoveCRsSingle", msMODULENAME, 1, _
"remove all carriage returns from all entries in the single dimensional array " & _
"""" & sArrayName & """")
End Function
Array_RemoveDuplicatesMulti
Removes any entries from a multi dimensional array that contain a duplicate entry in a given column. Maybe add all unique entries to a string, then populate again removing from the string concat and using Instr(). Alternatively use a collection ?? The slightly smaller multi dimensional array is returned TEST !!!.Public Function Array_RemoveDuplicatesMulti(ByVal sArrayName As String, _
ByVal vArrayName As Variant, _
ByVal iDuplicateCol As Integer) As Variant
Dim clCells As New Collection
Dim cell As Range
Dim vvalue As Variant
Dim luniquecount As Long
Dim larraycount1 As Long
Dim larraycount2 As Long
Dim lmatches As Long
Dim vArrayNameTemp As Variant
Dim vcompare As Variant
On Error Resume Next
For larraycount1 = UBound(vArrayName, 1) To LBound(vArrayName, 1) Step -1
If vArrayName(larraycount1, iDimension) = Empty Then
clCells.Add "", ""
Else
clCells.Add _
vArrayName(larraycount1, iDuplicateCol), _
vArrayName(larraycount1, iDuplicateCol)
End If
Next larraycount1
On Error GoTo 0
On Error GoTo AnError
ReDim vArrayNameTemp(clCells.Count, UBound(vArrayName, 2))
luniquecount = 1
For larraycount1 = UBound(vArrayName, 1) To LBound(vArrayName, 1) Step -1
vcompare = vArrayName(larraycount1, iDuplicateCol)
If Array_IsItIn(vArrayNameTemp, vcompare, iDuplicateCol) = False Then
For larraycount2 = LBound(vArrayName, 2) To UBound(vArrayName, 2)
vArrayNameTemp(luniquecount, larraycount2) = _
vArrayName(larraycount1, larraycount2)
Next larraycount2
luniquecount = luniquecount + 1
End If
Next larraycount1
Array_RemoveDuplicates = vArrayNameTemp
If gbDEBUG = False Then Exit Function
AnError:
Array_RemoveDuplicatesMulti = vArrayName
Call Error_Handle("Array_RemoveDuplicatesMulti", msMODULENAME, 1, _
"remove any duplicate rows from the multi dimensional array " & _
"""" & sArrayName & """ in column """ & iDuplicateCol & """")
End Function
Array_RemoveHiddenFolders
Public Shared Sub RemoveHiddenFolders(ByRef asFoldersArray As System.Array)
Try
If gbEND_GENERAL = True Then Exit Sub
Dim iarraycount As System.Int32
Dim ifolderscount As System.Int32
Dim astemp As System.Array
Dim itempcount As System.Int32
For iarraycount = 0 To asFoldersArray.Length - 1
Dim objfileinfo As New System.IO.DirectoryInfo(asFoldersArray.GetValue(iarraycount))
If (objfileinfo.Attributes And IO.FileAttributes.Hidden) <> _
IO.FileAttributes.Hidden Then
ifolderscount = ifolderscount + 1
End If
Next iarraycount
ReDim astemp(ifolderscount - 1)
For iarraycount = 0 To asFoldersArray.Length - 1
Dim objfileinfo As New System.IO.DirectoryInfo(asFoldersArray.GetValue(iarraycount))
If (objfileinfo.Attributes And IO.FileAttributes.Hidden) <> _
IO.FileAttributes.Hidden Then
astemp.GetValue(itempcount) = asFoldersArray.GetValue(iarraycount)
itempcount = itempcount + 1
End If
Next iarraycount
ReDim asFoldersArray(astemp.Length - 1)
asFoldersArray = astemp
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("RemoveHiddenFolders", msCLASSNAME, _
"remove the hidden folders from the array.", _
mobjCOMException, mobjException)
End If
End Try
End Sub
Array_Sort
Public Shared Sub Sort(ByVal saArrayName As System.Array)
Try
If gbEND_GENERAL = True Then Exit Sub
System.Array.Sort(saArrayName)
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex,
"sort the array.")
End Try
End Sub
Array_SortRecordsString
Public Shared Function SortRecordsString(ByVal sArrayName As String, _
ByVal vArrayName As System.Array, _
ByVal iNumberOfColumns As Integer, _
ByVal iSortByColumn As Integer, _
Optional ByVal bAscending As Boolean = True) _
As String()
Try
If gbEND_GENERAL = True Then Exit Function
Dim bsorted As Boolean
Dim iarraylistcount As Integer
Dim scomparevalue1 As String
Dim scomparevalue2 As String
Dim icolumncount As Integer
Dim asTempArray As System.Array
ReDim asTempArray(iNumberOfColumns - 1)
'Repeat until the array is sorted correctly
Do
bsorted = True
'start looping through the array from the 2nd record
For iarraylistcount = 1 To (vArrayName.Length \ iNumberOfColumns) - 1
scomparevalue1 = CType(vArrayName.GetValue(((iarraylistcount - 1) * iNumberOfColumns) + (iSortByColumn - 1)), String)
scomparevalue2 = CType(vArrayName.GetValue((iarraylistcount * iNumberOfColumns) + (iSortByColumn - 1)), String)
If bAscending = True Then
'if scomparevalue1 > scomparevalue2
If String.Compare(scomparevalue1, scomparevalue2) = 1 Then
For icolumncount = 0 To (iNumberOfColumns - 1)
asTempArray.GetValue(icolumncount) = _
CType(vArrayName.GetValue(((iarraylistcount - 1) * iNumberOfColumns) + icolumncount), String)
Next icolumncount
For icolumncount = 0 To (iNumberOfColumns - 1)
vArrayName(((iarraylistcount - 1) * iNumberOfColumns) + icolumncount) = _
vArrayName.GetValue((iarraylistcount * iNumberOfColumns) + icolumncount)
Next icolumncount
For icolumncount = 0 To (iNumberOfColumns - 1)
vArrayName((iarraylistcount * iNumberOfColumns) + icolumncount) = _
asTempArray.GetValue(icolumncount)
Next icolumncount
bsorted = False
End If
End If
If bAscending = False Then
'if scomparevalue2 > scomparevalue1
If String.Compare(scomparevalue2, scomparevalue1) = 1 Then
For icolumncount = 0 To (iNumberOfColumns - 1)
asTempArray.GetValue(icolumncount) = _
CType(vArrayName.GetValue(((iarraylistcount - 1) * iNumberOfColumns) + icolumncount), String)
Next icolumncount
For icolumncount = 0 To (iNumberOfColumns - 1)
vArrayName.GetValue(((iarraylistcount - 1) * iNumberOfColumns) + icolumncount) = _
vArrayName.GetValue((iarraylistcount * iNumberOfColumns) + icolumncount)
Next icolumncount
For icolumncount = 0 To (iNumberOfColumns - 1)
vArrayName.GetValue((iarraylistcount * iNumberOfColumns) + icolumncount) = _
asTempArray.GetValue(icolumncount)
Next icolumncount
bsorted = False
End If
End If
Next iarraylistcount
Loop Until bsorted = True
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Function
Array_ToArraySingle
Public Shared Function ToArraySingle(ByVal objArray As System.Array) _
As Single()
ToArraySingle = Nothing
Try
If gbEND_GENERAL = True Then Exit Function
Dim iarraytotal As System.Int32
Dim iarraycount As System.Int32
Dim sngArraySingle() As Single
iarraytotal = objArray.GetUpperBound(0)
ReDim sngArraySingle(iarraytotal - 1)
For iarraycount = 1 To iarraytotal
sngArraySingle(iarraycount - 1) = CType(objArray.GetValue(iarraycount), Single)
Next
Return sngArraySingle
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Function
Array_ToArrayString
Public Shared Function ToArrayString(ByVal objArray As System.Array) _
As String()
ToArrayString = Nothing
Try
If gbEND_GENERAL = True Then Exit Function
Dim iarraytotal As System.Int32
Dim iarraycount As System.Int32
Dim asArraySTring() As String
iarraytotal = objArray.GetUpperBound(0)
ReDim asArraySTring(iarraytotal - 1)
For iarraycount = 1 To iarraytotal
asArraySTring(iarraycount - 1) = CType(objArray.GetValue(iarraycount), String)
Next
Return asArraySTring
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Function
Public Shared Function ToArrayString(ByVal objArray As System.Array) _
As System.Array
ToArrayString = Nothing
Try
If gbEND_GENERAL = True Then Exit Function
Dim iarraytotal As System.Int32
Dim iarraycount As System.Int32
Dim asArrayString As System.Array
iarraytotal = objArray.GetUpperBound(0)
System.Array.Resize(ByRef asArrayString, iarraytotal - 1)
For iarraycount = 1 To iarraytotal
asArrayString[iarraycount - 1] = CType(objArray.GetValue(iarraycount), String)
Next
Return asArrayString
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Function
Array_ToArrayStringUnique
public static System.Array ToArrayStringUnique(
string sArrayName,
System.Array saArrayName)
{
System.Array saArrayTemp;
System.Int32 ifindunder;
string sprevious = "";
string scurrent = "";
System.Collections.ArrayList alUniqueList;
System.Int32 iarraycount;
try
{
ifindunder = saArrayName(0).ToString.IndexOf("_");
if (ifindunder > 0)
{
sprevious = saArrayName(0).ToString.SubString(0, ifindunder - 1);
}
if (ifindunder = 0)
{
sprevious = saArrayName(0).ToString();
}
alUniqueList.Add(sprevious);
for (iarraycount = 0; iarraycount < saArrayName.GetUpperBound(0); iarraycount++)
{
ifindunder = saArrayName(iarraycount).ToString.IndexOf("_");
if (ifindunder > 0)
{
scurrent = saArrayName(iarraycount).ToString.SubString(0, ifindunder - 1);
}
if (ifindunder = 0)
{
scurrent = saArrayName(iarraycount).ToString();
}
//could we / should we use :
//if (alUniqueList.Contains(scurrent) == false) { }
if (scurrent != sprevious)
{
alUniqueList.Add(scurrent);
}
sprevious = scurrent;
}
saArrayTemp = alUniqueList.ToArray();
return saArrayTemp;
}
catch { }
finally { }
}
Public Shared Function ToArrayStringUnique(ByVal sArrayName As String, _
ByVal saArrayName System.Array) _
As String()
Dim varraytemp As System.Array
Dim ifindunder As System.Int32
Dim sprevious As String
Dim scurrent As String
Dim colunique As New Microsoft.VisualBasic.Collection()
Dim iarraycount As Integer
Try
If gbEND_GENERAL = True Then Exit Function
ifindunder = Microsoft.VisualBasic.InStr(saArrayName(0), "_")
If ifindunder > 0 Then sprevious = Microsoft.VisualBasic.Left(saArrayName.GetValue(0), ifindunder - 1)
If ifindunder = 0 Then sprevious = saArrayName(0)
colunique.Add(sprevious)
For iarraycount = 0 To saArrayName.Length - 1
ifindunder = Microsoft.VisualBasic.InStr(saArrayName.GetValue(iarraycount), "_")
If ifindunder > 0 Then scurrent = Microsoft.VisualBasic.Left(saArrayName.GetValue(iarraycount), ifindunder - 1)
If ifindunder = 0 Then scurrent = saArrayName.GetValue(iarraycount)
If scurrent <> sprevious Then
colunique.Add(scurrent)
End If
sprevious = scurrent
Next iarraycount
ReDim varraytemp(colunique.Count)
For iarraycount = 0 To colunique.Count - 1
varraytemp.GetValue(iarraycount) = CStr(colunique.Item(iarraycount + 1))
Next iarraycount
ToArrayStringUnique = varraytemp
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex,
"to return an array of unique elements.")
End Try
End Function
'*************************************************************************************
Array_ToCheckedListBox
public static void ToCheckedListBox(
System.Windows.Forms.CheckedListBox objCheckedListBox,
string sArrayName,
System.Array saArrayName,
bool bClearList,
System.Array saExtrasBefore)
{
System.Int32 iarraycount;
try
{
if (bClearList == true)
{
objCheckedListBox.Items.Clear();
}
for (iarraycount = saExtrasBefore.GetLowerBound(0); iarraycount < saExtrasBefore.GetUpperBound(0); iarraycount++)
{
objCheckedListBox.Items.Add(saExtrasBefore(iarraycount).ToString);
}
for (iarraycount = saArrayName.GetLowerBound(0); iarraycount < saArrayName.GetUpperBound(0); iarraycount++)
{
if (saArrayName(iarraycount).ToString.Length > 0)
{
objCheckedListBox.Items.Add(saArrayName(iarraycount).ToString);
}
}
}
catch { }
finally { }
}
Public Shared Sub ToCheckedListBox(ByVal chlbCheckedListBox As System.Windows.Forms.CheckedListBox,
ByVal sArrayname As String,
ByVal saArrayName As System.Array,
ByVal bClearList As Boolean,
ByVal ParamArray saExtrasBefore() As String)
Try
If gbEND_GENERAL = True Then Exit Sub
Dim sText As String
Dim iarraycount As System.Int32
If bClearList = True Then chlbCheckedListBox.Items.Clear()
For Each sText In saExtrasBefore
chlbCheckedListBox.Items.Add(sText)
Next
For iarraycount = saArrayName.GetLowerBound(0) To saArrayName.GetUpperBound(0)
If (saArrayName.GetValue(iarraycount).ToString.Length > 0) Then _
chlbCheckedListBox.Items.Add(CStr(saArrayName.GetValue(iarraycount)))
Next iarraycount
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex,
"transfer the contents of the array '" & sArrayname & "'" &
" to the checkedlistbox '" & chlbCheckedListBox.Name & "' one element at a time")
End Try
End Sub
Array_ToComboBox
public static void ToComboBox(
System.Windows.Forms.ComboBox objComboBox,
string sArrayName,
System.Array saArrayName,
bool bClearList,
System.Array saExtrasBefore)
{
System.Int32 iarraycount;
try
{
if (bClearList == true)
{
objComboBox.Items.Clear();
}
for (iarraycount = saExtrasBefore.GetLowerBound(0); iarraycount < saExtrasBefore.GetUpperBound(0); iarraycount++)
{
objComboBox.Items.Add(saExtrasBefore(iarraycount).ToString);
}
for (iarraycount = saArrayName.GetLowerBound(0); iarraycount < saArrayName.GetUpperBound(0); iarraycount++)
{
if (saArrayName(iarraycount).ToString.Length > 0)
{
objComboBox.Items.Add(saArrayName(iarraycount).ToString);
}
}
}
catch { }
finally { }
}
Public Shared Sub ToComboBox(ByVal objComboBox As System.Windows.Forms.ComboBox,
ByVal sArrayName As String,
ByVal saArrayName As System.Array,
ByVal bClearList As Boolean,
ByVal ParamArray saExtrasBefore() As String)
Try
If gbEND_GENERAL = True Then Exit Sub
Dim sText As String = ""
Dim iarraycount As System.Int32
If bClearList = True Then objComboBox.Items.Clear()
For Each sText In saExtrasBefore
objComboBox.Items.Add(sText)
Next
For iarraycount = 0 To saArrayName.Length - 1
If (saArrayName.GetValue(iarraycount).ToString.Length > 0) Then _
objComboBox.Items.Add(saArrayName.GetValue(iarraycount).ToString)
Next iarraycount
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex,
"transfer the contents of the array '" & sArrayName & "'" &
" to the combobox '" & objComboBox.ToString & "' one element at a time")
End Try
End Sub
Array_ToDataGridView
Public Sub Array_ToDataGridView(ByVal arItemsArray As System.Array, _
ByVal sArrayDelimiter As String, _
ByVal dgrDataGridView As System.Windows.Forms.DataGridView)
Dim objDataGridViewRow As System.Windows.Forms.DataGridViewRow
Dim arComponentsArray As System.Array
Dim iItemCount As System.Int32
Dim icolumnno As System.Int32
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If Not (arItemsArray Is Nothing) Then
For iItemCount = 0 To arItemsArray.GetUpperBound(0)
arComponentsArray = Microsoft.VisualBasic.Split(arItemsArray.GetValue(iItemCount), sArrayDelimiter)
dgrDataGridView.Rows.Add()
objDataGridViewRow = dgrDataGridView.Rows(dgrDataGridView.Rows.Count - 1)
For icolumnno = 0 To (dgrDataGridView.Columns.Count - 1)
objDataGridViewRow.Cells(icolumnno).Value = arComponentsArray.GetValue(icolumnno)
Next icolumnno
Next iItemCount
End If
Catch ex As Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
Array_ToDataSet
Public Shared Function ToDataSet(ByVal sArrayName As String, _
ByVal asArrayName As System.Array) As DataSet
Try
If gbEND_GENERAL = True Then Exit Function
Dim objDataSet As New DataSet("TempDataSet")
Dim objDataTable As New DataTable("ListBoxTable")
Dim objDataColumn As DataColumn
Dim objDataRow As DataRow
'objDataColumn = New DataColumn("First")
'objDataColumn.DataType = System.Type.GetType("System.String")
'objDataTable.Columns.Add(objDataColumn)
'objDataColumn = New DataColumn("Second")
'objDataColumn.DataType = System.Type.GetType("System.String")
'objDataTable.Columns.Add(objDataColumn)
'objDataRow = objDataTable.NewRow()
'objDataRow.Item("First") = "1 - 1"
'objDataRow.Item("Second") = "1 - 2"
'objDataTable.Rows.Add(objDataRow)
'objDataRow = objDataTable.NewRow()
'objDataRow.Item("First") = "2 - 1"
'objDataRow.Item("Second") = "2 - 2"
'objDataTable.Rows.Add(objDataRow)
Dim icolumnnumber As System.Int32
Dim irowcount As System.Int32
For icolumnnumber = 0 To asArrayName.GetUpperBound(0)
objDataColumn = New DataColumn("Column" & icolumnnumber)
objDataColumn.DataType = System.Type.GetType("System.String")
objDataTable.Columns.Add(objDataColumn)
Next icolumnnumber
For irowcount = 0 To asArrayName.GetUpperBound(1)
objDataRow = objDataTable.NewRow()
For icolumnnumber = 0 To asArrayName.GetUpperBound(0)
'If Len(CStr(asArrayName.GetValue(icolumnnumber, irowcount))) > 0 Then
objDataRow.Item("Column" & icolumnnumber) = asArrayName.GetValue(icolumnnumber, irowcount)
'End If
Next icolumnnumber
objDataTable.Rows.Add(objDataRow)
Next irowcount
objDataSet.Tables.Add(objDataTable)
ToDataSet = objDataSet
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("ToDataSet", msCLASSNAME, _
"", _
mobjCOMException, mobjException)
End If
End Try
End Function
'*************************************************************************************
Array_ToListBox
public static void ToListBox(
System.Windows.Forms.ListBox objListBox,
string sArrayName,
System.Array saArrayName,
bool bClearList,
System.Array saExtrasBefore)
{
System.Int32 iarraycount;
try
{
if (bClearList == true)
{
objListBox.Items.Clear();
}
for (iarraycount = saExtrasBefore.GetLowerBound(0); iarraycount < saExtrasBefore.GetUpperBound(0); iarraycount++)
{
objListBox.Items.Add(saExtrasBefore(iarraycount).ToString);
}
for (iarraycount = saArrayName.GetLowerBound(0); iarraycount < saArrayName.GetUpperBound(0); iarraycount++)
{
if (saArrayName(iarraycount).ToString.Length > 0)
{
objListBox.Items.Add(saArrayName(iarraycount).ToString);
}
}
}
catch { }
finally { }
}
Public Shared Sub ToListBox(ByVal objListBox As System.Windows.Forms.ListBox,
ByVal sArrayName As String,
ByVal saArrayName As System.Array,
ByVal bClearList As Boolean,
ByVal ParamArray saExtrasBefore() As String)
Try
If gbEND_GENERAL = True Then Exit Sub
Dim sText As String = ""
Dim iarraycount As System.Int32
If bClearList = True Then objListBox.Items.Clear()
For Each sText In saExtrasBefore
objListBox.Items.Add(sText)
Next
For iarraycount = saArrayName.GetLowerBound(0) To saArrayName.GetUpperBound(0)
If (saArrayName.GetValue(iarraycount).ToString.Length > 0) Then _
objListBox.Items.Add(saArrayName.GetValue(iarraycount).ToString)
Next iarraycount
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex,
"transfer the contents of the array '" & sArrayName & "'" &
" to the listbox '" & objListBox.ToString & "' one element at a time")
End Try
End Sub
Array_ToListView
public static void ToListView(
System.Windows.Forms.ListView objListView,
string sArrayName,
System.Array saArrayName,
bool bColumnHeadersIncluded,
bool bIncludeFolderBack,
bool bClearItems)
{
System.Int32 iarraycount;
System.Int32 icolumncount;
try
{
objListView.BeginUpdate();
if (bClearList == true)
{
objListView.Items.Clear();
}
if (bIncludeFolderBack == true)
{
objListView.Items.Add("...");
}
for (iarraycount = saArrayName.GetLowerBound(0); iarraycount < saArrayName.GetUpperBound(0); iarraycount++)
{
System.Windows.Forms.ListViewItem objListViewItem = new System.Windows.Forms.ListViewItem(saArrayName(iarraycount, 0), 0);
objListView.Items.Add(objListViewItem);
for (icolumncount = 0; icolumncount < saArrayName.GetUpperBound(1); icolumncount++)
{
objListViewItem.SubItems.Add(saArrayName(iarraycount, icolumncount));
}
}
objListView.EndUpdate();
}
catch { }
finally { }
}
Public Shared Sub ToListView(ByVal objListView As System.Windows.Forms.ListView,
ByVal Arrayname As String,
ByVal saArrayName As System.Array,
Optional ByVal bColumnHeadersIncluded As Boolean = False,
Optional ByVal bIncludeFolderBack As Boolean = False)
Try
If gbEND_GENERAL = True Then Exit Sub
Dim objListViewItem As System.Windows.Forms.ListViewItem
Dim iarraycount As System.Int32
Dim icolumncount As System.Int32
objListView.BeginUpdate()
objListView.Items.Clear()
If bIncludeFolderBack = True Then
objListView.Items.Add("...")
End If
For iarraycount = 0 To saArrayName.GetUpperBound(0)
objListViewItem = New System.Windows.Forms.ListViewItem(saArrayName.GetValue(iarraycount, 0).ToString(), 0)
objListView.Items.Add(objListViewItem)
For icolumncount = 1 To saArrayName.GetUpperBound(1)
objListViewItem.SubItems.Add(saArrayName.GetValue(iarraycount, icolumncount).ToString())
Next icolumncount
Next iarraycount
objListView.EndUpdate()
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
Array_ToRegistryList
public static void ToRegistryList(
string sArrayName,
System.Array saArrayName,
string sAppName,
string sSection,
System.Array asColumnsRegistryPrefix,
bool bDeleteExisting)
{
System.Int32 iarraycount;
System.Int32 icolcount;
try
{
if (clsRegistry.KeyExists(sAppName,sSection) == true) && (bDeleteExisting == true)
{
clsRegistry.Delete(sAppName,sSection);
}
for (iarraycount = 0; iarraycount < saArrayName.GetLength; iarraycount++)
{
for (icolcount = 0; icolcount < asColumnsRegistryPrefix.GetLength; icolcount++)
{
clsRegistry.Save(sAppName,
sSection,
asColumnsRegistryPrefix(icolcount) + " " + iarraycount + 1,
saArrayName(iarraycount,icolcount));
}
}
}
catch { }
finally { }
}
Public Shared Sub ToRegistryList(ByVal sArrayName As String, _
ByVal saArrayName(,) As String, _
ByVal sAppName As String, _
ByVal sSection As String, _
ByVal asColumnsRegistryPrefix() As String, _
Optional ByVal bDeleteExisting As Boolean = True)
Try
If gbEND_GENERAL = True Then Exit Sub
Dim iarraycount As System.Int32
Dim icolcount As System.Int32
If clsRegistry.KeyExists(sAppName, sSection) = True And
bDeleteExisting = True Then
Call clsRegistry.Delete(sAppName, sSection)
End If
For iarraycount = 0 To saArrayName.GetUpperBound(0)
For icolcount = 0 To asColumnsRegistryPrefix.GetUpperBound(0)
Call clsRegistry.Save(sAppName, sSection,
asColumnsRegistryPrefix(icolcount) & " " & iarraycount + 1,
saArrayName(iarraycount, icolcount))
Next icolcount
Next iarraycount
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
Array_ToStringConCat
public static void ToStringConCat(
string sArrayName,
System.Array saArrayName,
string sSeperatorChar)
{
string sconcat = "";
System.Int32 iarraycount;
try
{
for (iarraycount = saArrayName.GetLowerBound(0); iarraycount < saArrayName.GetUpperBound(0); iarraycount++)
{
if (saArrayName(iarraycount).ToString.Length > 0)
{
sconcat += saArrayName(iarraycount).ToString;
}
}
return sconcat.Substring(0, sconcat.Length - 1);
}
catch { }
finally { }
}
Public Shared Function ToStringConCat(ByVal sArrayName As String,
ByVal saArrayName As System.Array,
Optional ByVal sSeperatorChar As String = ";") _
As String
ToStringConCat = ""
Try
If gbEND_GENERAL = True Then Exit Function
Dim sconcat As String = ""
Dim iarraycount As System.Int32
For iarraycount = saArrayName.GetLowerBound(0) To saArrayName.GetUpperBound(0)
If (saArrayName.GetValue(iarraycount).ToString.Length > 0) Then _
sconcat = sconcat & CStr(saArrayName.GetValue(iarraycount))
Next iarraycount
Return sconcat.Substring(0, sconcat.Length - 1)
Catch ex As System.Exception
Call clsError.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex,
"transfer the contents of the array '" & sArrayName & "'" &
" to a string concatenation one element at a time")
End Try
End Function
Array_ToTreeView
Public Shared Sub ToTreeView(ByVal objAddToNode As System.Windows.Forms.TreeNode, _
ByVal sArrayName As String, _
ByVal saArrayName As System.Array, _
Optional ByVal iImageIndex As Integer = -1)
Dim sText As String
Dim iarraycount As System.Int32
Try
If gbEND_GENERAL = True Then Exit Sub
If saArrayName Is Nothing Then
clszMessagesGeneral.Message("The array argument 'saArrayName' is Nothing!", "clsArray.ToTreeView")
Exit Sub
End If
For iarraycount = 0 To saArrayName.Length - 1
If (saArrayName.GetValue(iarraycount).ToString.Length > 0) Then
objAddToNode.Nodes.Add(CStr(saArrayName.GetValue(iarraycount))).ImageIndex = iImageIndex
End If
Next iarraycount
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("ToTreeView", msCLASSNAME, _
"transfer the contents of the array '" & sArrayName & "'" & _
" to the treeview node """ & objAddToNode.Text & """ one element at a time", _
mobjCOMException, mobjException)
End If
End Try
End Sub
Array_ToTreeViewTags
Public Shared Sub ToTreeViewTags(ByVal objAddToNode As System.Windows.Forms.TreeNode, _
ByVal sArrayName As String, _
ByVal saArrayName As System.Array)
Dim sText As String
Dim iarraycount As System.Int32
Try
If gbEND_GENERAL = True Then Exit Sub
For iarraycount = 0 To saArrayName.Length - 1
If (saArrayName.GetValue(iarraycount).ToString.Length > 0) Then
objAddToNode.Nodes(iarraycount).Tag = CStr(saArrayName.GetValue(iarraycount))
End If
Next iarraycount
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("ToTreeViewTags", msCLASSNAME, _
"transfer the contents of the array '" & sArrayName & "'" & _
" to the tags of the treeview node '" & objAddToNode.Text & "'", _
mobjCOMException, mobjException)
End If
End Try
End Sub
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top