| 
| ข้อมูลทั้งหมดเกี่ยวกับวิชวลสตูดิโอดอทเน็ต ได้จากการอ่าน ทดสอบ และใช้เวลาไปมากมายในแต่ละเรื่อง .. ไม่มีเรื่องใดได้จากการนั่งทางใน .. แม้พยายามนั่งแล้วก็ตาม ..
 ถ้าเป็นไปได้ช่วยคัดลอก (Copy) ทุกอย่างที่ผมเขียนไปเผยแพร่ต่อด้วย .. จะได้ลดเวลาในการค้นหา และทดสอบ
 | 
 |   | ยินดีรับ ผู้สนับสนุน เว็บไซต์ด้านการศึกษา กลุ่มเว็บไซต์นี้ เริ่มพัฒนา พ.ศ.2542
 โดยบุคลากรทางการศึกษาด้านคอมพิวเตอร์
 โทร. 081-9927223 (ผมเป็นคนลำปางหนา)
 ปล. ขอไม่รับ work at home / อาหารเสริม
 | 
 
| ตัวอย่างจอภาพ
 + ตัวเลือก สำหรับสร้างโปรเจคใหม่
 โฮมเพจนักศึกษา
 + thaiall512
 + thaiall512setup
 + northwind.mdb (532 KB)
 + dthai97.mdb 70 KB
 tbthai: fid int, fname string, fsalary double
 + boardx.mdb 108 KB
 questions, answers, users ..
 + search.mdb 662 KB
 webdat, describ, group, url
 
   แก้ปัญหาภาษาไทย
 Download MySQL Connector
 + Connector/Net
 - MySQL Connector/Net 5.1 #
 - MySQL Connector/Net 5.0
 + Connector/ODBC
 - Connector/ODBC 5.1
 - Connector/ODBC 3.51 #
 
 ใช้ aspnet_regiis แล้วอย่าลืมเปิดบริการ
 
   ผลงานนักศึกษา
 + #
#
#
#
#	
#
#
 | การเพิ่มผู้ใช้ใน SQLExpress 2005 (Peter)
บอกให้ SQLServer ยอมรับวิธีเข้ารหัสของวินโดว์ ?
DOS>REGEDIT
 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft
 \Microsoft SQL Server\MSSQL.1\MSSQLServer
 LoginMode = 2 (Old value = 1)
 ถ้าไม่ reboot จะใช้ User ที่สร้างใหม่ Connect ไม่ได้
สร้างตาราง และตัวอย่างข้อมูล เพื่อทดสอบใน windows form
DOS>sqlcmd -S.\SQLEXPRESS -E
 1> sp_databases
 2> go
 1> create database dbthai
 2> go
 1> use dbthai
 2> go
 1> create table tbthai(id int,name varchar(10))
 2> go
 1> insert into tbthai values(1,'abc')
 2> insert into tbthai values(2,'def')
 3> go
 1> select * from tbthai
 2> go
 1> select * from sys.tables
 2> go
สร้างรหัสผู้ใช้ และรหัสผ่านสำหรับเข้าใช้ระบบ
DOS>cd C:\Program Files\Microsoft SQL Server\90\Tools\Binn>
 DOS>sqlcmd -S.\SQLEXPRESS -E
 sp_addLogin 'thai', 'thai2007'
 go
 sp_addsrvrolemember 'thai', 'sysadmin'
 go
 sp_password @old = null, @new = '1234', @loginame = 'sa'
 go
 alter login sa enable
 go
 DOS>osql -S .\SQLEXPRESS -E -i data.sql
 osql เป็น sql manager on command line เหมือนกับ sqlcmd
 แต่ sqlcmd จะใช้ฟังก์ชันได้มากกว่า osql
เพิ่มระเบียนใหม่ใน Windows Form ของ VB.NET ?
คลาสสำคัญที่ต้องเรียกมาใช้
 1) SqlConnection สำหรับเชื่อมฐานข้อมูล
 2) SqlCommand สำหรับส่ง sql เข้าไป
 3) method ExecuteNonQuery() ของ SqlCommand
 Imports system.data.sqlclient
 Dim conn As SqlConnection
 Dim myCommand As SqlCommand
 Dim ra As Integer
 Dim sql As String
 conn = New SqlConnection("server=.\sqlexpress;" + _
 "user id=thai;password=thai2007;database=dbthai")
 conn.Open()
 sql = "insert into tbthai values ("
 sql = sql + TextBox1.Text + ","
 sql = sql + "'" + TextBox2.Text + "')"
 myCommand = New SqlCommand(sql, conn)
 ra = myCommand.ExecuteNonQuery() ' ra = 1
 MessageBox.Show("New Row Inserted " & ra)
 conn.Close()
แสดงข้อมูลจาก SQLServer ใน messagebox
คลาสสำคัญที่ต้องเรียกมาใช้
 1) SqlConnection สำหรับเชื่อมฐานข้อมูล
 2) SqlCommand สำหรับส่ง sql เข้าไป
 3) SqlDataReader สำหรับประมวลผลเพื่ออ่านระเบียน
 4) method.read() ของ SqlDataReader
 Imports system.data.sqlclient
 Dim conn As SqlConnection
 Dim myCommand As SqlCommand
 Dim s As String = ""
 conn = New SqlConnection("server=.\sqlexpress;" + _
 "user id=thai;password=thai2007;database=dbthai")
 conn.Open()
 myCommand = New SqlCommand("select * from tbthai", conn)
 Dim reader As SqlDataReader = myCommand.ExecuteReader()
 While reader.Read()
 s &= reader(1) & Chr(10) 'only name
End While
 MessageBox.Show(s)
 conn.Close()
แนะนำเว็บ (Web Guides)
MySQL
 + ใช้ MySQL ในสภาพแวดล้อม .NET 3 วิธี (ODBC, Native Provider และ OLEDB.NET)
+ การใช้ MySQL ด้วย Visual Studio (ละเอียดดี)
+ Configuring a Connector/ODBC DSN on Windows
+ .NET Data Providers
+ Types of .NET Framework Data Provider
Lesson
+ vbnet + mysql
+ e-book หลายภาษา หลากหลาย
+ e-book 8 บท ดีมาก
+ คำสั่งใน SQLCMD จาก MSDN
+ SQLCMD : SQL Command Line
+ SQLCMD บทที่ 1
+ http://www.a1vbcode.com
+ http://msdn2.microsoft.com/en-us/vstudio (official)
+ http://www.developerfusion.co.uk/vbnet/
+ เปิดสอน VB2005
+ สอน Visual Basic .net
+ สอน .net โดย ไพรัช เพลินมาลัย
+ http://www.codeproject.com
- http://www.codeproject.com/aspnet/fileupload.asp
+ VB.Net Black (password: ganelon)
+ VB.Net Book 13 Chapters
+ หลักสูตร Crystal Report Version 11 โดย พงษ์พันธ์ ศิวิลัย
* Check List เตรียมสมัครงาน
 | 
 
 
 
| แหล่งอ้างอิง (Reference) | | From : http://www.programmersheaven.com/2/VB-NET-School
1. Welcome to the VB.NET School 
2. Introduction to the .NET Framework & VB.NET 
3. VB.NET Language Fundamentals 
4. Classes & Objects 
5. Inheritance & Polymorphism in VB.NET 
6. Structures, Enumeration, Garbage Collection & Nested Classes 
7. Abstract Classes & Interfaces 
8. Arrays, Collections & String Manipulation 
9. Exception Handling in VB.NET 
10. Delegates & Events 
11. WinForms & Windows Applications 
12. More Windows Controls and Standard Dialog Boxes 
13. Data Access in .NET using ADO.NET 
14. Multithreading in VB.NET 
15. File System & Streams 
|   |  | 
 |  |  
| ตัวอย่างรหัสต้นฉบับอย่างสั้น (Short Source Code) |  | 
สร้าง console application หรือเปลี่ยนใน Application type ก็ได้ แล้วสร้าง module ?
Module Module1
    Public a As Integer = 5
    Sub main()
        Dim b As Integer
        b = a + 1
        Console.WriteLine(b)
        a = Val(Console.ReadLine())
        b = a + 5
        For a = b To 10 : Console.WriteLine(a) : Next
        If a = 1 Then Console.Write(5)
        Console.ReadLine()
    End Sub
End Module  สร้าง Module ที่มี sub main จะแสดงชื่อ module ให้เลือกใน Startup Object
Module Module1
    Sub main()
        MsgBox(5)
    End Sub
End Moduleใน form1 สามารถสร้างและเรียกใช้ method ของตนได้
Public Class Form1
    Sub m()
        MsgBox(6)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, 
        ByVal e As System.EventArgs) Handles MyBase.Load
        Call m()
    End Sub
End Classถ้าสร้าง method ใน class แบบ shared จะเรียกใน form ได้ ถ้า imports
Public Class Class1
    Shared Sub m()
        MsgBox(6)
    End Sub
End Class
Imports WindowsApplication1.Class1
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, 
        ByVal e As System.EventArgs) Handles MyBase.Load
        Call m()
    End Sub
End Classใช้แต่ method สร้าง form และ control ใน runtime 
All these Windows Controls are based on the Control class, the base class for all controls. 
Visual Basic allows us to work with controls in two ways: at design time and at runtime. ?
The Control class is in the System.Windows.Forms namespace. 
เลือก enable application framework ใน WindowsApplication Properties แล้วเลือก Sub Main
Module Module1
    Sub main()
        Dim instance As New Form
        Dim cm As New Button
        cm.Text = "abc"
        instance.Size = New Size(300, 200)
        instance.Controls.Add(cm)
        instance.ShowDialog()
    End Sub
End Module ใช้แต่ method สร้าง form และ control และ event
Module Module1
    Sub main()
        Dim instance As New Form
        Dim lb As New ListBox
        Dim cm As New Button
        AddHandler cm.Click, AddressOf cmEventHandler
        cm.Text = "abc"
        lb.Items.Add("ทดสอบ")
        lb.Items.Add("ไทยออล")
        lb.Left = 100 ' pixels
        AddHandler lb.Click, AddressOf lbEventHandler
        instance.Size = New Size(300, 200)
        instance.Controls.Add(cm)
        instance.Controls.Add(lb)
        instance.ShowDialog()
    End Sub
    Public Sub cmEventHandler(ByVal sender As Object, ByVal e As System.EventArgs)
        MsgBox(sender.text.ToString)
    End Sub
    Public Sub lbEventHandler(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim s As ListBox = sender
        MsgBox(s.Items(s.SelectedIndex.ToString))
        ' MsgBox(sender.items(1)) ' ไทยออล
	End Sub
End Moduleเปิด web browser ในตัว
เขียนใน Windows Application แต่แก้ Properties ของ Windowsapplication ใน Startup Object เป็น Module1
 Module Module1
    Sub main()
        Dim instance As New Form
        Dim wb As New WebBrowser
        wb.Navigate(New Uri("http://www.thaiall.com"))
        instance.Size = New Size(600, 500)
        wb.Width = instance.Size.Width.ToString
        wb.Height = instance.Size.Height.ToString
        instance.Controls.Add(wb)
        instance.ShowDialog()
    End Sub
End Moduleฟังก์ชัน อาร์เรย์ และวันที่ (Random & Array & Date)
Dim v1 As Integer = CInt(Rnd() * 100)
Dim v2 As Double = Rnd()
Dim v3() As Integer = {5, 6}
MsgBox(v1 & "-" & v2 & "-" & v3(0) & "-" & v3.Length)
Dim v4 As Date
v4 = Now '11/13/2007 8:29:50 PM
v4 = #11/13/2007#
MsgBox(TimeOfDay & " " & v4) ' 8:29:50 PM 11/13/2007
Dim v5(2) As Integer
v5(0) = 7 : v5(1) = 8 : MsgBox(v5(0) + v5(1)) ' 15
Dim v6 As Integer
v6 = DateDiff(DateInterval.Day, #10/13/2006#, v4) ' 396
MsgBox(v6)
Dim v7 As String = "abcdef"
MsgBox(Mid(v7, 1, 2) & Microsoft.VisualBasic.Left(v7, 2))
Dim v8() As String
v8 = Split("a+b+c", "+")
MsgBox(v8(0) & chr(10) & v8(1)) 
' chr(65)=A & Asc("A")=65 & Format(Asc("A"), "000")=065
การสุ่มแบบไม่ซ้ำ (Random & No duplicate)
Randomize()
Dim a(5) As Integer, i, j As Integer, s As String = "", found As Boolean
For i = 0 To 5
found = False
Dim t As Integer = CInt(Rnd() * 10)
For j = 0 To i - 1
If a(j) = t Then found = True
Next
If (found) Then i -= 1 Else a(j) = t : s &= t & Chr(10)
Next
MsgBox(s)consoleapplication + byval + byref + sub + function (stop with breakpoint + ต.ย.ข้อสอบ)
Module Module1
Dim a As Integer
Sub Main()
Dim a As Integer = 5
sub1(a, a)
Console.WriteLine(func1(a, a)) ' 25
End Sub
Sub sub1(ByVal x As Integer, ByRef y As Integer)
a += x : x += a : y += a
End Sub
Function func1(ByVal x As Integer, ByRef y As Integer) As Integer
func1 = a + x + y
End Function
End ModuleTimer + Nanosecond + Progressbar 
Public Class Form1
    ' The value of this property represents the number of 100-nanosecond intervals 
    ' that have elapsed since 12:00:00 midnight, January 1, 0001.
    Dim start As Long
    Private Sub Form1_Load(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles MyBase.Load
        start = Now.Ticks
        Timer1.Interval = 250 'milliseconds
        Timer1.Start()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("Nano Second = " & (Now.Ticks - start))
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles Timer1.Tick
        If (ProgressBar1.Value = 100) Then ProgressBar1.Value = 0
        ProgressBar1.Value += 1
        Button1.Text = ProgressBar1.Value
    End Sub
End Classโปรแกรมนี้ error เกี่ยวกับความเข้ากันได้ของคำสั่ง 
- ทำไม error ว่า Keyword not supported: 'provider'. ตอนส่งค่าให้ ConnectionString
 1. เพราะ provider=microsoft.jet.oledb.4.0 ใช้กับ SqlConnection ไม่ได้
 2. ถ้าใช้ SqlConnection ต้องเชื่อมต่อกับ SQLServer ที่กำหนด server, user, password, db
 Public Class Class1
    Public Shared data As String = _
    "provider=microsoft.jet.oledb.4.0;data source=c:\northwind.mdb"
End ClassImports system.data.sqlclient
Public Class Form1
    Dim conn As SqlConnection
    Dim com As SqlCommand
    Private Sub Form1_Load(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strconn As String = Class1.data
        conn = New SqlConnection()
        With conn
            If .State = ConnectionState.Open Then .Close()
            .ConnectionString = strconn ' Keyword not supported: 'provider' 
            .Open()
        End With
    End Sub
End Class
จับเวลาการประมวลผล 10 ล้านรอบใน for 
' my computer use about 62.5 Millisecond
Module Module1
    Dim i, j, startclock, stopclock As Long
    Sub Main()
        display_time(startclock)
        For i = 1 To 10000000 : j += i : Next
        display_time(stopclock)
        Console.WriteLine(stopclock - startclock)
        Console.ReadLine()
    End Sub
    Sub display_time(ByRef x As Long)
        x = Now.Ticks
        Console.WriteLine(Now.Millisecond & " millisecond " & Now.Ticks & " ticks")
    End Sub
End Module
ASP Short Code
<body bgcolor=yellow>
<form id="fm" runat="server">
<asp:TextBox ID="TextBox1" runat="server" Text="0">
</form>
<% response.write(textbox1.text) %>
<% Session("x") = TextBox1.Text %>
</body>
' คำสั่งสำหรับปุ่มใน .vb เพื่อเปิดฟอร์มใหม่ Server.Transfer("default2.aspx", True)
' Session เป็นอีกวิธีหนึ่งที่ใช้ส่งค่าระหว่างฟอร์ม
' Response.Redirect("default.aspx?a=6") เป็นการส่งผ่าน request.querystring อีกวิธีหนึ่ง
to call command in shell
Shell("notepad.exe", AppWinStyle.NormalFocus)
Shell("c:\x.bat", AppWinStyle.NormalFocus)to start & close process
Dim p As New Process()
Private Sub b1()
  p = Process.Start("C:\Windows\system32\calc.exe")
End Sub
Private Sub b2()
  p.CloseMainWindow()
  p.Close()
End SubSQL ที่น่ารู้สำหรับ Crystal Report มาก 
1. select * from [order details]
2. select * from orders where orderdate = #11/16/1994#
3. select * from orders where customerid like "*A*"
4. select * from orders where employeeid > {?t1}
5. select * from orders where orderdate = {?t1} ' CDate(TextBox1.Text)
6. select orders.*,[order details].* from (
[order details]  inner join orders 
on [order details].orderid = orders.orderid
) where [order details].productid={?t1} and orders.employeeid = {?t2}
Imports Crystaldecisions.shared ?
Dim rpt As String
rpt = "C:\CrystalReport1.rpt"
CrystalReportViewer1.ReportSource = rptการ ping และ download แฟ้มจากอินเทอร์เน็ต 
If My.Computer.Network.Ping("www.google.com", 1000) Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If
My.Computer.Network.DownloadFile("http://www.thaiall.com/ta1.gif", "C:\ta1.gif") 
My.Computer.Network.UploadFile( _
"C:\ta1.gif", "http://www.yourhost.com/upload.aspx", "anonymous", "")
' Format(1, "000")=001
If My.Computer.FileSystem.FileExists("c://x.txt") Then
My.Computer.FileSystem.DeleteFile("c://x.txt")
My.Computer.Network.DownloadFile("http://www.thaiall.com", "C:\x.txt")
msgbox(My.Computer.FileSystem.ReadAllText("c://x.txt"))
Else
My.Computer.Network.DownloadFile("http://www.thaiall.com", "C:\x.txt")
End If
ตัวอย่าง Visual C# เมื่อประมวลผลใน Console
- Compile ผ่าน Command Line หรือ Editplus ก็ได้
 - กำหนด Command ใน Editplus เป็น "c:\windows\system32\cmd.exe" "/k"
 - ตัวอย่างการแปล C:\WINDOWS.0\Microsoft.NET\Framework\v2.0.50727>csc hello.cs
public class HelloWorld {
public static void Main(string[] args) {
  string name = "hello";
  System.Console.WriteLine(name);
}
}
ตัวอย่าง Visual C# เมื่อเขียนใน Visual Studio
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1 {
    class Program  {
        static void Main(string[] args) {
            Console.Write("x");
            Console.Read();
        }
    }
}
ตัวอย่าง Visual J# เมื่อประมวลผลใน Console
- Compile ผ่าน Command Line หรือ Editplus ก็ได้
 - กำหนด Command ใน Editplus เป็น "c:\windows\system32\cmd.exe" "/k"
 - ตัวอย่างการแปล C:\WINDOWS.0\Microsoft.NET\Framework\v2.0.50727>vjc x.jsl
public class x {
	public static void main(String[] args) {
		System.out.println(5);
	}
}
ตัวอย่าง Visual C++ ใน Windows 32 Console Application
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[]) {
  printf("a");
  char s[80];
  scanf("%s",&s);
  printf(s);
  char c;
  scanf("%c",&c);
  return 0;
}
ตัวอย่าง Visual C++ ใน CLR 32 Console Application
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args) {
    Console::WriteLine(L"Hello World");
    Console::Read();
    return 0;
}
ตัวอย่าง class ใน .net แทน printer object ที่เคยมีใน vb6
'Dim Print As New Class1
'Print.prt("About Visual Basic 1" & vbCrLf & "About Visual Basic 2")
'http://visualbasic.about.com/od/usingvbnet/a/printvb2005.htm
Public Class Class1
  Friend tx As String
  Public Sub prt(ByVal text As String)
      tx = text
      Dim prn As New Printing.PrintDocument
      Using (prn)
          ' prn.PrinterSettings.PrinterName  = "PrinterName" 
          AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
          prn.Print()
          RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
      End Using
  End Sub
  Private Sub PrintPageHandler(ByVal sender As Object,ByVal args As Printing.PrintPageEventArgs)
      Dim myFont As New Font("Microsoft San Serif", 10)
      args.Graphics.DrawString(tx, New Font(myFont, FontStyle.Regular), Brushes.Black, 50, 50)
  End Sub
End Class
ลูกศิษย์ที่ชื่อวศิลป์ ถามว่า ถ้า form เรียก class มา แล้วต้องการให้ใน class สั่งปิดการทำงานของปุ่มจะทำได้ไหม
ผมจึงใช้ VS2005 สร้าง form1 และ class1.vb โดยเขียน code ทดสอบกับ button1 ที่สร้างผ่าน design time อย่างง่ายดังนี้
' class1.vb
Public Class Class1
  Shared Sub hidebutton(ByRef o as System.Object)
    o.text ="a"
    o.enabled = false
  End Sub
End Class
' form1.vb
Imports WindowsApplication1.Class1
Public Class Form1
  Private Sub Button1_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles Button1.Click
      call hidebutton(Button1)
  End Sub
End Class
การควบคุม control ทั้งหมดในฟอร์มผ่านคลาสที่ import เข้าไป 
ถ้า form1 ทำงานปกติมี button และ textbox และ import คลาสจาก application อย่างถูกต้อง
โดยเรียกใช้คลาสด้วยการส่งฟอร์มให้กับคลาสทำการควบคุม ซึ่งคุมได้ทุกวัตถุดังนี้
Public Class Class1
    Shared Sub hidebutton(ByRef o As System.Object)
        o.text = o.name ' same result is form1
        Dim s As String = ""
        For Each c As Control In o.controls
            c.Enabled = False 
            If TypeOf c Is TextBox Then c.Enabled = True
            s += c.Name + vbLf
        Next
        MsgBox(s)
    End Sub
End Class
 |  | วิชวลเบสิกดอทเน็ต 
วิชวลเบสิกดอทเน็ต คือการโปรแกรมที่มีสภาพแวดล้อมแบบกราฟิกสำหรับระบบปฏิบัติการวินโดว์ โดยมีโครงสร้างภาษาแบบภาษาเบสิก และทำงานบนดอทเน็ตเฟรมเวิร์ค ถูกพัฒนาให้เป็นการโปรแกรมเชิงวัตถุอย่างแท้จริง รองรับการออกแบบด้วยยูเอ็มแอล
ความหมายของการโปรแกรมเชิงวัตถุ (Object-Oriented Programming)
 OOP เป็นเรื่องของวัตถุ (Object) ความหมายวัตถุ คือ หน่วยหนึ่งของโปรแกรม ซึ่งมีหน้าที่การทำงานเฉพาะเจาะจง และถูกกำหนดปฏิสัมพันธ์กับโปรแกรมหน่วยอื่นอย่างแน่ชัด 
นักเขียนโปรแกรม VB6 บางคนพบว่าตนไม่สามารถเขียนโปรแกรมใน VB.NET ได้ดีนัก เพราะพบแนวคิดที่แตกต่างจาก VB6 ไปมากจนไม่อาจปรับวิธีทำงานให้เข้ากับ VB.NET ได้ สาเหตุที่เป็นเช่นนั้นเพราะ VB6 เป็น Object based programming (การเขียนโปรแกรมที่มีพื้นฐานจากวัตถุ) ส่วน VB.NET เป็นภาษา OOP โดยสมบูรณ์ มิได้เป็นเพียง VB6 เวอร์ชันใหม่ ขณะที่นักเขียนโปรแกรมที่เคยเขียนภาษา C++ และหรือภาษาจาวา (Java Language) มาแล้วจะสามารถเรียนรู้ภาษา C# ได้อย่างรวดเร็ว เพราะมีพื้นฐานเกี่ยวกับ OOP มาก่อน 
ใน VB6 มี object อยู่จำนวนหนึ่งเรียกว่า Control (เช่นปุ่มและ Label) มันมี property method และ event ครบถ้วนเหมือน object ใน OOP แต่เราไม่สามารถนำมันมา สืบสันดาน (inheritance) หรือนำมาสร้างเป็น object ใหม่ โดยเพิ่มเติมแก้ไขคุณสมบัติของมันได้ง่ายเหมือนที่ทำได้ในภาษา .NET การไม่มีคุณสมบัติ inheritance เป็นเครื่องชี้ว่าภาษา VB6 ไม่ใช่ภาษา OOP
ข้อมูลจาก http://www.meelink.com/webboard/data/3/0011-1.html
 | 
 | OOP in VB.NET
Public Class Form1
  Private Sub Form1_Load( ...
    Dim obj As New Test()
    obj.disp() ' hello
    Dim b As New child()
    MsgBox(b.sum() & b.add()) ' 13030
  End Sub
End Class
Public Class Test
  Sub disp()
    MsgBox("hello")
  End Sub
End Class
Public Class child
  Inherits father
  Private k As Integer = 100
  Public Function sum() As Integer
      Return i + j + k
  End Function
End Class
Public Class father
  Protected i As Integer = 10
  Protected j As Integer = 20
  Public Function add() As Integer
    Return i + j
  End Function
End Class |   | 
 |  |  | OOP Sample Code
' Class and Object
Imports System.Console
Module Module1
    Sub Main()
        Dim obj As New Test()
        obj.disp()
        Read()
    End Sub
End Module
Public Class Test
    Sub disp()
        Write("Object testing")
    End Sub
End Class
'  Constructor
' work to initialize the objects 
Imports System.Console
Module Module1
    Sub Main()
        Dim obj As New Test(5)
        Write(obj.dispx()) ' output = 7
        Read()
    End Sub
End Module
Public Class Test
    Public x As Integer
    Public Sub New()
        x = 1
    End Sub
    Public Sub New(ByVal value As Integer)
        x = value + 2
    End Sub
    Function dispx() As Integer
        Return x
    End Function
End Class
 ' Inheritance
' Reusing the class that is tested, debugged and used many times 
Imports System.Console
Module Module1
    Sub Main()
        Dim burin As New child()
        WriteLine(burin.sum()) ' 130
        WriteLine(burin.add()) ' 30
        Read()
    End Sub
End Module
Public Class child
    Inherits father
    Private k As Integer = 100
    Public Function sum() As Integer
        Return i + j + k
    End Function
End Class
Public Class father
    Protected i As Integer = 10
    Protected j As Integer = 20
    Public Function add() As Integer
        Return i + j
    End Function
End Class
 ' Polymorphism
' one name, multiple forms
Imports System.Console
Module Module1
    Sub Main()
        Dim lampang As New child()
        WriteLine(lampang.dsp(10))
        WriteLine(lampang.dsp("ten"))
        Read()
    End Sub
End Module
Public Class child
    Public Function dsp(ByVal i As Integer) As Integer
        Return i
    End Function
    Public Function dsp(ByVal i As String) As Integer
        Return 10
    End Function
End Class
 ' Interface
' allow us to create definitions for component interaction
Imports System.Console
Module Module1
    Sub Main()
        Dim obj As New child()
        obj.disp()
        Write(obj.mul())
        Read()
    End Sub
End Module
Public Interface myobj
    Sub disp()
    Function mul() As Double
End Interface
Public Class child
    Implements myobj
    Public i As Double = 12
    Sub disp() Implements myobj.disp
        WriteLine(i)
    End Sub
    Public Function mul() As Double Implements myobj.mul
        Return i * i
    End Function
End Class
 ' Abstract
' designed to act as a base class
Imports System.Console
Module Module1
    Public MustInherit Class aburin
        Public i As Integer = 10
        Public MustOverride Function Add() As Integer
        Sub dsp()
            Write(5)
        End Sub
    End Class
    Public Class burin
        Inherits aburin
        Shadows i As Integer = 20
        Public Overrides Function Add() As Integer
            Return i + i
        End Function
    End Class
    Sub Main()
        Dim abs As New burin()
        WriteLine("one is " & abs.i)
        WriteLine(abs.Add())
        abs.dsp()
        Read()
    End Sub
End Module
 ' Structure
' defined for handling a group of logically related data items
Imports System.Console
Module Module1
    Structure Employee
        Dim firstname As String
        Dim lastname As String
    End Structure
    Sub Main()
        Dim person As New Employee()
        person.firstname = "burin"
        person.lastname = "rujjanapan"
        Write(person.firstname + " " + person.lastname)
        Read()
    End Sub
End Module
 | 
 | คำถาม - คำตอบ (Question & Answer)
ความแตกต่างของ C# กัย VB.NET ?
ต่างกันทุกส่วนตั้งแต่
program structure, data types, constants, operators, choices, loops, arrays, functions, strings, exception handling, namespaces, classes and using objects เป็นต้น
รายชื่อโปรแกรมที่เคยถูกเปิดด้วย Visual Studio .net ลบออกได้อย่างไร
ใช้ Regedit เข้าไปที่ HKCR\Software\Microsoft\VisualStudio\8.0\ProjectMRUList
ถ้าแก้ Regedit ในส่วน LoginMode=2 และสร้าง user จะ connect ทันทีไม่ได้
จะใช้ conn = New SqlConnection("server=.\sqlexpress;user id=thai;password=thai2007;database=dbthai") ไม่ได้
 ต้อง reboot เครื่องก่อน เพราะปัญหานี้ผมพบในเครื่องที่ติด deepfreeze
แหล่งเก็บข้อมูลของ SQL Server คือโฟรเดอร์ใด
อยู่ใน C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\
ต.ย.ผลการสร้างฐานข้อมูลชื่อ dbthaiall ใน SQLExpress คล้ายกับ dbthai.mdb มี 2 ระเบียน
เก็บข้อมูลใน C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\
 โดย dbthaiall.mdf มีขนาด 2,293,760 bytes และ dbthaiall_log.LDF มีขนาด 516,096 bytes
 ถ้าไม่มีแฟ้ม dbthaiall_log.LDF ระบบจะสร้างขึ้นอัตโนมัติ
 ผมมี dbthaiall.zip 126 KB ให้นำไปทดสอบ
แหล่งเก็บข้อมูลของ MySQL Server อยู่ในโฟรเดอร์ใด
เช่น โฟรเดอร์ C:\thaiabc\mysql\data\dbthai
เปิด MSDN แล้วพบว่า ms-help://MS.MSDNQTR.v80.en invalid
อาจมีวิธีแก้ไขหลายวิธี แต่ที่ผมทดสอบแล้วได้ผลมีขั้นตอนสั้น ๆ ดังนี้
 1. ไปที่ C:\Program Files\Common Files\Microsoft Shared\Help 8\Microsoft Document Explorer 2005
 2. สั่ง install.exe แล้วเลือก Repair แล้วทำไปจนจบ
 3. หลัง Reboot เครื่อง ผมใช้ MSDN ได้ตามปกติครับ
ลงทะเบียน ASP.NET เข้ากับ IIS ผ่าน DOS Prompt
   1. ติดตั้ง IIS ใน Application Server
 2. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727> aspnet_regiis.exe -i
 | 
 | ความหมายของสิ่งที่น่าสนใจ และตัวอย่างคำสั่ง
โอดีบีซี (ODBC)
โอดีบีซี (ODBC = Open Database Connectivity) คือ ส่วนต่อประสานระหว่าง  ภาษาโปรแกรม (Program Language) กับ ตัวขับฐานข้อมูล เป็นบริการที่แยกอิสระจาก ภาษาโปรแกรม โปรแกรมประยุกต์ ระบบฐานข้อมูล และระบบปฏิบัติการ ส่วนต่อประสานนี้รองรับข้อคำถามเอสคิวแอล (SQL) เพื่อเข้าถึงและจัดการข้อมูล ผ่านอินเทอร์พรีเตอร์ (Interpreter) ระหว่าง โปรแกรมประยุกต์ กับ ตัวขับฐานข้อมูล ทำให้ผู้พัฒนาโปรแกรมได้สะดวก โดยไม่ต้องยึดติดวิธีการ หรือลักษณะจำเพาะของตัวขับฐานข้อมูลที่เลือกใช้ 
ดีเอสเอ็นในโอดีบีซี (DSN in ODBC) ?
ดีเอสเอ็น (DSN = Data Source Name) คือ ชื่อแหล่งข้อมูลที่ถูกสร้างผ่านโอดีบีซี เพื่อใช้อ้างอิงการเชื่อมประสานกับตัวขับฐานข้อมูล และระบบฐานข้อมูล ถ้าในโอดีบีซีไม่มีตัวขับฐานข้อมูลที่ต้องการใช้ก็สามารถติดตั้งตัวขับโอดีบีซีเพิ่มเติมได้  การสร้างดีเอสเอ็นให้ภาษาโปรแกรมเรียกใช้มี 3 แบบ คือ แบบเฉพาะผู้ใช้ (User DSN) แบบผู้ใช้ทุกคนในเครื่อง (System DSN)  และ แบบอ้างอิงจากแฟ้ม (File DSN)
ตัวอย่างโปรแกรมที่ใช้โอดีบีซี (ODBC Sample)
' Imports System.Data.Odbc
Dim ConnString As String = "Dsn=modbc351mysql;Uid=admin;Pwd=p"
Dim sql As String = "select user,password from user"
Dim oConn As OdbcConnection = New Odbc.OdbcConnection(ConnString)
' Dim strthai as String = "SET NAMES 'tis620'" 
' Dim cmdCat as New OdbcCommand(strthai,oConn)
' oConn.Open()
' cmdCat.ExecuteNonQuery()
Dim CmdCat As OdbcCommand = New OdbcCommand(sql, oConn)
oConn.Open()
Dim ReaderCat As OdbcDataReader = CmdCat.ExecuteReader()
Dim s As String = ""
Do While ReaderCat.Read() : s &= ">" & ReaderCat.GetString(0) & Chr(10) : Loop
MsgBox(s)
ReaderCat.Close()
oConn.Close() เอดีโอ (ADO) ?
เอดีโอ (ADO = ActiveX Data Objects) คือ ชุดส่วนประกอบวัตถุ (Component Object Model)  มีหน้าที่เป็นอินเตอร์เฟซโปรแกรมประยุกต์ (API = Application Program Interface) สำหรับการเชื่อมโยงแหล่งข้อมูล (OLEDB = Object Linking and Embedding Database)  กับภาษาโปรแกรม (Program Language) เพื่อให้ผู้พัฒนาเชื่อมต่อข้อมูลโดยตรง และไม่จำเป็นต้องรู้ว่าฐานข้อมูลเก็บในรูปแบบใด ผู้พัฒนาสามารถเลือกใช้งานเอดีโอ (ADO) แทนโอดีบีซี (ODBC) สำหรับเข้าถึงระบบฐานข้อมูลได้ 
การเข้าถึงข้อมูลด้วยเอดีโอ มี 2 แบบ คือ ดาต้าเซท (DataSet) และดาต้าโพไวเดอร์ (Data Provider)
การทำงานของดาต้าเซท คือ คัดลอกข้อมูลเข้าสู่หน่วยความจำและตัดการเชื่อมต่อ สามารถปรับปรุงแก้ไขมูลในหน่วยความจำเสมือนแก้ในฐานข้อมูล เมื่อแก้ไขแล้วสามารถส่งข้อมูลจากหน่วยความจำไปแทนข้อมูลในฐานข้อมูล
การทำงานของดาต้าโพไวเดอร์ คือ ให้บริการเชื่อมต่อ และบริการกิจกรรมจากการเชื่อมต่อ ซึ่งใช้บริการได้ 2 แบบ
คือ เอสคิวแอลดาตาโพไวเดอร์ (SQL Data Provider) 
สำหรับเอสคิวแอลเซอร์ฟเวอร์ 7.0 (Microsoft's SQL Server 7.0) หรือสูงกว่าโดยเฉพาะ 
ส่วนโอแอลอีดีบีดาต้าโพไวเดอร์ (OleDb DataProvider) สำหรับเชื่อมต่อฐานข้อมูลแบบอื่น เช่น Access, MySQL หรือ Oracle ซึ่งมีคลาสให้ใช้ 4 ระดับ ดังนี้ 1)Connection Object 2)Command Object 3)DataReader Object 4)DataAdapter Object 
ตัวอย่าง Data Provider แบบ SQL Data Provider ใช้คลาส 2 ระดับ 
' Imports system.data.sqlclient
 Dim conn As SqlConnection
 Dim myCommand As SqlCommand
 conn = New SqlConnection("server=.\sqlexpress;user id=x;password=y;database=z")
 conn.Open()
 Dim sql As String = "insert into t1 values (1,'aaa')"
 myCommand = New SqlCommand(sql, conn)
 Dim ra As Integer = myCommand.ExecuteNonQuery() ' ra = 1
 MessageBox.Show("New Row Inserted " & ra)
 conn.Close()
 ตัวอย่าง Data Provider แบบ SQL Data Provider ใช้คลาส 3 ระดับ
 ' Imports system.data.sqlclient
 Dim conn As SqlConnection
 Dim myCommand As SqlCommand
 Dim s As String = ""
 conn = New SqlConnection("server=.\sqlexpress;user id=x;password=y;database=z")
 conn.Open()
 myCommand = New SqlCommand("select * from tbthai", conn)
 Dim reader As SqlDataReader = myCommand.ExecuteReader()
 While reader.Read()
 s &= reader(1) & Chr(10) 'only name 
End While
 MessageBox.Show(s)
 conn.Close()
ตัวอย่าง Data Provider แบบ OleDB Data Provider ใช้คลาส 3 ระดับ
 ' Imports system.data.oledb
 Dim strconn As String = "provider=microsoft.jet.oledb.4.0;data source=c:\dthai97.mdb"
 Dim cn As New OleDbConnection(strconn)
 Dim strsql As String = "select * from tbthai"
 Dim cm As New OleDbCommand(strsql, cn)
 cn.Open()
 Dim dr As OleDbDataReader = cm.ExecuteReader()
 Dim s As String = ""
 While dr.Read()
 s &= dr.Item(0) & "," & dr.Item(1) & "," & dr.Item(2) & Chr(10)
End While
 msgbox(s)
 cn.Close()
ตัวอย่าง Data Set และ OleDB Data Provider ใช้คลาส 3 ระดับ
' Imports System.Data.OleDb
' Dim da As New OleDbDataAdapter
' Dim ds As New DataSet
Dim strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/dthai97.mdb"
Dim cn As New OleDbConnection(strconn)
da.SelectCommand = New OleDbCommand("select * from tbthai", cn)
da.Fill(ds, "tb")
DataGridView1.DataSource = ds.Tables("tb")
 Dim cb As New OleDbCommandBuilder(da)
Try
  Dim chg As Integer = da.Update(ds, "tb")
  MsgBox(chg) 'MsgBox(DataGridView1.Rows.Count())
Catch ex As Exception
  MsgBox(ex.Message)
End Try
 | 
 |   | เคยพบปัญหาว่า สั่ง Start debugging หรือทดสอบโปรแกรมแล้ว ไม่ประมวลผล
แต่พบ error message ว่า พบข้อผิดพลาดขณะประมวลผลโปรเจค แก้ไขโดยเข้าไปใน properties ของ project
แล้วเลือก Enable the Visual Studio hosting process ก็จะสั่ง debug ได้ตามปรกติ | 
 |   | เข้า DOS mode เพื่อเขียนโปรแกรม Visual C แล้วสั่ง Compile และ Execute โดยไม่ต้องผ่าน IDE
DOS Mode echo Module Module1 > y.vb
 echo Sub main() >> y.vb
 echo Console.WriteLine(5) >> y.vb
 echo End Sub : End Module >> y.vb
 vbc y.vb
 y
 | 
 |   | พบว่าในห้องปฏิบัติการ มีเครื่องคอมพิวเตอร์บางเครื่องสร้าง project ไว้ใน directory ทันทีที่ create project
แต่บางเครื่องจะสร้างแบบ temporary เมื่อสั่ง save จึงจะถามว่าเก็บเข้า directory ใด ซึ่งพบว่ามี option ให้เลือกกำหนดว่าจะจัดเก็บแบบใดได้ | 
 | เอกสารอ้างอิง [1] เรวัตร ธรรมาอภิรมย์, "เจาะลึกเทคโนโลยีใหม่ Microsoft .net Framework", บริษัท เอส.พี.ซี.พริ้นติ้ง จำกัด, กรุงเทพฯ, 2544.
 [2] พร้อมเลิศ หล่อวิจิตร, "คู่มือเรียน Visual Basic 2005", บริษัท โปรวิชั่น จำกัด., กรุงเทพฯ, 2549.
 [3] ธวัชชัย สุริยะทองธรรม, "พัฒนาเว็บแอพพลิเคชั่น ASP.NET", บริษัท ซัคเซส มีเดีย จำกัด., กรุงเทพฯ, 2548.
 [4] ยุทธนา ลีลาศวัฒนกุล, "คู่มือการเขียนโปรแกรมและใช้งาน Visual C++.NET", สำนักพิมพ์อินโฟเพรส, กรุงเทพฯ, 2546.
 [5] กิตติ ภักดีวัฒนะกุล, จำลอง ครูอุตสาหะ, "ASP ฉบับโปรแกรมเมอร์", บริษัท เคทีพี คอมพ์ แอนด์ คอนซัลท์ จำกัด., กรุงเทพฯ, 2543.
 | 
 |