VB.Net: Error "System.IO.IOException" comes at runtime - vb.net

The error of "System.IO.IOException" is coming at run time.
The error message which appear is as follows:
System.IO.IOException: The Parameter is incorrect.
at Sysytem>IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream.BeginWriteCore(Byte[]array, Int32 offset, Int32 numbytes, AsyncCallback userCallback, Object stateObject)
at System.IO.Ports.SerialStream.Write(Byte[]array, Int32 offset, Int32 count, Int32 timeout)
at System.IO.Ports.Serialport.Write(String text)
at WindowsApplication1.Form1.Button3_Click(Object sender, EventArgs e) in C:\Documents and Settings\user\Desktop\Nikunj\data5\WindowsApplication1\Neuation.vb:Line 151
Now the line 151 is: SerialPort1.Write("2)" & vbCrLf)
This is my whole code:
Public Class Form1
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
For i As Integer = 0 To _
My.Computer.Ports.SerialPortNames.Count - 1
cbbCOMPorts.Items.Add( _
My.Computer.Ports.SerialPortNames(i))
Next
Button7.Enabled = False
Timer1.Enabled = False
End Sub
' Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
'End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'While Button1.Enabled = True
If IsNumeric(Button1) = False Then
If NumericUpDown1.Value < 20000 Then
NumericUpDown1.Value = NumericUpDown1.Value + 10
TextBox1.Text = NumericUpDown1.Value
'If ProgressBar1.Value < 175 Then
'ProgressBar1.Value = ProgressBar1.Value + 4
'End If
End If
End If
Button1.Enabled = False
Button1.Enabled = True
'End While
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If IsNumeric(Button2) = False Then
If NumericUpDown1.Value > 10 Then
NumericUpDown1.Value = NumericUpDown1.Value - 10
'TextBox1.Text = "RCF"
'If ProgressBar1.Value < 175 Then
'ProgressBar1.Value = ProgressBar1.Value - 4
'End If
End If
End If
End Sub
' Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
' Try
'SerialPort1.Write("2&" & RichTextBox2.Text & vbCrLf)
' If NumericUpDown1.Value < 100 Then
' SerialPort1.Write("2&000" & NumericUpDown1.Value & vbCrLf)
' End If
' If NumericUpDown1.Value < 1000 Then
' SerialPort1.Write("2&00" & NumericUpDown1.Value & vbCrLf)
' End If
' If NumericUpDown1.Value < 10000 Then
' SerialPort1.Write("2&0" & NumericUpDown1.Value & vbCrLf)
' End If
' If NumericUpDown1.Value > 9999 Then
' SerialPort1.Write("2&" & NumericUpDown1.Value & vbCrLf)
' End If
' SerialPort1.Write("2&" & NumericUpDown1.Value & vbCrLf)
' With RichTextBox1
' .SelectionColor = Color.Black
'.AppendText(RichTextBox2.Text & vbCrLf)
' .ScrollToCaret()
' End With
' RichTextBox2.Text = String.Empty
' Catch ex As Exception
' MsgBox(ex.ToString)
' End Try
' End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub RichTextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox2.TextChanged
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If SerialPort1.IsOpen Then
End If
Try
With SerialPort1
.PortName = cbbCOMPorts.Text
.BaudRate = 19200
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
'.Encoding = System.Text.Encoding.Unicode
End With
SerialPort1.Open()
RichTextBox2.Text = cbbCOMPorts.Text & " connected."
Button4.Enabled = False
Button7.Enabled = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub DataReceived( _
ByVal sender As Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles SerialPort1.DataReceived
' RichTextBox1.Invoke(New _
' myDelegate(AddressOf updateTextBox), _
' New Object() {})
End Sub
Public Delegate Sub myDelegate()
Public Sub updateTextBox()
'With RichTextBox1
'.Font = New Font("Garamond", 12.0!, FontStyle.Bold)
'.SelectionColor = Color.Red
' .AppendText(SerialPort1.ReadExisting)
'.ScrollToCaret()
'End With
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
If NumericUpDown1.Value < 100 Then
SerialPort1.Write("2&000" & NumericUpDown1.Value & vbCrLf)
End If
If NumericUpDown1.Value < 1000 Then
SerialPort1.Write("2&00" & NumericUpDown1.Value & vbCrLf)
End If
If NumericUpDown1.Value < 10000 Then
SerialPort1.Write("2&0" & NumericUpDown1.Value & vbCrLf)
End If
If NumericUpDown1.Value > 9999 Then
SerialPort1.Write("2&" & NumericUpDown1.Value & vbCrLf)
End If
' SerialPort1.Write("2&" & NumericUpDown1.Value & vbCrLf)
SerialPort1.Write("2)" & vbCrLf)
'With RichTextBox1
' .SelectionColor = Color.Black
'.AppendText(RichTextBox2.Text & vbCrLf)
' .ScrollToCaret()
'End With
RichTextBox2.Text = cbbCOMPorts.Text & " connected."
Catch ex As Exception
MsgBox(ex.ToString)
End Try
' SerialPort1.Write("2)" & vbCrLf)
Timer1.Enabled = True
Button3.Enabled = False
Button6.Enabled = True
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
SerialPort1.Write("2*" & vbCrLf)
Button3.Enabled = True
Button6.Enabled = False
Timer1.Enabled = False
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Try
SerialPort1.Close()
RichTextBox2.Text = SerialPort1.PortName & " disconnected."
Button4.Enabled = True
Button7.Enabled = False
Timer1.Enabled = False
Button3.Enabled = True
Button6.Enabled = False
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub cbbCOMPorts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbCOMPorts.SelectedIndexChanged
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If NumericUpDown3.Value > 0 Then
NumericUpDown3.Value = NumericUpDown3.Value - 1
If NumericUpDown3.Value = 0 Then
' If NumericUpDown2.Value > 0 Then
'NumericUpDown2.Value = NumericUpDown2.Value - 1
'If NumericUpDown2.Value >= 0 And NumericUpDown3.Value = 0 Then
' NumericUpDown3.Value = 59
'End If
'End If
End If
Else 'NumericUpDown3.Value = 59
If NumericUpDown2.Value > 0 Then
NumericUpDown2.Value = NumericUpDown2.Value - 1
If NumericUpDown2.Value >= 0 And NumericUpDown3.Value = 0 Then
NumericUpDown3.Value = 59
End If
End If
End If
If NumericUpDown3.Value = 0 And NumericUpDown2.Value = 0 Then
Timer1.Enabled = False
SerialPort1.Write("2*" & vbCrLf)
Timer1.Enabled = False
Button3.Enabled = True
Button6.Enabled = False
End If
End Sub
Private Sub NumericUpDown2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown2.ValueChanged
End Sub
Private Sub NumericUpDown3_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown3.ValueChanged
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Display_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles Display.LinkClicked
End Sub
Private Sub ContextMenuStrip1_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs)
End Sub
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
End Sub
End Class
Another thing, this error comes only when i try to run the application in windows XP. It work without any error in Windows 7.
Please help me how to resolve the Exception error. I thing error is related to serial port1. It is not able to transmit data.
The application is to run the motor. It easily get connect to COM Port but when i click on START Button the application gets stop and the above error message is shown.
Please Help me to resolve the issue. Thank in advance.

Related

MS Access Query In VB.NET 2008

The below code works in this way: When I enter data inside my textboxes, they go straight to my database and then if I click up button on the numeric up and down, it will give me empty textboxes to put data on again.
If I click on the down button in the numeric up and down, it will show me the previous data I entered in their respective textboxes. That's exactly what I have been wanting to do, but the problem is it only updates the database (obviously because of the UPDATE query) and overwrites the previously saved data.
Is there anyway that I can still achieve the same result (the one I mentioned about still being able to see the data I entered previously by the use of the numeric up and down) but the data previously stored in the database will not be overwritten?
Imports System.Data.OleDb
Public Class Form1
Dim ds As DataSet
Dim da As OleDbDataAdapter
Dim tables As DataTableCollection
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form2.ShowDialog()
Form2.Dispose()
End Sub
Private Sub RadioButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton1.Click
Label1.Text = "1"
Button1.PerformClick()
End Sub
Private Sub RadioButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton2.Click
Label1.Text = "2"
Button1.PerformClick()
End Sub
Private Sub RadioButton3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton3.Click
Label1.Text = "3"
Button1.PerformClick()
End Sub
Private Sub RadioButton4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton4.Click
Label1.Text = "4"
Button1.PerformClick()
End Sub
Public Sub clear()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
TextBox1.Select()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
NumericUpDown1.Value = ComboBox1.SelectedIndex
Dim dr As DataRow
Dim i As Integer
If Integer.TryParse(ComboBox1.SelectedValue.ToString, i) Then
i = ComboBox1.SelectedValue - 1
End If
dr = ds.Tables(0).Rows(i)
TextBox1.Text = dr("Question").ToString
TextBox2.Text = dr("Answer1").ToString
TextBox3.Text = dr("Answer2").ToString
TextBox4.Text = dr("Answer3").ToString
TextBox5.Text = dr("Answer4").ToString
Label1.Text = dr("RightAnswer").ToString
Label8.Text = ComboBox1.Text
If Label1.Text = "1" Then
RadioButton1.Checked = True
ElseIf Label1.Text = "2" Then
RadioButton2.Checked = True
ElseIf Label1.Text = "3" Then
RadioButton3.Checked = True
ElseIf Label1.Text = "4" Then
RadioButton4.Checked = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.Open()
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [Questions]", con)
da.Fill(ds, "Questions")
Dim view1 As New DataView(tables(0))
With ComboBox1
.DataSource = ds.Tables("Questions")
.ValueMember = "ID"
.DisplayMember = "ID"
.SelectedIndex = 0
End With
con.Close()
ComboBox1.SelectedIndex = NumericUpDown1.Value
NumericUpDown1.Value = ComboBox1.SelectedIndex
NumericUpDown1.Maximum = ComboBox1.Items.Count - 1
End Sub
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
ComboBox1.SelectedIndex = NumericUpDown1.Value
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
con.Open()
Dim update_user As New Data.OleDb.OleDbCommand("UPDATE Questions SET [Question]= #Q, [Answer1]= #A1, [Answer2]= #A2, [Answer3]= #A3, [Answer4]= #A4, [RightAnswer]= #RA WHERE ID = #ID;", con)
update_user.Parameters.AddWithValue("#Q", TextBox1.Text)
update_user.Parameters.AddWithValue("#A1", TextBox2.Text)
update_user.Parameters.AddWithValue("#A2", TextBox3.Text)
update_user.Parameters.AddWithValue("#A3", TextBox4.Text)
update_user.Parameters.AddWithValue("#A4", TextBox5.Text)
update_user.Parameters.AddWithValue("#RA", Label1.Text)
update_user.Parameters.AddWithValue("#ID", Label8.Text)
update_user.ExecuteNonQuery()
update_user.Dispose()
con.Close()
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [Questions]", con)
da.Fill(ds, "Questions")
End Sub
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
Button1.PerformClick()
End Sub
Private Sub TextBox2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyUp
Button1.PerformClick()
End Sub
Private Sub TextBox3_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyUp
Button1.PerformClick()
End Sub
Private Sub TextBox4_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyUp
Button1.PerformClick()
End Sub
Private Sub TextBox5_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox5.KeyUp
Button1.PerformClick()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
NumericUpDown1.Enabled = False
If NumericUpDown1.Value = NumericUpDown1.Value + 1 Then
NumericUpDown1.Enabled = True
NumericUpDown1.Value = NumericUpDown1.Value - 1
End If
Else
NumericUpDown1.Enabled = True
End If
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
NumericUpDown1.Enabled = False
If NumericUpDown1.Value = NumericUpDown1.Value + 1 Then
NumericUpDown1.Value = NumericUpDown1.Value - 1
End If
Else
NumericUpDown1.Enabled = True
End If
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
NumericUpDown1.Enabled = False
If NumericUpDown1.Value = NumericUpDown1.Value + 1 Then
NumericUpDown1.Value = NumericUpDown1.Value - 1
End If
Else
NumericUpDown1.Enabled = True
End If
End Sub
Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
NumericUpDown1.Enabled = False
If NumericUpDown1.Value = NumericUpDown1.Value + 1 Then
NumericUpDown1.Value = NumericUpDown1.Value - 1
End If
Else
NumericUpDown1.Enabled = True
End If
End Sub
Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
NumericUpDown1.Enabled = False
If NumericUpDown1.Value = NumericUpDown1.Value + 1 Then
NumericUpDown1.Value = NumericUpDown1.Value - 1
End If
Else
NumericUpDown1.Enabled = True
End If
End Sub
End Class

Sending items to database and making a receipt in VB.NET

We have another IT project, and this time it's on VB.NET, it's actually going pretty good compared to the one we did on Java. So it's still a POS System, and I have six functions of the POS (for admins, and 4 for employees). Right now I'm almost done with the Cash Register function. I have a problem, though. The menu items are in buttons, and once you click a button, it appears in three listboxes (one for item name, quantity and price), and once a button is clicked more than once, it looks for the string with its name and updates the price and quantity. A keypad is adjacent to the buttons, for the input of the customer's payment. Once btnTransact is clicked, it checks for equality of the total amount and the amount paid. So it goes through if else statements and once everything is niff and dandy it shows that the transaction is completed in a message box.
I need the items in the listboxes to appear in either a form or a message box (if that's possible), but I don't know how. Also, I need the listbox items to be sent to a database, tbl_Invoice with columns "Invoice Number (autonumber)", "Invoice Date (there's a realtime clock in my POS)", "Product Code (in tbl_Products, each item has a specific item code", "Quantity", "Unit Price", "Employee ID (I have a log-in as well, and I need to get the Employee ID based on the logged-in user from tbl_Employees)". I will provide appendices.
Also, I have partially added a DisplayDeceipt sub just in case.
I'm sorry if I do not know a lot about VB.NET, only basic functions are being taught to us, and what they're asking from us is waaaay beyond basic. Your help is greatly appreciated. Thank you]1
Imports System.Data.OleDb
Public Class frmCR
Dim intTotal, intPlace As Integer
Dim quantCCS, quantSalad, quantKare, quantGarlic, quantAdobo, quantMushroom, quantAsul, quantDilaw, quantBasket, quantIslands As Integer
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
txtPaid.Text += btn1.Text
End Sub
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
txtPaid.Text += btn2.Text
End Sub
Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
txtPaid.Text += btn3.Text
End Sub
Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
txtPaid.Text += btn4.Text
End Sub
Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
txtPaid.Text += btn5.Text
End Sub
Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
txtPaid.Text += btn6.Text
End Sub
Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
txtPaid.Text += btn7.Text
End Sub
Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
txtPaid.Text += btn8.Text
End Sub
Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
txtPaid.Text += btn9.Text
End Sub
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
txtPaid.Text += btn0.Text
End Sub
Private Sub btnDeci_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeci.Click
txtPaid.Text += btnDeci.Text
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtPaid.Clear()
End Sub
Private Sub btnCCS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCCS.Click
quantCCS += 1
If quantCCS = 1 Then
lstItems.Items.Add("CAESALAD")
lstQuant.Items.Add(quantCCS)
lstPrice.Items.Add("160")
Else
intPlace = lstItems.FindStringExact("CAESALAD")
lstQuant.Items(intPlace) = (quantCCS)
lstPrice.Items(intPlace) += 160
End If
intTotal += 160
lblTotal.Text = intTotal
End Sub
Private Sub tmrCR_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCR.Tick
lblTime.Text = Format(Now, "MM-dd-yyyy hh:mm:ss")
End Sub
Private Sub frmCR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tmrCR.Enabled = True
End Sub
Private Sub btnSalad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalad.Click
quantSalad += 1
If quantSalad = 1 Then
lstItems.Items.Add("BBFSALAD")
lstQuant.Items.Add(quantSalad)
lstPrice.Items.Add("160")
Else
intPlace = lstItems.FindStringExact("BBFSALAD")
lstQuant.Items(intPlace) = (quantSalad)
lstPrice.Items(intPlace) += 160
End If
intTotal += 160
lblTotal.Text = intTotal
End Sub
Private Sub btnKare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKare.Click
quantKare += 1
If quantKare = 1 Then
lstItems.Items.Add("KAREKARE")
lstQuant.Items.Add(quantKare)
lstPrice.Items.Add("210")
Else
intPlace = lstItems.FindStringExact("KAREKARE")
lstQuant.Items(intPlace) = (quantKare)
lstPrice.Items(intPlace) += 210
End If
intTotal += 210
lblTotal.Text = intTotal
End Sub
Private Sub btnGarlic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGarlic.Click
quantGarlic += 1
If quantGarlic = 1 Then
lstItems.Items.Add("TAPAO")
lstQuant.Items.Add(quantGarlic)
lstPrice.Items.Add("180")
Else
intPlace = lstItems.FindStringExact("TAPAO")
lstQuant.Items(intPlace) = (quantGarlic)
lstPrice.Items(intPlace) += 180
End If
intTotal += 180
lblTotal.Text = intTotal
End Sub
Private Sub btnAdobo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdobo.Click
quantAdobo += 1
If quantAdobo = 1 Then
lstItems.Items.Add("ADOBODILAW")
lstQuant.Items.Add(quantAdobo)
lstPrice.Items.Add("145")
Else
intPlace = lstItems.FindStringExact("ADOBODILAW")
lstQuant.Items(intPlace) = (quantAdobo)
lstPrice.Items(intPlace) += 145
End If
intTotal += 145
lblTotal.Text = intTotal
End Sub
Private Sub btnMushroom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMushroom.Click
quantMushroom += 1
If quantMushroom = 1 Then
lstItems.Items.Add("MUSHCHICKEN")
lstQuant.Items.Add(quantMushroom)
lstPrice.Items.Add("160")
Else
intPlace = lstItems.FindStringExact("MUSHCHICKEN")
lstQuant.Items(intPlace) = (quantMushroom)
lstPrice.Items(intPlace) += 160
End If
intTotal += 160
lblTotal.Text = intTotal
End Sub
Private Sub btnAsul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAsul.Click
quantAsul += 1
If quantAsul = 1 Then
lstItems.Items.Add("KNGASUL")
lstQuant.Items.Add(quantAsul)
lstPrice.Items.Add("35")
Else
intPlace = lstItems.FindStringExact("KNGASUL")
lstQuant.Items(intPlace) = (quantAsul)
lstPrice.Items(intPlace) += 35
End If
intTotal += 35
lblTotal.Text = intTotal
End Sub
Private Sub btnDilaw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDilaw.Click
quantDilaw += 1
If quantDilaw = 1 Then
lstItems.Items.Add("KNGDILAW")
lstQuant.Items.Add(quantDilaw)
lstPrice.Items.Add("35")
Else
intPlace = lstItems.FindStringExact("KNGDILAW")
lstQuant.Items(intPlace) = (quantAsul)
lstPrice.Items(intPlace) += 35
End If
intTotal += 35
lblTotal.Text = intTotal
End Sub
Private Sub btnBasket_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBasket.Click
quantBasket += 1
If quantBasket = 1 Then
lstItems.Items.Add("ICECRMBASKET")
lstQuant.Items.Add(quantBasket)
lstPrice.Items.Add("110")
Else
intPlace = lstItems.FindStringExact("ICECRMBASKET")
lstQuant.Items(intPlace) = (quantAsul)
lstPrice.Items(intPlace) += 110
End If
intTotal += 110
lblTotal.Text = intTotal
End Sub
Private Sub btnIslands_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIslands.Click
quantIslands += 1
If quantIslands = 1 Then
lstItems.Items.Add("TSOKOISLAND")
lstQuant.Items.Add(quantIslands)
lstPrice.Items.Add("180")
Else
intPlace = lstItems.FindStringExact("TSOKOISLAND")
lstQuant.Items(intPlace) = (quantIslands)
lstPrice.Items(intPlace) += 180
End If
intTotal += 180
lblTotal.Text = intTotal
End Sub
Private Sub btnTransact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransact.Click
Dim intAmount, intPricePaid, intLack, intSuffice As Integer
If txtPaid.Text <> "" Or (lstItems.Items.Count = -1) Then
intAmount = lblTotal.Text
intPricePaid = txtPaid.Text
If intAmount > intPricePaid Then
intLack = intAmount - intPricePaid
Do
intSuffice = InputBox("Insufficient amount paid. Please ask Php " & intLack & "." & vbNewLine & "Enter amount:", "Insufficient Amount", MessageBoxButtons.OK, MessageBoxIcon.Error)
intLack = intLack - intSuffice
Loop While intLack > 0
If intLack = 0 Then
MessageBox.Show("Transaction Completed. There is no change. Here is your receipt.", "Transaction success", MessageBoxButtons.OK, MessageBoxIcon.Information)
lstItems.Items.Clear()
lstQuant.Items.Clear()
lstPrice.Items.Clear()
txtPaid.Text = ""
intTotal = 0
lblTotal.Text = "0.00"
ElseIf intLack < 0 Then
MessageBox.Show("Transaction Completed. The change is Php " & intLack * -1 & ". Here is your receipt.", "Transaction success", MessageBoxButtons.OK, MessageBoxIcon.Information)
lstItems.Items.Clear()
lstQuant.Items.Clear()
lstPrice.Items.Clear()
txtPaid.Text = ""
intTotal = 0
lblTotal.Text = "0.00"
End If
ElseIf intAmount = intPricePaid Then
MessageBox.Show("Transaction Completed. There is no change. Here is your receipt.", "Transaction success", MessageBoxButtons.OK, MessageBoxIcon.Information)
lstItems.Items.Clear()
lstQuant.Items.Clear()
lstPrice.Items.Clear()
txtPaid.Text = ""
intTotal = 0
lblTotal.Text = "0.00"
Else
MessageBox.Show("Transaction Completed. The change is Php " & intPricePaid - intAmount & ". Here is your receipt.", "Transaction success", MessageBoxButtons.OK, MessageBoxIcon.Information)
lstItems.Items.Clear()
lstQuant.Items.Clear()
lstPrice.Items.Clear()
txtPaid.Text = ""
intTotal = 0
lblTotal.Text = "0.00"
End If
ElseIf txtPaid.Text = "" Or (lstItems.Items.Count = -1) Then
MessageBox.Show("Please input a value.", "Null value", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Public Sub DisplayReceipt()
End Sub
End Class

OleDbException was unhandled [Newbie here]

i got error in this code please
i need this in school its a group project but im only doing this because they dont know how to code, so i participate to do this program, im a begginer in vb, i hope you understand, Thank you :)
Imports System.Data.OleDb
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form9
Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'FoodDataSet.Table1' table. You can move, or remove it, as needed.
Table1BindingSource.AddNew()
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
TextBox1.Text = ("Burger P 12")
ElseIf RadioButton1.Checked = False Then
TextBox1.Text = ("Choose Your Order!")
End If
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
TextBox1.Text = ("Cheese Burger = P 15")
ElseIf RadioButton2.Checked = False Then
TextBox1.Text = ("Choose Your Order!")
End If
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
If RadioButton3.Checked = True Then
TextBox1.Text = ("Ham Burger = P 15")
ElseIf RadioButton3.Checked = False Then
TextBox1.Text = ("Choose Your Order!")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
If RadioButton4.Checked = True Then
TextBox2.Text = ("Potato = P 10")
ElseIf RadioButton4.Checked = False Then
TextBox2.Text = ("Choose Your Order!")
End If
End Sub
Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
If RadioButton5.Checked = True Then
TextBox2.Text = ("Piatos = P 12")
ElseIf RadioButton5.Checked = False Then
TextBox2.Text = ("Choose Your Order!")
End If
End Sub
Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged
If RadioButton6.Checked = True Then
TextBox2.Text = ("Potato Fries = P 15")
ElseIf RadioButton6.Checked = False Then
TextBox2.Text = ("Choose Your Order!")
End If
End Sub
Private Sub RadioButton11_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton11.CheckedChanged
If RadioButton11.Checked = True Then
TextBox3.Text = ("Coke = P 10")
ElseIf RadioButton11.Checked = False Then
TextBox3.Text = ("Choose Your Order!")
End If
End Sub
Private Sub RadioButton8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton8.CheckedChanged
If RadioButton8.Checked = True Then
TextBox3.Text = ("Sprite = P 10")
ElseIf RadioButton8.Checked = False Then
TextBox3.Text = ("Choose Your Order!")
End If
End Sub
Private Sub RadioButton9_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton9.CheckedChanged
If RadioButton9.Checked = True Then
TextBox3.Text = ("Royal = P 10")
ElseIf RadioButton9.Checked = False Then
TextBox3.Text = ("Choose Your Order!")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim con As OleDbConnection
Table1BindingSource.AddNew()
MessageBox.Show("Your Orders in ongoing,Kindly Prepare your money and wait your order, Thank you!")
Me.Validate()
Me.Table1BindingSource.EndEdit()
con = New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0;Data Source=C:\Documents and Settings\WinXP\Desktop\LoadTest HP\WindowsApplication1\Food.mdb")
Me.Table1TableAdapter.Update(Me.FoodDataSet.Table1)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Table1BindingSource.RemoveCurrent()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Private Sub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton7.CheckedChanged
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Form10.Show()
Me.Close()
End Sub
End Class
It means you have a possible exception that wasn't handled you should handle the exception which will even show you a error which can further help you figure out what's wrong with your code :)
How do you handle exceptions? wrap code which uses OleDB with try/catch anywhere you use OleDb you should try/catch it.. remove the try/catch later when you know your code works 100%.
like so..
Try
con = New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0;Data Source=C:\Documents and Settings\WinXP\Desktop\LoadTest HP\WindowsApplication1\Food.mdb")
Catch ex as OleDbException
Msgbox ex.ToString()
End Try
I would wrap where you declare the OleDbConnection as well which is not necessary but it gets all the OleDb stuff in a try/catch
Try
Dim con As OleDbConnection
Table1BindingSource.AddNew()
MessageBox.Show("Your Orders in ongoing,Kindly Prepare your money and wait your order, Thank you!")
Me.Validate()
Me.Table1BindingSource.EndEdit()
con = New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0;Data Source=C:\Documents and Settings\WinXP\Desktop\LoadTest HP\WindowsApplication1\Food.mdb")
Catch ex as OleDbException
Msgbox ex.ToString()
End Try

Visual basic ICMP Pinger?

I am building an ICMP Pinger in visual basic.
I would like to be able to determine the destination address, time out, size of packets, and how many packets to send.
I only have a small amount of programming knowledge, does anybody have any suggestions? Or a more efficient way to run the program?
Here is what i have that is working so far.
Option Explicit On
Option Infer Off
Imports System.Net.NetworkInformation
Imports System.ComponentModel
Public Class Form1
Private WithEvents bwPing As New BackgroundWorker
Private pingTarget As String
Private pingsize As Integer
Private numOfpings As Integer
Dim timeout As Integer
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
' start pinger
bwPing.WorkerReportsProgress = True
bwPing.WorkerSupportsCancellation = True
pingTarget = TextBox2.Text
timeout = ComboBox4.Text
If Not bwPing.IsBusy Then bwPing.RunWorkerAsync()
If ComboBox3.Text & ComboBox1.Text = "" Then
bwPing.CancelAsync()
ListBox1.Items.Add("*****!!!!!***** INVALID ENTRY *****!!!!!*****")
MsgBox(" By failing to prepare, you are preparing to fail. ", MsgBoxStyle.Exclamation)
ElseIf ComboBox3.Text = "" Then
bwPing.CancelAsync()
ListBox1.Items.Add("*****!!!!!***** INVALID ENTRY *****!!!!!*****")
MsgBox(" How many troops are you sending in? ", MsgBoxStyle.Exclamation)
ElseIf ComboBox1.Text = "" Then
bwPing.CancelAsync()
ListBox1.Items.Add("*****!!!!!***** INVALID ENTRY *****!!!!!*****")
MsgBox(" How strong are your soldiers? ", MsgBoxStyle.Exclamation)
Else : numOfpings = CInt(ComboBox3.Text)
pingsize = CInt(ComboBox1.Text)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' cancel pinger
bwPing.CancelAsync()
End Sub
Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
' clear
ListBox1.Items.Clear()
ComboBox1.Text = ""
ComboBox3.Text = ""
ProgressBar1.Value = 0
End Sub
Private Sub bwPing_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles bwPing.DoWork
' ping worker
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
Dim packet(pingsize) As Byte
For i As Integer = 0 To numOfpings - 1
bwPing.ReportProgress(i + 1)
Dim ping As New Ping
Dim reply As PingReply = ping.Send(pingTarget, timeout)
If ComboBox3.Text & ComboBox1.Text = "" Then
bwPing.CancelAsync()
Else
ListBox1.Items.Add("You hit " & pingTarget & " in " & reply.RoundtripTime.ToString() & " ms with " & pingsize & " bytes.")
System.Threading.Thread.Sleep(500)
End If
If worker.CancellationPending Then Exit For
Next
End Sub
Private Sub bwPing_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Handles bwPing.ProgressChanged
' update results
Me.ProgressBar1.Value = e.ProgressPercentage
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = numOfpings
End Sub
Private Sub bwPing_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles bwPing.RunWorkerCompleted
' finished
Me.ListBox1.Items.Add("*!* The battle is over, but not the war *!*")
bwPing.CancelAsync()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False
End Sub
End Class

vb For loop repeat a certain number of times

So I am making a port scanner and have a min and max port, but can't get the port scanner to stop scanning when it reaches the maximum port?
I have tried doing an Exit For when port reaches portmax.
Here is the code:
Public Class Form1
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim counter As Integer
Button2.Enabled = False
'set counter explained before to 0
counter = 0
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
Dim host As String
Dim counter As Integer
Dim portmin As Integer = TextBox3.Text
Dim portmax As Integer = TextBox2.Text
'Set the host and port and counter
counter = counter + 1 'counter is for the timer
host = TextBox1.Text
For port As Integer = portmin To portmax
' Next part creates a socket to try and connect
' on with the given user information.
Dim hostadd As System.Net.IPAddress = _
System.Net.Dns.GetHostEntry(host).AddressList(0)
Dim EPhost As New System.Net.IPEndPoint(hostadd, port)
Dim s As New System.Net.Sockets.Socket( _
System.Net.Sockets.AddressFamily.InterNetwork, _
System.Net.Sockets.SocketType.Stream, _
System.Net.Sockets.ProtocolType.Tcp)
Try
s.Connect(EPhost)
Catch
End Try
If Not s.Connected Then
ListBox1.Items.Add("Port " + port.ToString + " is not open")
Else
ListBox1.Items.Add("Port " + port.ToString + " is open")
ListBox2.Items.Add(port.ToString)
End If
Label3.Text = "Open Ports: " + ListBox2.Items.Count.ToString
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
'stop button
Timer1.Stop()
Timer1.Enabled = False
Button1.Enabled = True
Button2.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add("Scanning: " + TextBox1.Text)
ListBox1.Items.Add("-------------------")
Button2.Enabled = True
Button1.Enabled = False
Timer1.Enabled = True
Timer1.Start()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub ListBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox2.SelectedIndexChanged
End Sub
End Class
I would really appreciate any help
thanks,
Try to stop the Timer while in the scanning.
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
'Your code
Timer1.Enabled = True
End Sub
If thats the problem, and looks like it, you should consider using a Try/Catch block:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Timer1.Enabled = False
'Your code
Catch ex As Exception
'Manage the error
Finally
Timer1.Enabled = True
End Try
End Sub
Try this
For port As Integer = portmin To portmax - 1