VB.Net KnowledgeBase Menu

 

Common Functions

ToolBar Code

ToolBar2 Code

VB.Net 2005

MS Data Access Blocks

Functions And Subs Module

Creating And Using Objects Article
StreamsExplained

 

Setup

DataGrid Control

TabControl

ComboBox

ListBox  

PictureBox

Bond TextBox Sample App

Date And Time

 

File And Directory

FileInfo And DirectoryInfo Class

 

DataSet

DataView

DataGridView

SQL Server Stuff

Web Service

 

 

How To Make A DLL With VB.Net Standard

Sample Control Creation (My DateSite Control)

Simplified Sample Control Creationg

 

Code To Resize Controls With Form

 

Command line, (commandline), Paramaters

 

        Dim separators As String = ","

        Dim commands As String = Microsoft.VisualBasic.Interaction.Command()

        Dim args() As String = commands.Split(separators.ToCharArray)

        MsgBox(args(0))

 

 

 

Generate A Random Number…

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim r As Integer

        r = RandomNumber(11, 1) 'Return a number between and includeing 1 and 10

        MsgBox(r)

    End Sub

 

    Public Function RandomNumber(ByVal MaxNumber As Integer, Optional ByVal MinNumber As Integer = 0) As Integer

        'Note, MaxNumber will never be returned

        Dim i As Integer

        Dim s As String

        Dim n As Integer

 

        'Generate a Seed...

        s = System.Guid.NewGuid.ToString

        For i = 1 To Len(s)

            n = n + Val(Asc(Mid(s, i, 1)))

        Next

        '*********************************

 

        Dim r As New Random(n)

        If MinNumber > MaxNumber Then

            Dim t As Integer = MinNumber

            MinNumber = MaxNumber

            MaxNumber = t

        End If

 

        Return r.Next(MinNumber, MaxNumber)

 

    End Function

 

 

 

 

Get Data From The Clipboard…

        Dim objClipboard As IDataObject = Clipboard.GetDataObject()

        Dim v As String

 

        If objClipboard.GetDataPresent(DataFormats.Text) Then

            v = objClipboard.GetData(DataFormats.Text)

        End If

 

        TextBox1.Text = v

 

 

Label1.Location = New Point(50, 50)

 

 

Label1.Font = New Font("Times New Roman", 3, FontStyle.Bold)

 

 

Cursor = Cursors.WaitCursor

 

 

‘How to find the Cursor Position anywhere on the screen…

Label1.Text = Cursor.Position.X.ToString & " - " & Cursor.Position.Y.ToString

 

Clipboard Stuff

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Clipboard.SetDataObject(TextBox1.Text)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ' Create a new instance of the DataObject interface.
    Dim data As IDataObject = Clipboard.GetDataObject()
    ' If the data is text, then set the text of the 
    ' TextBox to the text in the Clipboard.
   If (data.GetDataPresent(DataFormats.Text)) Then
     TextBox1.Text = data.GetData(DataFormats.Text).ToString()
   End If
End Sub
 

 

 

App.path = Application.StartupPath

 

 

‘How To Do Global Variables…

Module Module1

    Public gblDBPath As String = Application.StartupPath & "\cp.mdb"

End Module

 

 

DoEvents Replacement SYSTEM THREADING…

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Create a new thread....

        Dim MyThread As New System.Threading.Thread(AddressOf MyRoutine)

        'Start the thread...

        MyThread.Start()

    End Sub

 

    Sub MyRoutine()

        Dim i As Integer

        For i = 1 To 120000000

            'waste of time

        Next

        Beep()

    End Sub

 

        OR...... System.Windows.Forms.Application.DoEvents()

 

 

 

‘Replacement For The Right$ Function…

Dim s As String, s1 As String

s = "Hello World"

s1 = s.Substring(s.Length - 5)  ' returns "World"

 

‘Replacement For The Left$ Function…

Dim s As String

s = "Hello World".Substring(0, 5)  ' returns "Hello"

 

 

 

VB6 Open a Password Protected MS Access Database With Code…

Set db_cp = OpenDatabase(dbpath & "cp.mdb", False, False, "MS Access;pwd=daisy")

 

Set tbl_system = db_cp.OpenRecordset("system")

tbl_system.MoveFirst

 

 

Create A Table With Code

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        Dim TableName As String = "MyTable"

        Dim ColumnNames As New ArrayList

        Dim ColumnTypes As New ArrayList

        Dim ColumnMaxLengths As New ArrayList

 

        '********* Possible Table Column Types ******************************************************

        'Boolean, Byte, Char, DateTime, Decimal, Double, Int16, Int32

        'String, TimeSpan, UInt16, UInt32, Int64,Single,Int64, SByte

 

        ColumnNames.Add("Name_First") : ColumnTypes.Add("System.String") : ColumnMaxLengths.Add(25)

        ColumnNames.Add("Name_Last") : ColumnTypes.Add("System.String") : ColumnMaxLengths.Add(25)

        ColumnNames.Add("Age") : ColumnTypes.Add("System.Int32") : ColumnMaxLengths.Add(0)

        ColumnNames.Add("BirthDate") : ColumnTypes.Add("System.DateTime") : ColumnMaxLengths.Add(0)

        ColumnNames.Add("Married") : ColumnTypes.Add("System.Boolean") : ColumnMaxLengths.Add(0)

        '********************************************************************************************

 

        Dim dt As DataTable

        Dim dr As DataRow

        dt = CreateTable(TableName, ColumnNames, ColumnTypes, ColumnMaxLengths, ColumnNames.Count)

 

        'Now add data to my table..... ************

        dr = dt.NewRow

        dr("Name_First") = "Steve"

        dr("Name_Last") = "Schimsky"

        dr("Age") = 41

        dr("BirthDate") = "11/24/1963"

        dr("Married") = True

 

        dt.Rows.Add(dr)

        '******************************************

 

        'Now data to my table..... ****************

        dr = dt.NewRow

        dr("Name_First") = "Lee"

        dr("Name_Last") = "Schroeder"

        dr("Age") = 45

        dr("BirthDate") = "1/24/1963"

        dr("Married") = True

 

        dt.Rows.Add(dr)

        '******************************************

 

        'Sort the data...**************************

        Dim dv As DataView

        dv = dt.DefaultView

        dv.Sort = "Name_First"

        '******************************************

 

        DataGrid1.DataSource = dt

 

 

    End Sub

 

    Function CreateTable(ByVal TableName, ByVal ColumnNames, ByVal ColumnTypes, ByVal ColumnMaxLengths, ByVal TotalColumns)

 

        Dim dt As New DataTable(TableName)

 

        Dim i As Integer

        For i = 0 To TotalColumns - 1

            Dim dc As New DataColumn(ColumnNames(i), Type.GetType(ColumnTypes(i)))

            If Val(ColumnMaxLengths(i)) > 0 Then

                dc.MaxLength = ColumnMaxLengths(i)

            End If

            'dc.AutoIncrement = True

            'dc.AutoIncrementSeed = 1

            'dc.ReadOnly = True

            dt.Columns.Add(dc)

        Next

 

        Return dt

 

    End Function