C
C#5mo ago
Kapa._

Assignment

I want the code to show the text file in the visual stuido console however its not working right now, any help?
No description
56 Replies
Pobiega
Pobiega5mo ago
"show the file", as in show the path to the file, or show the content of the file?
Angius
Angius5mo ago
Describe "not working right"
Kapa._
Kapa._5mo ago
content of the file its wont show it in the console
Pobiega
Pobiega5mo ago
Nowhere in your code are you opening the file. Or printing the file. Or the file path. Don't take this the wrong way, but have you tried googling "C# read text file"?
Kapa._
Kapa._5mo ago
i have but im getting even more confused cuz there is multiple ways of doing it and im not sure which one to use and i thought this way would be the simplest
Angius
Angius5mo ago
Pick any of them and see if it works
Pobiega
Pobiega5mo ago
"this way"?
Angius
Angius5mo ago
If it doesn't, try another
Pobiega
Pobiega5mo ago
you are not doing any way at the moment, sir you have nothing that even attempts to open a file here all you have is a conditional assignment of a fileName variable, and some writing
Kapa._
Kapa._5mo ago
so what should i do to make the user input choose the desired file
Angius
Angius5mo ago
Well, the selection you have there would work
Pobiega
Pobiega5mo ago
You've already done that part
Angius
Angius5mo ago
It would result in one path being chosen You just need to actually open a file at this path
Kapa._
Kapa._5mo ago
ahhh i see give me 5 mins
Kapa._
Kapa._5mo ago
No description
Kapa._
Kapa._5mo ago
this is where im at now? still doesnt seem to open the file in console
Pobiega
Pobiega5mo ago
That should work fine. does it say anything about error in the console when you run it?
Kapa._
Kapa._5mo ago
nope there is one warning on line 51 about ex never being used but the console still opens and immidiately closes
Angius
Angius5mo ago
Do the files have... text in them?
Kapa._
Kapa._5mo ago
indeed
Pobiega
Pobiega5mo ago
opens and immidiately closes
Pobiega
Pobiega5mo ago
do you not even get to answer 1 2 or 3?
Kapa._
Kapa._5mo ago
nope
Pobiega
Pobiega5mo ago
No description
Pobiega
Pobiega5mo ago
this is not the main method are you calling this method from Main?
Angius
Angius5mo ago
How are you running fileChoice() method? (should be named FileChoice() btw)
Kapa._
Kapa._5mo ago
i mean it wont let me run fileChoice but it will let me run filePath in the main FilePath filePath = new FilePath();
Angius
Angius5mo ago
If a method doesn't run... it doesn't run If you don't call a method, it doesn't run If you want fileChoice() to run, you need to call it
Kapa._
Kapa._5mo ago
it not letting me call it
Pobiega
Pobiega5mo ago
what do you mean by that
Kapa._
Kapa._5mo ago
No description
Pobiega
Pobiega5mo ago
thats not a methodcall
Angius
Angius5mo ago
Methods belong to classes You can't just refer to a method from another class loosely like that You need either an instance of that class if the method is non-static
Pobiega
Pobiega5mo ago
also, you called the method fileChoice, not FileChoice
Angius
Angius5mo ago
Or the class itself if the method is static See that Console.WriteLine() you use a lot? It's class Console and a static method WriteLine()
Kapa._
Kapa._5mo ago
FileChoice is a public static void class
Angius
Angius5mo ago
No such thing as a void class Or a static class
Kapa._
Kapa._5mo ago
i mean method
Pobiega
Pobiega5mo ago
are you sure?
Angius
Angius5mo ago
Incorrect again fileChoice() is a static void method
Pobiega
Pobiega5mo ago
No description
Kapa._
Kapa._5mo ago
😭
Angius
Angius5mo ago
You don't have a method called FileChoice()
Pobiega
Pobiega5mo ago
that clearly says its fileChoice
Kapa._
Kapa._5mo ago
i changed it to a capital as visual studio was prompting me too
Pobiega
Pobiega5mo ago
Okay, but what class is that method declared in? FilePath?
Kapa._
Kapa._5mo ago
i want to declare it Program
Angius
Angius5mo ago
Then do that?
Pobiega
Pobiega5mo ago
Declare is where its code is written you did not write it in program
Angius
Angius5mo ago
Currently, you seem to have it declared in its own class
Pobiega
Pobiega5mo ago
so if you want it in Program, just move it there definately are static classes, even if not very relevant here :p
Angius
Angius5mo ago
derp
Kapa._
Kapa._5mo ago
i shall get back to you
Somgör from Human Resources
Why not make the program get all files from the directory and then make a dictionary and then generate the selection UI. :SCcrawl:
Kapa._
Kapa._5mo ago
ok so i was being silly I called in in the program calls by FilePath.FileChoice(); and it works