|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||||
|
|||||
|
Hello,
I am having trouble with the following; I have made an application where the program uses data about a file specified when clicking a link on the context(right-click) menu. When the user clicks the link the program starts up. To get the data about the file i access it through the main args. Like so - C# Code:
This code is from Program.cs because that is where i can get the data from where the file was selected. However, i only need to use this data when a button is clicked, this button is on another file. When i try to access the data through the global variable it appears as nothing. So, the variable is not transferring across the different files (in this case - program.cs to form1.cs). I know this because if i add a MessageBox to program.cs the variable is shown, whereas, if i do the same on form1.cs its shows nothing. It is not a problem with the global variable set up code. I have a hunch that this is because the above function is static and it can then only be used in the one file. Please help, Thanks, |
|
#2
|
||||
|
||||
|
Say what?
![]()
__________________
C/C++ pointers (Original in the "Commonly Asked Questions" thread). |
|
#3
|
|||
|
|||
|
Quote:
lol yea i was the same way. but another read over and i think i know what hes asking. his c# app has a "global" declared in a file that gets a path but when he tries to access this var in code in another file it gets nothing and hes wondering how to accomplish this. how exactly is Global._fullpath defined? is it a private/public member of the program class or some other class being used in the application? what is the scope of the method that in form1.cs that tries to access this variable? |
|
#4
|
||||||||
|
||||||||
|
Sorry, yes the global variable is defined like so -
c# Code:
Sorry, i will explain it a bit better. I have made an application that interacts with the user by using the right click (context) menu. User right clicks a file > clicks the link to my app > my app loads. I then want to use the information about this file in my app. In this case, the path to the file. The path can be retrieved using the code i posted. I wanted to have the path stored in a "global variable" so i can use in multiple files. But, for some reason the "global variable" is not being sent out of the file it was defined in. I get the file path through the main arguments. example - c# Code:
Now, i have found a workaround for this, that's moving the main entry point to another file and defining the variable on that file. This way, it is still possible to use that information on that file. However, it still defeats the purpose of having the file path as a "global" variable. The question is - How do i let the global variable be used outside the file it was defined in? The global variable code does work perfectly well on other files, i think it is something to do with being defined in a static class etc. Sorry for being unclear, |
|
#5
|
||||
|
||||
|
Working solely from general principles (since I have no knowledge of nor experience with nor desire for C#), I would suspect that that global variable is being hidden.
If the global variable is not being hidden but rather is just not visible, then it shouldn't have compiled. If a local or duplicate variable is hiding that global variable, then I would expect or assume that that local/duplicate had been initialized to zero or empty-string by the system and then never updated by the code and hence would output nothing, as reported. |
|
#6
|
||||
|
||||
|
|
|
#7
|
|||
|
|||
|
Good point, for some reason i thought the path was received in chunks, eh...yeah, i will change it, thanks.
|
|
#8
|
|||
|
|||
|
ok, is Global defined inside the class that holds the program or outside of it?
also, is it defined in the same namespace as the application class? |
|
#9
|
|||
|
|||
|
Quote:
Global is defined in a seperate file, in the same namespace. |
|
#10
|
|||
|
|||
|
Quote:
try making Global a public static class |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Fail to transfer variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|