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