Sending items to database and making a receipt in VB.NET - 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

Related

So I tried creating a checklist with points in vb.net

I'm still currently trying to create a checklist with points as a reference if you are unsure you have COVID-19. ex. "if you have 1 point then you are still fine"
Right now all checkboxes work except for one which is the second checkbox
Public Class Form1
Dim pts As Byte
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "You have " & pts
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If Me.CheckBox1.Checked = True Then
pts = pts + 1
End If
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If Me.CheckBox2.Checked = True Then
pts = pts + 1
End If
End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
If Me.CheckBox1.Checked = True Then
pts = pts + 98
End If
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
CheckBox1.CheckState = 0
CheckBox2.CheckState = 0
CheckBox3.CheckState = 0
Label1.Text = ""
pts = 0
End Sub
End Class
I don't know what else I can do really
The total values are just added but not subtracted on un-check event. Just simply use Else statement to do so. Look at the following example:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If Me.CheckBox1.Checked = True Then
pts = pts + 1
Else
pts = pts - 1
End If
End Sub

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

String cannot be converted to System.Uri

Code:
Imports System
Imports System.IO
Imports System.Text
Public Class Browser
Dim Tab1Url As String = ""
Dim Tab2Url As String = ""
Dim TabNumber As Integer = 1
Dim DefaultHomePageSavedLocation As String = "C:\ToolBoxData\TinyBrowser\Home.txt"
Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
Label2.Text = "[BROWSER] Loading in Progress......"
ProgressBar1.Value = 50
End Sub
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
WebBrowser1.GoBack()
Label2.Text = "[BROWSER] Going to Last History......"
ProgressBar1.Value = 0
End Sub
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
'Next
WebBrowser1.GoForward()
Label2.Text = "[BROWSER] Going to Next History......"
ProgressBar1.Value = 0
End Sub
Private Sub HomeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HomeToolStripMenuItem.Click
'Home
Dim HomeLink As String = My.Computer.FileSystem.ReadAllText(DefaultHomePageSavedLocation)
WebBrowser1.Navigate(HomeLink)
Label2.Text = "[BROWSER] Going Home......"
ProgressBar1.Value = 0
End Sub
Private Sub ToolStripTextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripTextBox1.Click
Label2.Text = "[USER] Inserting / Copying URL......"
End Sub
Private Sub GoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoToolStripMenuItem.Click
If TabNumber = 1 Then
Tab1Url = ToolStripTextBox1.Text
WebBrowser1.Navigate(Tab1Url)
Button1.Text = ToolStripTextBox1.Text
ElseIf TabNumber = 2 Then
Tab2Url = ToolStripTextBox1.Text
WebBrowser1.Navigate(Tab2Url)
Button2.Text = ToolStripTextBox1.Text
End If
ProgressBar1.Value = 0
End Sub
Private Sub ReloadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReloadToolStripMenuItem.Click
WebBrowser1.Refresh()
Label2.Text = "[BROWSER] Refreshing......"
ProgressBar1.Value = 0
End Sub
Private Sub TinyBrowserV10ByToolBoxWeeblyComToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TinyBrowserV10ByToolBoxWeeblyComToolStripMenuItem.Click
WebBrowser1.Navigate("http://tool-box.weebly.com/")
Label2.Text = "[BROWSER] Redirecting to Our Website......"
ProgressBar1.Value = 0
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Label2.Text = "[BROWSER] Loading Completed."
ToolStripTextBox1.Text = WebBrowser1.Url.ToString
ProgressBar1.Value = 100
End Sub
Private Sub ToolStripTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ToolStripTextBox1.KeyPress
If e.KeyChar = Chr(13) Then
If TabNumber = 1 Then
Tab1Url = ToolStripTextBox1.Text
WebBrowser1.Navigate(Tab1Url)
Button1.Text = ToolStripTextBox1.Text
ElseIf TabNumber = 2 Then
Tab2Url = ToolStripTextBox1.Text
WebBrowser1.Navigate(Tab2Url)
Button2.Text = ToolStripTextBox1.Text
End If
ProgressBar1.Value = 0
End If
End Sub
Private Sub Browser_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = Convert.ToChar(Keys.Back) Then
WebBrowser1.GoBack()
ProgressBar1.Value = 0
End If
End Sub
Private Sub OptionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OptionToolStripMenuItem.Click
Setting.Show()
End Sub
Private Sub Browser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Computer.FileSystem.FileExists(DefaultHomePageSavedLocation) = False Then
My.Computer.FileSystem.CreateDirectory("C:\ToolBoxData\TinyBrowser\")
My.Computer.FileSystem.WriteAllText(DefaultHomePageSavedLocation, "http://hk.yahoo.com", True)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not TabNumber = 1 Then
TabNumber = 1
ChangeTab()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Not TabNumber = 2 Then
TabNumber = 2
ChangeTab()
End If
End Sub
Private Sub ChangeTab()
If TabNumber = 1 Then
WebBrowser1.Url = Tab1Url
ElseIf TabNumber = 2 Then
WebBrowser1.Url = Tab2Url
End If
End Sub
End Class
And the error is:
Value of type "String" cannot be converted to "System.Uri" (Line 121, 123)
What's the problem?
I've found the solution at another website.
Solution:
Line 121:
WebBrowser1.Url = New Uri(Tab1Url)
Line 123:
WebBrowser1.Url = New Uri(Tab2Url)
Thanks for all your help!

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

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.

Compiling application only source available

I'm trying to compile some code that I found for an Application that I want to use.
Now I've download VB.NET express created a new project and just replaced the code with the one I got, but this isn't creating the forms (textfields etc.) at all, so I can't compile it.
Is this normal ? What else do I have to do to be able to compile it.
This is the source code:
Public Class Form1
Dim psc As String
Dim pwchange As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not My.Settings.pw_save = "" Then
TextBox6.Text = My.Settings.pw_save
CheckBox2.CheckState = CheckState.Checked
End If
If Not My.Settings.new_pw_save = "" Then
TextBox7.Text = My.Settings.new_pw_save
CheckBox1.CheckState = CheckState.Checked
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Document.GetElementById("mainPagePart:verifyCaptcha").InnerText = TextBox5.Text
'Die 1. - 5. Zahlenkombi
WebBrowser1.Document.GetElementById("mainPagePart:rn1").InnerText = TextBox1.Text
WebBrowser1.Document.GetElementById("mainPagePart:rn2").InnerText = TextBox2.Text
WebBrowser1.Document.GetElementById("mainPagePart:rn3").InnerText = TextBox3.Text
WebBrowser1.Document.GetElementById("mainPagePart:rn4").InnerText = TextBox4.Text
'Button bestätigen
'WebBrowser1.Document.Forms(0).InvokeMember("submit")
'Passwort Eingabe
WebBrowser1.Document.GetElementById("mainPagePart:passField").InnerText = TextBox6.Text
'WebBrowser1.Document.GetElementById("mainPagePart:next").InvokeMember("submit")
'Abfrage ob richtige Captcha Eingabe
'WebBrowser1.Document.GetElementById("mainPagePart:next").SetAttribute("value", "Free")
WebBrowser1.Document.GetElementById("mainPagePart:next").Focus()
SendKeys.Send("{ENTER}")
psc = 1
'Dim wert As HtmlElement = WebBrowser1.Document.GetElementById("j_id66")
'MessageBox.Show(wert.InnerText)
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Me.WebBrowser1.Document.Window.ScrollTo(50, 342)
If psc = 1 Then
'Dim wert As HtmlElement = WebBrowser1.Document.GetElementById("j_id66")
' Dim wert As HtmlElement = WebBrowser1.Document.GetElementFromPoint()
'MessageBox.Show(wert.InnerText)
Me.WebBrowser1.Document.Window.ScrollTo(150, 310)
psc = 0
If WebBrowser1.DocumentText.Contains("Bei deinem PIN-Code und/oder Passwort ist ein Fehler aufgetreten. Bitte überprüfe die korrekte Eingabe des PIN-Codes oder Passworts.") Then
Label1.Text = "Pin oder Passwort Falsch"
psc = 0
Label1.ForeColor = Color.Red
Me.WebBrowser1.Document.Window.ScrollTo(100, 370)
'WebBrowser1.Navigate("https://customer.cc.at.paysafecard.com/psccustomer/GetWelcomePanelServlet?&language=de&javax.faces.ViewState=j_id1")
ElseIf WebBrowser1.DocumentText.Contains("Bei der Eingabe des PIN-Codes oder Passworts ist ein Fehler aufgetreten. Bitte korrigiere deine Eingabe. Hast du ein Passwort für diese paysafecard vergeben, kontaktiere bitte unser Service-Team.") Then
Label1.Text = "Pin oder Passwort Falsch"
psc = 0
Label1.ForeColor = Color.Red
Me.WebBrowser1.Document.Window.ScrollTo(100, 370)
'Abfrage ob richtige Pin-Code Eingabe
ElseIf WebBrowser1.DocumentText.Contains("Bitte korrigiere deine Eingabe") Then
Label1.Text = "Pin oder Passwort Falsch"
psc = 0
Label1.ForeColor = Color.Red
Me.WebBrowser1.Document.Window.ScrollTo(100, 370)
ElseIf WebBrowser1.DocumentText.Contains("Der eingegebene Text stimmt nicht mit dem Angezeigten überein.") Then
Label1.Text = "Captcha falsch"
Label1.ForeColor = Color.Red
psc = 0
Me.WebBrowser1.Document.Window.ScrollTo(120, 350)
'WebBrowser1.Navigate("https://customer.cc.at.paysafecard.com/psccustomer/GetWelcomePanelServlet?&language=de&javax.faces.ViewState=j_id1")
ElseIf WebBrowser1.DocumentText.Contains("Verfügbares Guthaben") Then
Label1.ForeColor = Color.Green
Label1.Text = "PSC OK"
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.Document.GetElementById("tabForm:password").Focus()
SendKeys.Send("{ENTER}")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If WebBrowser1.DocumentText.Contains("passwordPage:passwordOld") And Not pwchange = 1 Then
WebBrowser1.Document.GetElementById("passwordPage:passwordOld").InnerText = TextBox6.Text
WebBrowser1.Document.GetElementById("passwordPage:password1").InnerText = TextBox7.Text
WebBrowser1.Document.GetElementById("passwordPage:password2").InnerText = TextBox7.Text
pwchange = 1
WebBrowser1.Document.GetElementById("passwordPage:submit").Focus()
SendKeys.Send("{ENTER}")
Label5.Text = "Das neue Passwort lautet:" & TextBox7.Text
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Document.GetElementById("tabForm:close").Focus()
SendKeys.Send("{ENTER}")
Label5.Text = ""
Label1.Text = ""
End Sub
Private Sub TextBox8_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged
If TextBox8.TextLength = 16 Then
TextBox1.Text = TextBox8.Text.Substring(0, 4)
TextBox2.Text = TextBox8.Text.Substring(4, 4)
TextBox3.Text = TextBox8.Text.Substring(8, 4)
TextBox4.Text = TextBox8.Text.Substring(12, 4)
End If
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.CheckState = CheckState.Checked Then
My.Settings.new_pw_save = TextBox7.Text
Else
My.Settings.new_pw_save = ""
End If
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.CheckState = CheckState.Checked Then
My.Settings.pw_save = TextBox6.Text
Else
My.Settings.pw_save = ""
End If
End Sub
End Class
From a quick glance at the code you need to have a form that goes with the code to provide the UI for the application. If you design your own remember to use the events dialog and wire up each event that you need.