Imports System.Data Imports Microsoft.VisualBasic Imports CenterSpace.NMath.Core Imports System.IO Namespace CenterSpace.NMath.Examples.VisualBasic A .NET example in Visual Basic showing ADO.NET and NMath Stats objects. Public Class Form1 Inherits System.Windows.Forms.Form Private Frame As DataFrame #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() This call is required by the Windows Form Designer. InitializeComponent() Add any initialization after the InitializeComponent() call Data consists of high jump, discus throw, long jump marks set during Olympic years from 1896 - 1984. Frame = DataFrame.Load("ADOExample.dat", True, False, ControlChars.Tab, True) Adjust year to 4 digits. Eg. -4 => 1896. Dim YearColumn As Integer = Frame.IndexOfColumn("Olympic_Year") Dim I As Integer For I = 0 To Frame.Rows - 1 Dim Original As Double = CType(Frame(I, YearColumn), Double) Frame(I, YearColumn) = Original + 1900 Next Permute columns so year comes first. Frame.PermuteColumns(1, 0) Convert my DataFrame to a DataTable. Dim Table As DataTable = Frame.ToDataTable() Remove the index column. Table.Columns.Remove(Frame.RowKeyHeader) Bind to DataGrid. DataGrid1.DataSource = Table Recompute() End Sub Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Required by the Windows Form Designer Private components As System.ComponentModel.IContainer NOTE: The following procedure is required by the Windows Form Designer It can be modified using the Windows Form Designer. Do not modify it using the code editor. Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents Record As System.Windows.Forms.TextBox Friend WithEvents Average As System.Windows.Forms.TextBox Friend WithEvents Shortest As System.Windows.Forms.TextBox Friend WithEvents Variance As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.DataGrid1 = New System.Windows.Forms.DataGrid() Me.Label1 = New System.Windows.Forms.Label() Me.Label2 = New System.Windows.Forms.Label() Me.Button1 = New System.Windows.Forms.Button() Me.Label3 = New System.Windows.Forms.Label() Me.Label4 = New System.Windows.Forms.Label() Me.Label5 = New System.Windows.Forms.Label() Me.Record = New System.Windows.Forms.TextBox() Me.Average = New System.Windows.Forms.TextBox() Me.Shortest = New System.Windows.Forms.TextBox() Me.Variance = New System.Windows.Forms.TextBox() CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() DataGrid1 Me.DataGrid1.BackgroundColor = System.Drawing.Color.White Me.DataGrid1.CaptionVisible = False Me.DataGrid1.DataMember = "" Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.DataGrid1.Location = New System.Drawing.Point(16, 80) Me.DataGrid1.Name = "DataGrid1" Me.DataGrid1.Size = New System.Drawing.Size(208, 312) Me.DataGrid1.TabIndex = 0 Label1 Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(128, 24) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(192, 40) Me.Label1.TabIndex = 1 Me.Label1.Text = "ADO Example" Label2 Me.Label2.Location = New System.Drawing.Point(248, 88) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(72, 23) Me.Label2.TabIndex = 2 Me.Label2.Text = "Record" Button1 Me.Button1.Location = New System.Drawing.Point(264, 296) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(152, 24) Me.Button1.TabIndex = 3 Me.Button1.Text = "Recompute" Label3 Me.Label3.Location = New System.Drawing.Point(248, 136) Me.Label3.Name = "Label3" Me.Label3.TabIndex = 4 Me.Label3.Text = "Average" Label4 Me.Label4.Location = New System.Drawing.Point(248, 184) Me.Label4.Name = "Label4" Me.Label4.TabIndex = 5 Me.Label4.Text = "Shortest" Label5 Me.Label5.Location = New System.Drawing.Point(248, 232) Me.Label5.Name = "Label5" Me.Label5.TabIndex = 6 Me.Label5.Text = "Variance" Record Me.Record.Location = New System.Drawing.Point(336, 88) Me.Record.Name = "Record" Me.Record.TabIndex = 7 Me.Record.Text = "" Average Me.Average.Location = New System.Drawing.Point(336, 136) Me.Average.Name = "Average" Me.Average.TabIndex = 8 Me.Average.Text = "" Shortest Me.Shortest.Location = New System.Drawing.Point(336, 184) Me.Shortest.Name = "Shortest" Me.Shortest.TabIndex = 9 Me.Shortest.Text = "" Variance Me.Variance.Location = New System.Drawing.Point(336, 232) Me.Variance.Name = "Variance" Me.Variance.TabIndex = 10 Me.Variance.Text = "" Form1 Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(466, 424) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Variance, Me.Shortest, Me.Average, Me.Record, Me.Label5, Me.Label4, Me.Label3, Me.Button1, Me.Label2, Me.Label1, Me.DataGrid1}) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle Me.Name = "Form1" Me.Text = "ADO Example" CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Recompute() End Sub Private Sub Recompute() Frame = New DataFrame(CType(DataGrid1.DataSource, DataTable)) Average.Text = StatsFunctions.Mean(Frame("Long_Jump")).ToString() Record.Text = StatsFunctions.MaxValue(Frame("Long_Jump")).ToString() Shortest.Text = StatsFunctions.MinValue(Frame("Long_Jump")).ToString() Variance.Text = StatsFunctions.Variance(Frame("Long_Jump")).ToString() End Sub End Class End Namespace← All NMath Code Examples