Bai Giai VB

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 12

Bi 3: Public Class Form1 Dim i As Integer = 99 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.

Click End End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Do i = i - 1 If i < 0 Then i = 99 Label1.Text = i delay(Val(TextBox1.Text)) Loop End Sub Private Sub delay(ByVal i As Integer) Timer1.Interval = i Timer1.Enabled = True Do Application.DoEvents() Loop Until Timer1.Enabled = False End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Enabled = False End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Do Application.DoEvents() Loop End Sub End Class Bai 4: Public Class Form1 Dim i As Integer = 100 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Interval = Val(TextBox1.Text) Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick i = i - 1 If i < 0 Then i = 100 Label1.Text = i End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Timer1.Enabled = False End Sub End Class Bai 5: Public Class Form1 Dim i As Integer = 0 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Do i = i + 1 If i > 180 Then i = 0 Label1.Text = i delay(Val(TextBox1.Text)) Loop End Sub Private Sub delay(ByVal i As Integer) Timer1.Interval = i Timer1.Enabled = True Do Application.DoEvents() Loop Until Timer1.Enabled = False End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Enabled = False End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Do Application.DoEvents() Loop End Sub End Class Bai 6: Public Class Form1 Dim i As Integer = 0 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Interval = Val(TextBox1.Text) Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick i = i + 1 If i > 180 Then i = 0 Label1.Text = i

End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Timer1.Enabled = False End Sub End Class Bai 7: Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged CheckBox5.Checked = Not ((CheckBox1.Checked Xor CheckBox2.Checked)) CheckBox6.Checked = ((Not CheckBox4.Checked) And CheckBox3.Checked) CheckBox7.Checked = CheckBox5.Checked Or CheckBox6.Checked End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Close() SerialPort1.Open() End Sub Private Sub CheckBox7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox7.CheckedChanged SerialPort1.DtrEnable = True End Sub End Class Bai 8: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Close() SerialPort1.Open() End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged CheckBox4.Checked = Not CheckBox2.Checked CheckBox3.Checked = CheckBox1.Checked Or CheckBox4.Checked CheckBox5.Checked = CheckBox3.Checked Xor CheckBox4.Checked End Sub Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged SerialPort1.DtrEnable = True

End Sub End Class Bai 9: Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged CheckBox4.Checked = Not CheckBox1.Checked CheckBox5.Checked = Not CheckBox3.Checked CheckBox6.Checked = Not (CheckBox1.Checked And CheckBox5.Checked) CheckBox7.Checked = Not (CheckBox2.Checked And CheckBox4.Checked) CheckBox8.Checked = Not (CheckBox2.Checked And CheckBox5.Checked) CheckBox9.Checked = Not (CheckBox6.Checked And CheckBox7.Checked And CheckBox8.Checked) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Close() SerialPort1.Open() End Sub Private Sub CheckBox9_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox9.CheckedChanged SerialPort1.DtrEnable = True End Sub End Class Bai 10: Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged CheckBox4.Checked = Not CheckBox1.Checked CheckBox5.Checked = Not CheckBox2.Checked CheckBox6.Checked = Not CheckBox3.Checked CheckBox7.Checked = CheckBox4.Checked And CheckBox5.Checked CheckBox8.Checked = CheckBox7.Checked Xor CheckBox6.Checked End Sub Private Sub CheckBox8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox8.CheckedChanged SerialPort1.DtrEnable = True End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Close() SerialPort1.Open() End Sub End Class Bai 11: Public Class Form1

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged CheckBox5.Checked = Not CheckBox2.Checked CheckBox6.Checked = Not CheckBox3.Checked CheckBox7.Checked = CheckBox4.Checked And CheckBox5.Checked CheckBox8.Checked = CheckBox4.Checked And CheckBox6.Checked CheckBox9.Checked = CheckBox1.Checked Xor CheckBox7.Checked Xor CheckBox8.Checked End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Close() SerialPort1.Open() End Sub Private Sub CheckBox9_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox9.CheckedChanged SerialPort1.DtrEnable = True End Sub End Class Bai 12: Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged CheckBox4.Checked = Not CheckBox1.Checked CheckBox5.Checked = Not CheckBox3.Checked CheckBox6.Checked = Not (CheckBox1.Checked And CheckBox5.Checked) CheckBox7.Checked = Not (CheckBox2.Checked And CheckBox4.Checked) CheckBox8.Checked = Not (CheckBox2.Checked And CheckBox5.Checked) CheckBox9.Checked = Not (CheckBox6.Checked And CheckBox7.Checked And CheckBox8.Checked) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Close() SerialPort1.Open() End Sub Private Sub CheckBox9_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox9.CheckedChanged SerialPort1.DtrEnable = True End Sub End Class

Bai 13: Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged,

CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged CheckBox5.Checked = Not CheckBox1.Checked CheckBox6.Checked = Not CheckBox2.Checked CheckBox7.Checked = Not CheckBox3.Checked CheckBox8.Checked = CheckBox5.Checked Or CheckBox6.Checked CheckBox9.Checked = CheckBox1.Checked Or CheckBox2.Checked CheckBox10.Checked = CheckBox4.Checked Or CheckBox7.Checked CheckBox11.Checked = CheckBox10.Checked And CheckBox9.Checked And CheckBox8.Checked End Sub Private Sub CheckBox11_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox11.CheckedChanged SerialPort1.DtrEnable = True End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Close() SerialPort1.Open() End Sub Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged End Sub End Class Bai 14: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Close() SerialPort1.Open() End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged CheckBox4.Checked = Not CheckBox2.Checked CheckBox3.Checked = CheckBox1.Checked Or CheckBox4.Checked CheckBox5.Checked = CheckBox3.Checked Xor CheckBox4.Checked End Sub Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged SerialPort1.DtrEnable = True End Sub End Class Bai 15: Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged,

CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged CheckBox6.Checked = Not CheckBox3.Checked CheckBox7.Checked = Not CheckBox1.Checked CheckBox5.Checked = Not (CheckBox1.Checked Xor CheckBox4.Checked) CheckBox8.Checked = (CheckBox5.Checked And CheckBox2.Checked And CheckBox3.Checked) CheckBox9.Checked = (CheckBox6.Checked And CheckBox2.Checked And CheckBox4.Checked And CheckBox7.Checked) CheckBox10.Checked = CheckBox8.Checked Or CheckBox9.Checked End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Close() SerialPort1.Open() End Sub Private Sub CheckBox10_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox10.CheckedChanged SerialPort1.DtrEnable = True End Sub End Class Bai 16: Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged CheckBox4.Checked = Not CheckBox2.Checked CheckBox5.Checked = Not (CheckBox1.Checked And CheckBox3.Checked) CheckBox6.Checked = Not (CheckBox1.Checked And CheckBox4.Checked) CheckBox7.Checked = Not (CheckBox2.Checked And CheckBox3.Checked) CheckBox8.Checked = Not (CheckBox5.Checked And CheckBox6.Checked And CheckBox7.Checked) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Close() SerialPort1.Open() End Sub Private Sub CheckBox8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox8.CheckedChanged SerialPort1.DtrEnable = True End Sub End Class

Bai 17: Public Delegate Sub myDelegate() Public Class Form1 Dim x, a As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox2.Text = "" x = Val(TextBox1.Text)

For i = 0 To 15 a = (x And (2 ^ i)) / (2 ^ i) TextBox2.Text = a & TextBox2.Text Next SerialPort1.Write(TextBox2.Text) End Sub Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived TextBox3.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) End Sub Public Sub updateTextBox() TextBox3.AppendText(SerialPort1.ReadExisting) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() With SerialPort1 .PortName = "COM1" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One End With SerialPort1.Open() End Sub Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged End Sub End Class Bai 18: Public Delegate Sub myDelegate() Public Class Form1 Dim i, j As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() With SerialPort1 .PortName = "COM1" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One End With SerialPort1.Open() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click i = Val(TextBox1.Text) TextBox2.Text = Convert.ToString(i, 16) SerialPort1.Write(TextBox2.Text) End Sub

Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived TextBox3.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) End Sub Public Sub updateTextBox() TextBox3.AppendText(SerialPort1.ReadExisting) End Sub End Class Bai 19: Public Delegate Sub myDelegate() Public Class Form1 Dim i, j As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() With SerialPort1 .PortName = "COM1" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One End With SerialPort1.Open() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click i = Val(TextBox1.Text) TextBox2.Text = Convert.ToString(i, 8) SerialPort1.Write(TextBox2.Text) End Sub Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived TextBox3.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) End Sub Public Sub updateTextBox() TextBox3.AppendText(SerialPort1.ReadExisting) End Sub End Class Bai 20: Public Delegate Sub myDelegate() Public Class Form1 Dim i, j As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() With SerialPort1 .PortName = "COM1" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One

End With SerialPort1.Open() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click i = Val(TextBox1.Text) TextBox2.Text = Convert.ToInt32(i, 2) SerialPort1.Write(TextBox2.Text) End Sub Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived TextBox3.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) End Sub Public Sub updateTextBox() TextBox3.AppendText(SerialPort1.ReadExisting) End Sub End Class Bai 21: Public Delegate Sub myDelegate() Public Class Form1 Dim i, j As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() With SerialPort1 .PortName = "COM1" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One End With SerialPort1.Open() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click i = Val(TextBox1.Text) j = Convert.ToInt32(i, 2) TextBox2.Text = Convert.ToString(j, 16) SerialPort1.Write(TextBox2.Text) End Sub Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived TextBox3.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) End Sub Public Sub updateTextBox() TextBox3.AppendText(SerialPort1.ReadExisting) End Sub End Class Bai 22:

Public Delegate Sub myDelegate() Public Class Form1 Dim i, j As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() With SerialPort1 .PortName = "COM1" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One End With SerialPort1.Open() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click i = Val(TextBox1.Text) j = Convert.ToInt32(i, 2) TextBox2.Text = Convert.ToString(j, 8) SerialPort1.Write(TextBox2.Text) End Sub Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived TextBox3.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) End Sub Public Sub updateTextBox() TextBox3.AppendText(SerialPort1.ReadExisting) End Sub End Class Bai 23: Public Delegate Sub myDelegate() Public Class Form1 Dim i As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() With SerialPort1 .PortName = "COM1" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One End With SerialPort1.Open() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click i = TextBox1.Text TextBox2.Text = Convert.ToInt32(i, 16) SerialPort1.Write(TextBox2.Text) End Sub

Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived TextBox3.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) End Sub Public Sub updateTextBox() TextBox3.AppendText(SerialPort1.ReadExisting) End Sub End Class Bai 24: Public Delegate Sub myDelegate() Public Class Form1 Dim i As String Dim j As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() With SerialPort1 .PortName = "COM1" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One End With SerialPort1.Open() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click i = TextBox1.Text j = Convert.ToInt32(i, 16) TextBox2.Text = Convert.ToString(j, 8) SerialPort1.Write(TextBox2.Text) End Sub Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived TextBox3.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) End Sub Public Sub updateTextBox() TextBox3.AppendText(SerialPort1.ReadExisting) End Sub End Class

Bai 25:

You might also like