C
C#•3mo 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
Pobiega•3mo ago
"show the file", as in show the path to the file, or show the content of the file?
Angius
Angius•3mo ago
Describe "not working right"
Kapa._
Kapa._•3mo ago
content of the file its wont show it in the console
Pobiega
Pobiega•3mo 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._•3mo 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
Angius•3mo ago
Pick any of them and see if it works
Pobiega
Pobiega•3mo ago
"this way"?
Angius
Angius•3mo ago
If it doesn't, try another
Pobiega
Pobiega•3mo 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._•3mo ago
so what should i do to make the user input choose the desired file
Angius
Angius•3mo ago
Well, the selection you have there would work
Pobiega
Pobiega•3mo ago
You've already done that part
Angius
Angius•3mo ago
It would result in one path being chosen You just need to actually open a file at this path
Kapa._
Kapa._•3mo ago
ahhh i see give me 5 mins
Kapa._
Kapa._•3mo ago
No description
Kapa._
Kapa._•3mo ago
this is where im at now? still doesnt seem to open the file in console
Pobiega
Pobiega•3mo ago
That should work fine. does it say anything about error in the console when you run it?
Kapa._
Kapa._•3mo ago
nope there is one warning on line 51 about ex never being used but the console still opens and immidiately closes
Angius
Angius•3mo ago
Do the files have... text in them?
Kapa._
Kapa._•3mo ago
indeed
Pobiega
Pobiega•3mo ago
opens and immidiately closes
Kapa._
Kapa._•3mo ago
Pobiega
Pobiega•3mo ago
do you not even get to answer 1 2 or 3?
Kapa._
Kapa._•3mo ago
nope
Pobiega
Pobiega•3mo ago
No description
Pobiega
Pobiega•3mo ago
this is not the main method are you calling this method from Main?
Angius
Angius•3mo ago
How are you running fileChoice() method? (should be named FileChoice() btw)
Kapa._
Kapa._•3mo ago
i mean it wont let me run fileChoice but it will let me run filePath in the main FilePath filePath = new FilePath();
Angius
Angius•3mo 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._•3mo ago
it not letting me call it
Pobiega
Pobiega•3mo ago
what do you mean by that
Kapa._
Kapa._•3mo ago
No description
Pobiega
Pobiega•3mo ago
thats not a methodcall
Angius
Angius•3mo 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
Pobiega•3mo ago
also, you called the method fileChoice, not FileChoice
Angius
Angius•3mo 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._•3mo ago
FileChoice is a public static void class
Angius
Angius•3mo ago
No such thing as a void class Or a static class
Kapa._
Kapa._•3mo ago
i mean method
Pobiega
Pobiega•3mo ago
are you sure?
Angius
Angius•3mo ago
Incorrect again fileChoice() is a static void method
Pobiega
Pobiega•3mo ago
No description
Kapa._
Kapa._•3mo ago
😭
Angius
Angius•3mo ago
You don't have a method called FileChoice()
Pobiega
Pobiega•3mo ago
that clearly says its fileChoice
Kapa._
Kapa._•3mo ago
i changed it to a capital as visual studio was prompting me too
Pobiega
Pobiega•3mo ago
Okay, but what class is that method declared in? FilePath?
Kapa._
Kapa._•3mo ago
i want to declare it Program
Angius
Angius•3mo ago
Then do that?
Pobiega
Pobiega•3mo ago
Declare is where its code is written you did not write it in program
Angius
Angius•3mo ago
Currently, you seem to have it declared in its own class
Pobiega
Pobiega•3mo ago
so if you want it in Program, just move it there definately are static classes, even if not very relevant here :p
Angius
Angius•3mo ago
derp
Kapa._
Kapa._•3mo ago
i shall get back to you
SCShocked 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._•3mo ago
ok so i was being silly I called in in the program calls by FilePath.FileChoice(); and it works