| The following code calculates the Max value in a DataTable column. Min can be calculated by replacing Max with Min in the code below. | ||
| DataTable Name.Compute("max([Column Name])", String.Empty) | ||
Common Code Snippets
Get Max or Min Value in DataTable Column
Convert DayOfYear to Date
| The following code converts a DayOfYear value to a Date. | ||
| DateSerial(Now.Year or the year you want, 1, DayOfYear Value).Date | ||
Check If A CheckListBox Item Is Checked
This is just a method call however I didn't know how to do it and it took me a while to find it online, hope this saves you some time.
Dim IsItemChecked as Boolean = CheckListBoxName.GetItemCheckState(ItemNumber)
Calculate The Distance Between Two Geographical Points
(Latitude / Longitude)
|
The following function returns the distance in feet between two geographical points (Latitude/Longitude). |
||
| Function getDistance(ByVal StartLongitude As Double, ByVal StartLatitude As Double, ByVal EndLongitude As Double, ByVal EndLatitude As Double, ByVal Type As String) As Double | ||
|
Dim distance As Double = Math.Abs(3280.839895013 * (6378.7 * (Math.Acos(Math.Cos(StartLatitude / (180 / Math.PI)) * Math.Cos(StartLongitude / (180 / Math.PI)) * Math.Cos(EndLatitude / (180 / Math.PI)) * Math.Cos(EndLongitude / (180 / Math.PI)) + Math.Cos(StartLatitude / (180 / Math.PI)) * Math.Sin(StartLongitude / (180 / Math.PI)) * Math.Cos(EndLatitude / (180 / Math.PI)) * Math.Sin(EndLongitude / (180 / Math.PI)) + Math.Sin(StartLatitude / (180 / Math.PI)) * Math.Sin(EndLatitude / (180 / Math.PI))))))
Return distance |
||
| End Function | ||
Check If DataTable Row Is Marked For Deletion
This code checks to see if a DataTable row is marked for deletion
If DataTableName.Rows(RowCounter).RowState = 8 Then
//Code to run if the row is marked for deletion
End If
Note: 8 correlates with DataRowState.Deleted.
Delete Datatable Row
This code marks a datatable row for deletion and then accepts the deletion.
DataTableName.Rows(RowNumber).Delete // This marks the row for deletion
DataTableName.AcceptChanges() // Deletes all rows marked for deletion
Delete All Checked Items From A Check List Box
This code deletes all checked items in a check list box. It has a while loop that continues until all checked items are deleted.
While CheckListBoxName.CheckedItems.Count > 0
CheckListBoxName.Items.Remove( CheckListBoxName.CheckedItems(0))
End While
Subscribe to:
Posts (Atom)