Results 1 to 6 of 6

Thread: [RESOLVED] Stored Variable Location After Compiled

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    6

    Resolved [RESOLVED] Stored Variable Location After Compiled

    I have a question that I have searched for and never found a good answer.

    Here is my problem, I have a widget style app that the user can define an X,Y position. If the user screws up and defines the wrong numbers it ends up off the the screen. I have fixed the issue with building in recovery methods and restrictions, but there is one part that has left me curious.

    I had a default position 0, 0. User enters -10000, 0, they fat fingered the 0. Now the app goes off into space. Let say the executable was called widget.exe. If I copy and pasted and renamed it, upon opening the newly named app, it would be back to the default. This leads me to believe the variables are stored maybe somewhere with a connection to the executables name.

    These are just DIM assigned variable.

    Where are they stored?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Stored Variable Location After Compiled

    If you declare a variable (using Dim or Private/Public/...) it is only stored while your program is running, the value will not be there if the program is closed and opened again.

    Presumably you are also storing the value in some kind of long-term storage (perhaps via My.Settings), and where/how that is stored depends on what you are doing.

    Based on what you've written I assume you are using My.Settings, as that does store its values based on the name of the executable file (somewhere within AppData, but the exact location can vary and isn't easy to explain).


    In terms of dealing with it, you can simply re-verify the value(s) when your program reads them, and set them to the defaults (or 'closest valid value') at that point if the values aren't valid.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Stored Variable Location After Compiled

    I read it a bit differently, as there isn't any mention of storing the variables.

    Every variable has a default value. No values are stored between runs of the program unless you explicitly set up some mechanism to take the value from the variable and persist it to the hard drive, and retrieve it the next time the program runs. The variable itself cannot be stored, only the contents of the variable is stored.

    If you are persisting the variable, then you aren't doing so in the .exe. Wherever the data is stored, it almost certainly has no reference back to the exe. It is the program itself that knows where to look for the data, and load it. The data might be in a text file, a manifest, the registry, a database, or several other options, but none of those know anything about who stored them, or where that code was located....with one exception, which is that a binary serialized data file may know WHO stored them, though not where the code was located.

    So, you can't go from the data back to the .exe. It is up to the .exe to know where the data is and retrieve it.

    That's not quite where I was going with this, originally, as I was thinking that you were asking about where the variables were when the exe wasn't running, in which case the answer is: Nowhere. However, upon further reading, I decided you might be headed towards trying to keep the data tied to the program if the program moves around.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    6

    Re: Stored Variable Location After Compiled

    Thanks for the replies. The issue is I had lost the latest VS source code/project file, so I couldn't remember how I exactly declared the variables. I just found an earlier rendition, which at least had the way I declared the variables. I usually make a config text files and read and write to them for stored or user defined variables. I guess this time around I tried to do something different. I used the app.config manifest.

    I my head, I knew "Defined In Memory"... So it didn't make sense to me that a DIM defined variable could retain a custom value that changed in run time.

    So "si_the_geek", you are correct, I used my.settings. I know you said there is no easy way to explain where these would be stored locally on the computer, is there somewhere I can refer to get a rough explanation?

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Stored Variable Location After Compiled

    On Windows 7, one of my programs has a config file here:

    C:\Users\ <Username> \AppData\Local\ <My Company name> \ <executable name plus lots of "random" characters> \ <executable version number>

    Depending on the version of Windows you are using (and lots of other things, including project properties), several parts of this could change (eg: the \Local could be \Roaming ).

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    6

    Re: [RESOLVED] Stored Variable Location After Compiled

    That was exactly what I was looking for. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width