C
C#3mo ago
SCOLANATOR

Unable to add new columns to CSV file

The following code is giving me an error on the line: modifiedRecords.Add(newRecord); This needs to take in a CSV file, edit the data, then add additional columns of data.
61 Replies
SinFluxx
SinFluxx3mo ago
Is the error a secret?
SCOLANATOR
SCOLANATOR3mo ago
Error CS1503 Argument 1: cannot convert from 'IP_Convert.MainWindow.UpdatedRecord' to 'IP_Convert.MainWindow.CsvRecord' Sorry, forgot to post it
Jimmacle
Jimmacle3mo ago
what do you think the error means?
SCOLANATOR
SCOLANATOR3mo ago
That I've mixed something up somewhere I was trying to follow someone else's advice but I'm going round in circles trying to get it working It's really just trying to get an exisiting CSV, change some of the data in that CSV (those bits I managed), then add additional columns of data (this is where my problems started), then output the finished CSV
Jimmacle
Jimmacle3mo ago
i can't open your code, but i'm guessing modifiedRecords is some kind of collection of CsvRecord but you're trying to add a UpdatedRecord unless UpdatedRecord inherits CsvRecord or defines an implicit cast to it, that can't work
SCOLANATOR
SCOLANATOR3mo ago
GitHub
IP-Convert/IP_Convert.cs at main · KonigAI/IP-Convert
Contribute to KonigAI/IP-Convert development by creating an account on GitHub.
Jimmacle
Jimmacle3mo ago
so my guess is correct
SCOLANATOR
SCOLANATOR3mo ago
How do i fix it?
Jimmacle
Jimmacle3mo ago
by not trying to put the wrong type into your list or changing the list to accept that type
SCOLANATOR
SCOLANATOR3mo ago
OK how do I change the list to accept that type?
Jimmacle
Jimmacle3mo ago
well, what type did you declare it to hold?
SCOLANATOR
SCOLANATOR3mo ago
I declared all those additional entries as strings
Jimmacle
Jimmacle3mo ago
that doesn't matter, the type itself is not compatible with the type you made your list contain
SCOLANATOR
SCOLANATOR3mo ago
OK so whats the best way to resolve this?
Jimmacle
Jimmacle3mo ago
by changing the type of your list to hold what you're trying to put in it i can't really get more clear than that without writing the code for you
Pobiega
Pobiega3mo ago
Have list of old type. Use select to map to new type. You now have a different list of new type. Save this to file.
Jimmacle
Jimmacle3mo ago
the problem is List<CsvRecord> modifiedRecords = new List<CsvRecord>(); you don't have CsvRecords you have UpdatedRecords
SCOLANATOR
SCOLANATOR3mo ago
How do I map a type?
Jimmacle
Jimmacle3mo ago
the code you have is practically doing that already the problem is simply that you are trying to put a square peg in a round hole cannot convert from 'IP_Convert.MainWindow.UpdatedRecord' to 'IP_Convert.MainWindow.CsvRecord' UpdatedRecord is the square peg List<CsvRecord> is the round hole if you want a list of UpdatedRecord you need to make it a list of UpdatedRecord
SCOLANATOR
SCOLANATOR3mo ago
So just use modified records instead of updatedrecords? I feel like I've spent so long staring at this code I'm losing my mind
Jimmacle
Jimmacle3mo ago
you can't force an instance of an UpdatedRecord into a CsvRecord, they're completely different types of objects you don't have any class called "modified record" do you? look at this line specifically
modifiedRecords.Add(newRecord);
modifiedRecords.Add(newRecord);
what is modifiedRecords and what is newRecord?
SCOLANATOR
SCOLANATOR3mo ago
New record contains the variables in each line item that I wish to add to the list called modified records List<CsvRecord> modifiedRecords = new List<CsvRecord>();
Jimmacle
Jimmacle3mo ago
right, so do you see why you're getting the error? what type is newRecord?
SCOLANATOR
SCOLANATOR3mo ago
Updatedrecord
Jimmacle
Jimmacle3mo ago
is UpdatedRecord a CsvRecord?
SCOLANATOR
SCOLANATOR3mo ago
It's a class As is CSVRecord
Jimmacle
Jimmacle3mo ago
that doesn't answer my question
Pobiega
Pobiega3mo ago
it is not.
Jimmacle
Jimmacle3mo ago
i'm trying to help you understand why you get an error for trying to add an UpdatedRecord to a List<CsvRecord>
SCOLANATOR
SCOLANATOR3mo ago
I honestly think I'm just going to redo this in JS, as this is my first C# program and I am hating it I tried doing it in C# as this small tool needs to run locally on a windows machine This was the last stupid part I needed to do and it just breaks endlessly, man there's a reason I ditched Microsoft and I remember why
Jimmacle
Jimmacle3mo ago
this is really not microsoft's fault this is basic OOP
SCOLANATOR
SCOLANATOR3mo ago
In JS or Python this would've been a lot easier
Jimmacle
Jimmacle3mo ago
only if you refuse to understand a strongly typed programming language
SCOLANATOR
SCOLANATOR3mo ago
In fact I have a similar python script I can probably repurpose to achieve this task
Jimmacle
Jimmacle3mo ago
go do that i guess i'm not gonna force you to learn
SCOLANATOR
SCOLANATOR3mo ago
I have to do this for a job - not that coding is my primary purpose but I needed to provide a small tool to do a task, this has burned way too much time already I just wanted help to finish it, I won't be using C# again, lesson learned
Jimmacle
Jimmacle3mo ago
literally
-List<CsvRecord> modifiedRecords = new List<CsvRecord>();
+List<UpdatedRecord> modifiedRecords = new List<UpdatedRecord>();
-List<CsvRecord> modifiedRecords = new List<CsvRecord>();
+List<UpdatedRecord> modifiedRecords = new List<UpdatedRecord>();
that's all i wanted you to figure out
SCOLANATOR
SCOLANATOR3mo ago
Well thank you
Jimmacle
Jimmacle3mo ago
there's a reason we don't just solve problems for people because you're going to run into things like this again
SCOLANATOR
SCOLANATOR3mo ago
Look I get that, and 9 times out of 10 that's the right way. But I'm sticking to Python and JS where I am way more comfortable. I thought it would be fun to use C# for a change but this is not for me
Jimmacle
Jimmacle3mo ago
there are many strongly typed programming languages besides lua and maybe some others i'm pretty sure python and JS are the 2 popular languages that aren't
SCOLANATOR
SCOLANATOR3mo ago
In JS was more easily able to be made into desktop applications it would be great
Jimmacle
Jimmacle3mo ago
no thanks
SCOLANATOR
SCOLANATOR3mo ago
It's taken over everything and with NodeJS you can do full front and backend work
Jimmacle
Jimmacle3mo ago
dynamically typed programming languages are significantly more error prone, and JS is... JS
SCOLANATOR
SCOLANATOR3mo ago
I don't quite get where C# fits anymore, you have Rust or C++ for really demanding stuff like games, then anything less demanding you can use JS or Python
Jimmacle
Jimmacle3mo ago
ok
SCOLANATOR
SCOLANATOR3mo ago
Thats a sincere question, I'm wondering where C# fits now
Jimmacle
Jimmacle3mo ago
everywhere it's a general purpose programming language you can use it for web, desktop, background services, games, etc that's like asking why anyone made a programming language other than C
SCOLANATOR
SCOLANATOR3mo ago
I just don't see it in use much but I guess I run in different circles
Jimmacle
Jimmacle3mo ago
i personally have no desire to use languages like JS or python, a good type system is a requirement for me and not being slow is usually important
SCOLANATOR
SCOLANATOR3mo ago
While I agree Python is slow, JS especially if it 'compiles' like with Svelte is pretty dam quick these days
Jimmacle
Jimmacle3mo ago
no strong typing is a dealbreaker if i had to do JS for any reason i'd use TS
SCOLANATOR
SCOLANATOR3mo ago
I probably need to take actual coding classes I'm almost entirely self taught
Jimmacle
Jimmacle3mo ago
same classes don't teach you to develop software they teach you how to use a programming language and usually using outdated versions and practices
SCOLANATOR
SCOLANATOR3mo ago
Where's the best place to learn do you think?
Jimmacle
Jimmacle3mo ago
pick a project and figure out how to make it using resources on the internet
SCOLANATOR
SCOLANATOR3mo ago
And honestly I just don't have enough time to learn all the languages I would like, I find JS covers enough of my basis at this point That's what I always do
Jimmacle
Jimmacle3mo ago
i mean... based on the conversation earlier you didn't put much effort into understanding and fixing your problem which is the most important thing to do
SCOLANATOR
SCOLANATOR3mo ago
I got this far, I just got absolutely fed up with it And then intellisense is telling me my error is somewhere else
Jimmacle
Jimmacle3mo ago
yes, because you probably have new errors if your other code expected that list to hold CsvRecords and not UpdatedRecords