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

Did you find this page helpful?