EXCEL TOOLS
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
[code]
และปิดด้วย [/code]
ตัวอย่างเช่น [code]dim r as range[/code]
เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่างเพิ่มเติม)Code: Select all
Imports System
Imports System.ComponentModel
Imports System.Threading
Imports System.IO.Ports
Public Class Form1
Delegate Sub SetTextCallback(ByVal [text] As String)
Dim code As String = ""
Dim counter As Integer = 0
Dim SetAIR As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Open()
NumberAIR.Enabled = False
Submit.Enabled = False
AQ_Box.Enabled = False
AQV_Box.Enabled = False
AS_Box.Enabled = False
ASV_Box.Enabled = False
ARX_Box.Enabled = False
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
Dim msgresult As DialogResult
msgresult = MessageBox.Show(" Would you like to close this program ?", "Confirm to close program..", MessageBoxButtons.OKCancel)
If msgresult = DialogResult.Cancel Then
e.Cancel = False
End If
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
code = SerialPort1.ReadExisting
MessageBox.Show(code)
End Sub
Private Sub AQ_Check_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AQ_Check.CheckedChanged
AQ_Box.Enabled = True
AQV_Box.Enabled = False
AS_Box.Enabled = False
ASV_Box.Enabled = False
ARX_Box.Enabled = False
AQV_Box.SelectedIndex = -1
AS_Box.SelectedIndex = -1
ASV_Box.SelectedIndex = -1
ARX_Box.SelectedIndex = -1
NumberAIR.Enabled = True
Submit.Enabled = True
End Sub
Private Sub AQV_Check_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AQV_Check.CheckedChanged
AQ_Box.Enabled = False
AQV_Box.Enabled = True
AS_Box.Enabled = False
ASV_Box.Enabled = False
ARX_Box.Enabled = False
AQ_Box.SelectedIndex = -1
AS_Box.SelectedIndex = -1
ASV_Box.SelectedIndex = -1
ARX_Box.SelectedIndex = -1
NumberAIR.Enabled = True
Submit.Enabled = True
End Sub
Private Sub AS_Check_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AS_Check.CheckedChanged
AQ_Box.Enabled = False
AQV_Box.Enabled = False
AS_Box.Enabled = True
ASV_Box.Enabled = False
ARX_Box.Enabled = False
AQ_Box.SelectedIndex = -1
AQV_Box.SelectedIndex = -1
ASV_Box.SelectedIndex = -1
ARX_Box.SelectedIndex = -1
NumberAIR.Enabled = True
Submit.Enabled = True
End Sub
Private Sub ASV_Check_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ASV_Check.CheckedChanged
AQ_Box.Enabled = False
AQV_Box.Enabled = False
AS_Box.Enabled = False
ASV_Box.Enabled = True
ARX_Box.Enabled = False
AQ_Box.SelectedIndex = -1
AQV_Box.SelectedIndex = -1
AS_Box.SelectedIndex = -1
ARX_Box.SelectedIndex = -1
NumberAIR.Enabled = True
Submit.Enabled = True
End Sub
Private Sub ARX_Check_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ARX_Check.CheckedChanged
AQ_Box.Enabled = False
AQV_Box.Enabled = False
AS_Box.Enabled = False
ASV_Box.Enabled = False
ARX_Box.Enabled = True
AQ_Box.SelectedIndex = -1
AQV_Box.SelectedIndex = -1
AS_Box.SelectedIndex = -1
ASV_Box.SelectedIndex = -1
NumberAIR.Enabled = True
Submit.Enabled = True
End Sub
Private Sub NumberAIR_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumberAIR.TextChanged
If NumberAIR.Text = "" Then
SetAIR = 0
Exit Sub
End If
If Not IsNumeric(NumberAIR.Text) Then
MessageBox.Show("กรุณาใส่ค่าเฉพาะตัวเลขครับ...")
NumberAIR.Text = ""
End If
If IsNumeric(NumberAIR.Text) Then
SetAIR = NumberAIR.Text
End If
End Sub
Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit.Click
Dim AQ_model As String = AQ_Box.SelectedItem
Dim AQV_model As String = AQV_Box.SelectedItem
Dim AS_model As String = AS_Box.SelectedItem
Dim ASV_model As String = ASV_Box.SelectedItem
Dim ARX_model As String = ARX_Box.SelectedItem
If (SetAIR <> 0) And (AQ_Box.SelectedIndex <> -1) Then
ListAIR.Items.Add(" Model : " + AQ_model + " Amount : " + CStr(SetAIR))
ElseIf (SetAIR <> 0) And (AQV_Box.SelectedIndex <> -1) Then
ListAIR.Items.Add(" Model : " + AQV_model + " Amount : " + CStr(SetAIR))
ElseIf (SetAIR <> 0) And (AS_Box.SelectedIndex <> -1) Then
ListAIR.Items.Add(" Model : " + AS_model + " Amount : " + CStr(SetAIR))
ElseIf (SetAIR <> 0) And (ASV_Box.SelectedIndex <> -1) Then
ListAIR.Items.Add(" Model : " + ASV_model + " Amount : " + CStr(SetAIR))
ElseIf (SetAIR <> 0) And (ARX_Box.SelectedIndex <> -1) Then
ListAIR.Items.Add(" Model : " + ARX_model + " Amount : " + CStr(SetAIR))
End If
End Sub
Private Sub ListAIR_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListAIR.MouseDoubleClick
ListAIR.Items.Remove(ListAIR.SelectedItem)
End Sub
Private Sub Reset_List_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Reset_List.Click
ListAIR.Items.Clear()
End Sub
End Class
Code: Select all
Imports System.Data
Imports System.Data.SqlClient
Code: Select all
Private Sub Send_Data_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send_Data.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"
con.Open()
cmd.Connection = con
cmd.CommandText = "INSERT INTO table([field1], [field2]) VALUES([Value1], [Value2])"
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
con.Close()
End Try
End Sub