Changing the directory in a method and call variable elsewhere

Posted 13 January 2013 - 09:33 AM

Hi i am attempting to change the directory in a method in my program and i was wondering how i would then use the variable from the method to say that the directory has changed in a start screen method

Re: Changing the directory in a method and call variable elsewhere

Posted 13 January 2013 - 09:44 AM

I mean if i have a method that allows me to change the directory that is set at a main screen method as soon as the program loads how would i call the newDirectory variable in the start screen method ?

Re: Changing the directory in a method and call variable elsewhere

Posted 13 January 2013 - 09:46 AM

newDirectory is a local variable, you can't access it from another method. But why would you need to? You changed the current directory - that change will affect any method that gets called afterwards, whether it has access to the newDirectory variable or not.

If you declare these at class level then you can use them in all your methods within that class.

Its what we call "scope". A thing exists between the {} it was created in. So if you make a thing within a for{} loop, that's its scope. If you want to access a thing for the entire class, then define it in the class braces

Re: Changing the directory in a method and call variable elsewhere

Posted 13 January 2013 - 11:57 AM

I have a follow up question, i have qotten it to change the folder successfully but at the start of running the program it comes up with the folder as to where the project is saved, how can i set a directory at the start of the program and then change later in the directory change part ?