Skip to content

Instantly share code, notes, and snippets.

View NPS-ARCN-CAKN's full-sized avatar

NPS Arctic and Central Alaska Inventory and Monitoring Networks NPS-ARCN-CAKN

View GitHub Profile
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / MultipleBindings.vb
Created December 27, 2016 17:10
Bind a DataGridview and a TextBox to the same data source
Me.LogEntryTextBox.DataBindings.Add("Text", tblVitalSignWorkLogBindingSource, "LogEntry", True, DataSourceUpdateMode.OnPropertyChanged, vbNullString)
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / InsertUsingDataAdapter.vb
Last active May 1, 2017 01:12
VB .Net: Basic example of inserting new records using a DataGridView, Dataset and DataAdapter
'See https://msdn.microsoft.com/en-us/library/33y2221y(v=vs.110).aspx for more information
Imports System.Data.SqlClient
Public Class Form1
'create a dataset
Dim AKRODataset As New DataSet("AKRODataset")
'set up the database connectionstring
Dim tblVitalSignWorkLogSqlConnection As New SqlConnection(My.Settings.ConnectionString)
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / LoopString.vb
Created September 23, 2016 19:48
VB .Net: Loop through each line of a string
Dim str As String() = textBoxName.Text.Split(New [Char]() {CChar(vbCrLf)})
For Each s As String In str
MsgBox(s)
Next
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / Sql Server 2008R2 invalid geography fix.sql
Created September 8, 2016 16:39
Sql Server 2008R2 invalid geography fix
-- SS2008R2 requires counterclockwise input of vertices. This trick makes an invalid geography valid
DECLARE @geom GEOMETRY = 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))';
DECLARE @geog GEOGRAPHY = @geom.MakeValid().STUnion(@geom.STStartPoint()).STAsText()
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / DotSpatial_ReturnFeatureWKT.vb
Last active August 15, 2016 18:32
DotSpatial: Get a Feature's WKT
'There are a couple of ways to get a Feature's WKT
'1: BasicGeometry.ToString is WKT. This is the easiest way to get WKT
FeatureSet.Features(0).BasicGeometry.ToString 'returns the Feature's WKT
'2 A function that uses a WKTWriter
''' <summary>
''' Returns a Feature's WKT string equivalent
''' </summary>
''' <param name="Feature">DotSpatial Feature</param>
''' <returns>String</returns>
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / DotSpatial Add a WKT column to a FeatureSet's DataTable and populate it.vb
Created August 15, 2016 15:17
DotSpatial: Add a WKT column to a FeatureSet's DataTable and populate it.
Private Sub AddWKTDataColumnToFeatureSet(Featureset As FeatureSet)
Try
'add a WKT DataColumn to the FeatureSet's DataTable
Dim WKTColumn As New DataColumn("WKT", Type.GetType("System.String"))
Featureset.DataTable.Columns.Add(WKTColumn)
'dim a WKT writer
Dim WKTWriter As New DotSpatial.Topology.Utilities.WktWriter
'loop through the features and build WKT strings and add them to the WKT column
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / Dotspatial_Create and populate a FeatureSet.vb
Last active August 15, 2016 14:25
Dotspatial: Create and populate a FeatureSet
Public Function CreateFeatureset() As FeatureSet
'create a featureset with four data columns
Dim MyFeatureset As New DotSpatial.Data.FeatureSet(FeatureType.Point)
With MyFeatureset
.Name = "Bears"
.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984
.DataTable.Columns.Add(New DataColumn("Waypoint", Type.GetType("System.String")))
.DataTable.Columns.Add(New DataColumn("Boars", Type.GetType("System.Int32")))
.DataTable.Columns.Add(New DataColumn("Sows", Type.GetType("System.Int32")))
.DataTable.Columns.Add(New DataColumn("Cubs", Type.GetType("System.Int32")))
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / TextBoxSelectAll.vb
Created August 11, 2016 16:31
Select all the text in a TextBox automatically when clicked
'Select all the text in a TextBox automatically when clicked
'You would think that you want to do this with the TextBox's Enter event but SelectAll() doesn't work with that event.
'You have to use the MouseDown event.
Private Sub InputTextBox_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles InputTextBox.MouseDown
With Me.InputTextBox
.Focus()
.SelectAll()
End With
End Sub
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / DataTableToCSV.vb
Created June 14, 2016 21:58
DataTable to CSV
''' <summary>
''' Converts a DataTable to a string of delimited values such as CSV
''' </summary>
''' <param name="DataTable">DataTable to convert. DataTable</param>
''' <param name="Delimiter">Values separator</param>
''' <returns>String</returns>
''' <remarks></remarks>
Public Function DataTableToCSV(DataTable As DataTable, Delimiter As String) As String
Dim CSV As String = ""
Try
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / GetCurrentDate.vb
Created June 8, 2016 19:33
VB .Net: Get current datetime in yyyy-mm-dd hh:mm:ss format
Dim CurrentDateTime As String = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")