Click here to Skip to main content
14,212,594 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello All,

I converted this code from C# and i have been getting errors on my project. This particular one has the error :

"Unrecognized Escape Sequence


Can someone help me out please? Thanks for your help.

Regards



Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.IO
Imports System.Data

Namespace UsedCarsSales
Public Class CSVWriter
Private _seperator As String = ","


Public Sub New()
End Sub

Friend Sub SaveFile1(dataGridViewSales As DataGridView)
Try
Dim sb As New StringBuilder(50)
Dim path As String = "..\debug\CarSalesFiles\Commissions" & DateTime.Today.Year + DateTime.Today.Month & DateTime.Today.Day & ".txt"
If Not File.Exists(path) Then
Using sw As StreamWriter = File.CreateText(path)
For Each row As DataGridViewRow In dataGridViewSales.Rows
sb.Append(row.Cells("Model").Value.ToString() & _seperator)
sb.Append(row.Cells("Manufacturer").Value.ToString() & _seperator)
sb.Append(row.Cells("Color").Value.ToString() & _seperator)
sb.Append(row.Cells("Year").Value.ToString() & _seperator)
sb.Append(row.Cells("OdometerReading").Value.ToString() & _seperator)
sb.Append(row.Cells("VehicleID").Value.ToString() & _seperator)
sb.Append(row.Cells("SalesRepID").Value.ToString() & _seperator)
sb.Append(row.Cells("AcquisitionCost").Value.ToString() & _seperator)
sb.Append(row.Cells("AquiredDate").Value.ToString() & _seperator)
sb.Append(row.Cells("DateSold").Value.ToString() & _seperator)
sb.Append(row.Cells("MaintenanceCost").Value.ToString() & _seperator)
sb.Append(row.Cells("SellingPrice").Value.ToString() & _seperator)



sw.WriteLine(sb.ToString())

Next
End Using
End If
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
End Sub

Friend Sub SaveFile()
Try
Dim reader As New CSVReader()
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 5

I don't see the error anymore. I changed the code around and it seems just fine now. Please can you tell me what this error possibly means :

Public Event CheckedChanged(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. Line 21



Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.IO
Imports System.Collections.ObjectModel

Namespace UsedCarsSales
Public Partial Class MainForm
Inherits Form
Private filePath As String = String.Empty
Private pictueName As String = String.Empty

Public Sub New()
InitializeComponent()
Load += New EventHandler(MainForm_Load)
End Sub

Private Sub MainForm_Load(sender As Object, e As EventArgs)
LoadSalesRep()
LoadSales()
LoadGroupData()
LoadSalesRepSales(Nothing)
End Sub

Private Sub LoadSalesRepSales(lastName As String)

Try
Dim reader As New CSVReader()

Dim result = From s In reader.GetSales() _
Join c In reader.GetSalesRep() _
On c.SalesRepID Equals c.SalesRepID_
Order By c.SalesRepID _
Select New _
With { _
.SalesRepID = c.SalesRepID _
.FirstName = c.FirstName _
.LastName = c.LastName _
.PhotoFile = c.PhotoFile _
.Manufacturer = s.Manufacturer _
.Model = s.Model _
.Color = s.Color _
.Year = s.Year _
.DateSold = s.DateSold _
.AcquisitionCost = s.AcquisitionCost _
.MaintenanceCost = s.MaintenanceCost _
.SellingPrice = s.SellingPrice _
.AquiredDate = s.AquiredDate _
.OdometerReading = s.OdometerReading _
.StartDate = c.StartDate _
.VehicleID = s.VehicleID _
}

If lastName Is Nothing Or String.IsNullOrEmpty(lastName) Then
Me.dataGridViewSalesRepSales.DataSource = result.ToList()
Else
Me.dataGridViewSalesRepSales.DataSource = result.Where(Function(w) w.LastName.ToUpper() = lastName.ToUpper()).ToList()
End If
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try



End Sub

Private Sub LoadGroupData()
Try
Dim reader As New CSVReader()
Dim result = From s In reader.GetSales() _
Join c In reader.GetSalesRep() _
On s.SalesRepID Equals c.SalesRepID_
Order By c.SalesRepID_
Select New _
With { _
.SalesRepID = c.SalesRepID _
.Name = c.FirstName + " " + c.LastName _
.PhotoFile = c.PhotoFile _
.Manufacturer = s.Manufacturer _
.Model = s.Model _
.Color = s.Color _
.Year = s.Year _
.DateSold = s.DateSold _
.AcquisitionCost = s.AcquisitionCost _
.MaintenanceCost = s.MaintenanceCost _
.SellingPrice = s.SellingPrice _
.AquiredDate = s.AquiredDate _
.OdometerReading = s.OdometerReading _
.StartDate = c.StartDate _
.VehicleID = s.VehicleID _
}

Dim salesRepSalescollection


Dim list As New List(Of SalesRepSales)()
For Each item As var In salesRepSalescollection
Dim netProfit As Decimal = Calculations.getNetProfit(result.Where(Function(e) e.SalesRepID = item.Key).LastOrDefault().AcquisitionCost, result.Where(Function(e) e.SalesRepID = item.Key).LastOrDefault().SellingPrice, result.Where(Function(e) e.SalesRepID = item.Key).LastOrDefault().MaintenanceCost)
Dim commision As Decimal = netProfit * CDec(0.3)

If commision < 100 Then
commision = 100
End If

list.Add(New SalesRepSales() With { _
.TotalSales = result.Where(Function(e) e.SalesRepID = item.Key).Sum(Function(pkg) pkg.SellingPrice), _
.Name = result.Where(Function(e) e.SalesRepID = item.Key).LastOrDefault().Name, _
.Commission = commision, _
.PhotoFile = result.Where(Function(e) e.SalesRepID = item.Key).LastOrDefault().PhotoFile, _
.SalesRepID = result.Where(Function(e) e.SalesRepID = item.Key).LastOrDefault().SalesRepID, _
.VehicleSold = result.Where(Function(e) e.SalesRepID = item.Key).Count() _
})
Next

dataGridViewGroup.DataSource = list.ToList()

SetSalesGroupFormatting()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try

End Sub


End Namespace
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

On what line does this error occur? I don't see anything in the code you posted that will generate that error.

Also, are you sure you want to a field seperator character after the "SellingPrice" since it's the last field on the line before you write it out??
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 3

Hello, You can try by using @ symbol at the start of path in the string
or try to use two slash

1st ->@"..\debug\CarSalesFiles\Commissions"

2nd->"..\\debug\\CarSalesFiles\\Commissions"

Happy Coding
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

Dim path As String = "..\debug\CarSalesFiles\Commissions" & DateTime.Today.Year _ DateTime.Today.Month & DateTime.Today.Day & ".txt"


put '_' instead of '+'.
   
Comments
Dave Kreskowiak 2-Mar-12 23:44pm
   
Which will only result in compile-time errors in VB.NET. He's converting C# to VB.NET, not the other way around.
Rate this:
Please Sign up or sign in to vote.

Solution 6

You didn't mention the issue clearly, while line the error occurs? Try different convertors. Check this
.NET Code Conversion - Convert your code[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 7

   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190619.2 | Last Updated 3 Mar 2012
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100