Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

FilNotFoundException was unhandled

$
0
0

Please help me with my code I tried everything I know but I think I just know less

 Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Dim fileLoc As String = "C:\Users\84fes\OneDrive\Desktop\printreceipt.txt"

        If Val(lblChange.Text) <= 0 Then
            MsgBox("No Cash Received or Not Enough. Please try again!", vbCritical, "Warning")
            Exit Sub
        Else

            If File.Exists(fileLoc) Then
                Using sw As StreamWriter = New StreamWriter(fileLoc, True)

           Dim ornumber As String, companyname As String, compaddress As String, tin As String, lne As String, itmcost As String
                    Randomize()
                    ornumber = "            ORN-" & Rnd(Rnd() * 9999999999.0#) & Chr(Rnd(Rnd() * 25) + 65)
                    companyname = "         EINSTEIN RESTO HAUS"
                    compaddress = "        Ain Khaled, Doha, Qatar"
                    tin = "        TIN: 0000-0123-4567-8910"
                    lne = "---------------------------------------"
                    itmcost = "ITEM              QTY    COST"

                    sw.WriteLine(companyname)
                    sw.WriteLine(compaddress)
                    sw.WriteLine(tin)
                    sw.WriteLine(ornumber)
                    sw.WriteLine(lne)
                    sw.WriteLine(itmcost)
                    sw.WriteLine(lne)

                    For i = 0 To frmMenu.lstOrder.Items.Count - 1
                        sw.WriteLine(frmMenu.lstOrder.Items(i))
                    Next
                    sw.WriteLine(lne)
                    sw.WriteLine(lne)

                    Dim subtotal As Double, vat As Double
                    vat = Format(CDec(lblAmountDue.Text) * 0.12, "##,##0.00")
                    subtotal = Format(CDec(lblAmountDue.Text) - CDec(vat), "##,##0.00")
                    sw.WriteLine("SUB TOTAL:               " & subtotal)
                    sw.WriteLine("VAT (12%):               " & vat)
                    sw.WriteLine("Total Amount:            " & lblAmountDue.Text)
                    sw.WriteLine(lne & vbNewLine)

                    sw.WriteLine("Cash:                    " & txtCash.Text)
                    sw.WriteLine("Change:                  " & lblChange.Text)

                    sw.WriteLine(vbNewLine)
                    sw.WriteLine("Date: " & Date.Now.ToString())

                    sw.Close()

                    Shell("notepad++.exe C:\Users\84fes\OneDrive\Desktop\printreceipt.txt")

                End Using

                System.IO.File.WriteAllText(fileLoc, "")

            End If
        End If
    End Sub


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>