C
C#6mo ago
WRLD

✅ Reading .csv files correctly

hey im trying to read a .csv file correctly by sorting the different values etc insied of it, two of those values are revenue and price and im trying to add all that up into my varible but i ends up as 0 all the time does anyone know what im doing wrong the format of the csv file is like this: "Id,Buyer User Id,Date and Time,Location,Location Id,Universe Id,Universe,Asset Id,Asset Name,Asset Type,Hold Status,Revenue,Price"
C#
string[] values = line.Split(',');
if (values.Length >= 14)
{
string holdStatus = values[10];
decimal revenue = 0;
decimal price = 0;
if (decimal.TryParse(values[11], out revenue) && decimal.TryParse(values[12], out price))
{
if (holdStatus.Equals("Released", StringComparison.OrdinalIgnoreCase))
{
totalEarnedReleased += revenue;
totalSpentReleased += price;
releasedCount++;
}
else if (holdStatus.Equals("Held", StringComparison.OrdinalIgnoreCase))
{
totalEarnedHeld += revenue;
totalSpentHeld += price;
heldCount++;
}
C#
string[] values = line.Split(',');
if (values.Length >= 14)
{
string holdStatus = values[10];
decimal revenue = 0;
decimal price = 0;
if (decimal.TryParse(values[11], out revenue) && decimal.TryParse(values[12], out price))
{
if (holdStatus.Equals("Released", StringComparison.OrdinalIgnoreCase))
{
totalEarnedReleased += revenue;
totalSpentReleased += price;
releasedCount++;
}
else if (holdStatus.Equals("Held", StringComparison.OrdinalIgnoreCase))
{
totalEarnedHeld += revenue;
totalSpentHeld += price;
heldCount++;
}
26 Replies
Angius
Angius6mo ago
First deserialize that CSV into a list of objects Then do with that list whatever you want, sorting, summing, aggregating, whatever
WRLD
WRLDOP6mo ago
alright i'' try that
Angius
Angius6mo ago
https://joshclose.github.io/CsvHelper/ this library might be useful
WRLD
WRLDOP6mo ago
why cant i download CsVHelper? nvm got it i have no idea but this has completely fucked my program no litterally nothing at all works.. @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius6mo ago
Meaning? Errors? Unintended behaviour? What exactly did you do? Just installing this library broke things? Any other code you changed?
WRLD
WRLDOP6mo ago
no i tried to use
No description
WRLD
WRLDOP6mo ago
this crap and impelemnt it and boom litterally 0 works n o values gets added not even a simple + works
Angius
Angius6mo ago
That is a class, yes What's the code that's supposed to work but doesn't?
WRLD
WRLDOP6mo ago
it sssupposed to run through the .csv file and collect info such as how many sales, where the sales have been, revenue and price and it does litterally nothing nowww it doesnt update any values or anything
Jimmacle
Jimmacle6mo ago
sounds like your code is wrong then
WRLD
WRLDOP6mo ago
well without the classes it was working for the msot part so either im doing this class stuff wrong or idk
Jimmacle
Jimmacle6mo ago
it's probably that did you read the documentation for how to use csvhelper?
WRLD
WRLDOP6mo ago
^^ this was the only part of my code that wasnt working properly before now its everything yup
Jimmacle
Jimmacle6mo ago
well, you did something wrong i use this library for csv data and it's fine
WRLD
WRLDOP6mo ago
well how do you correctly sort the data?
Jimmacle
Jimmacle6mo ago
if "nothing works" then you shouldn't be thinking about sorting right now the first step is to correctly load the data in the first place
WRLD
WRLDOP6mo ago
wym "load" the data theres nothing to load theres data to go throguh through*
Jimmacle
Jimmacle6mo ago
so why are you doing anything with a CSV if there is no data
WRLD
WRLDOP6mo ago
jesus crist
Jimmacle
Jimmacle6mo ago
the data you need to load is in the CSV
WRLD
WRLDOP6mo ago
ill do it myself
Jimmacle
Jimmacle6mo ago
suit yourself i guess
Pobiega
Pobiega6mo ago
"load" in this context means to read the csv file into memory you cant go through it without loading it
Jimmacle
Jimmacle6mo ago
i don't see any sorting in the posted code either, so there are some terminology issues happening
Pobiega
Pobiega6mo ago
he left the thread it seems?
Jimmacle
Jimmacle6mo ago
the server their loss
Want results from more Discord servers?
Add your server