C
C#9mo 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
SinFluxx9mo ago
Is the error a secret?
SCOLANATOR
SCOLANATOROP9mo ago
Error CS1503 Argument 1: cannot convert from 'IP_Convert.MainWindow.UpdatedRecord' to 'IP_Convert.MainWindow.CsvRecord' Sorry, forgot to post it
Jimmacle
Jimmacle9mo ago
what do you think the error means?
SCOLANATOR
SCOLANATOROP9mo 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
Jimmacle9mo 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
SCOLANATOROP9mo 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
Jimmacle9mo ago
so my guess is correct
SCOLANATOR
SCOLANATOROP9mo ago
How do i fix it?
Jimmacle
Jimmacle9mo ago
by not trying to put the wrong type into your list or changing the list to accept that type
SCOLANATOR
SCOLANATOROP9mo ago
OK how do I change the list to accept that type?
Jimmacle
Jimmacle9mo ago
well, what type did you declare it to hold?
SCOLANATOR
SCOLANATOROP9mo ago
I declared all those additional entries as strings
Jimmacle
Jimmacle9mo ago
that doesn't matter, the type itself is not compatible with the type you made your list contain
SCOLANATOR
SCOLANATOROP9mo ago
OK so whats the best way to resolve this?
Jimmacle
Jimmacle9mo 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
Pobiega9mo 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
Jimmacle9mo ago
the problem is List<CsvRecord> modifiedRecords = new List<CsvRecord>(); you don't have CsvRecords you have UpdatedRecords
SCOLANATOR
SCOLANATOROP9mo ago
How do I map a type?
Jimmacle
Jimmacle9mo 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
SCOLANATOROP9mo 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
Jimmacle9mo 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
SCOLANATOROP9mo 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
Jimmacle9mo ago
right, so do you see why you're getting the error? what type is newRecord?
SCOLANATOR
SCOLANATOROP9mo ago
Updatedrecord
Jimmacle
Jimmacle9mo ago
is UpdatedRecord a CsvRecord?
SCOLANATOR
SCOLANATOROP9mo ago
It's a class As is CSVRecord
Jimmacle
Jimmacle9mo ago
that doesn't answer my question
Pobiega
Pobiega9mo ago
it is not.
Jimmacle
Jimmacle9mo ago
i'm trying to help you understand why you get an error for trying to add an UpdatedRecord to a List<CsvRecord>
SCOLANATOR
SCOLANATOROP9mo 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
Jimmacle9mo ago
this is really not microsoft's fault this is basic OOP
SCOLANATOR
SCOLANATOROP9mo ago
In JS or Python this would've been a lot easier
Jimmacle
Jimmacle9mo ago
only if you refuse to understand a strongly typed programming language
SCOLANATOR
SCOLANATOROP9mo ago
In fact I have a similar python script I can probably repurpose to achieve this task
Jimmacle
Jimmacle9mo ago
go do that i guess i'm not gonna force you to learn
SCOLANATOR
SCOLANATOROP9mo 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
Jimmacle9mo 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
SCOLANATOROP9mo ago
Well thank you
Jimmacle
Jimmacle9mo 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
SCOLANATOROP9mo 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
Jimmacle9mo 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
SCOLANATOROP9mo ago
In JS was more easily able to be made into desktop applications it would be great
Jimmacle
Jimmacle9mo ago
no thanks
SCOLANATOR
SCOLANATOROP9mo ago
It's taken over everything and with NodeJS you can do full front and backend work
Jimmacle
Jimmacle9mo ago
dynamically typed programming languages are significantly more error prone, and JS is... JS
SCOLANATOR
SCOLANATOROP9mo 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
Jimmacle9mo ago
ok
SCOLANATOR
SCOLANATOROP9mo ago
Thats a sincere question, I'm wondering where C# fits now
Jimmacle
Jimmacle9mo 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
SCOLANATOROP9mo ago
I just don't see it in use much but I guess I run in different circles
Jimmacle
Jimmacle9mo 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
SCOLANATOROP9mo ago
While I agree Python is slow, JS especially if it 'compiles' like with Svelte is pretty dam quick these days
Jimmacle
Jimmacle9mo ago
no strong typing is a dealbreaker if i had to do JS for any reason i'd use TS
SCOLANATOR
SCOLANATOROP9mo ago
I probably need to take actual coding classes I'm almost entirely self taught
Jimmacle
Jimmacle9mo 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
SCOLANATOROP9mo ago
Where's the best place to learn do you think?
Jimmacle
Jimmacle9mo ago
pick a project and figure out how to make it using resources on the internet
SCOLANATOR
SCOLANATOROP9mo 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
Jimmacle9mo 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
SCOLANATOROP9mo 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
Jimmacle9mo ago
yes, because you probably have new errors if your other code expected that list to hold CsvRecords and not UpdatedRecords
Want results from more Discord servers?
Add your server