Results 1 to 8 of 8

Thread: File Location

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    29

    File Location

    Using Windows 7 Pro + VB6 w/SP3.

    In my app, I save a file, apparently to C:\ProgramData\MyApp (this is where I want to save it.)
    Then, in my app, I recall the file, from C:\ProgramData\MyApp. Guess what? I get the OLD file, not the file that I just tried to save.

    The file that I thought I saved (to C:\ProgramData\MyApp) really got saved to C:\Users\MyName\AppData\Local\VirtualStore\ProgramData\MyApp
    or to
    C:\Users\MyName\AppData\Roaming\Microsoft\Windows\RecentData\MyApp.

    What is going on? Why is the file not being saved where I want it, and where it is telling me (lying to me) it is being saved?

    Need help badly. This is a commercial app.

    Hal W

  2. #2
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: File Location

    Halw

    What sort of file is it?
    ... text?
    ... something else?

    What is the code frag you are using to save the file?

    Spoo

  3. #3

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    29

    Re: File Location

    Sub SaveStrategy(Strategy_and_Tuning_Name$)

    The actual argument name for Strateg _and_Tuning_Name$, which I can check in Development mode, is
    "C:\ProgramData\PC-ControLAB 3.1\DecupFwd.stg"
    Code:
    Dim exists As Boolean
    Dim Attr_ReadOnly As Integer, n As Integer, i As Integer, np As Integer, j As Integer
    Dim errreturn As Integer, Result1 As Integer, imax As Integer
    Dim FileExists As Integer, fileflag As Integer, attr As Integer
    Dim ext$, try$, x$, Path$, Filenamstg$, msg$, Path_plus_Filename$
    Dim nl$
    nl$ = Chr$(10) + Chr$(13)
    Attr_ReadOnly = 1
    
    Filenamstg$ =Strategy_and_Tuning_Name$
    
    'Is this a good file name?
    fileflag = 0
    Call fileok(Filenamstg$, errreturn)
    If errreturn <> 0 Then Exit Sub
    
    ' If we got to here, it's a good files.
    ' Check file. If it exists, can we overwrite it?
    FileExists = (Dir(Filenamstg$) <> SEmpty$)
    If FileExists = -1 Then
        fileflag = 1
        attr = GetAttr(Filenamstg$)
    In Development mode, this last statement gives halts with Error Message #6, Overflow.
    In Runtime, it gives no error message and doesn't halt.
    Code:
        attr = attr And vbReadOnly
        If attr = vbReadOnly Then  'File property Read Only is NOT set.
    
            msg$ = "Process strategy file is Read Only."
            msg$ = msg$ + nl$ + "Select another file name and/or directory."
            MsgBox msg$, 48, "PC-ControLAB 3.1"
            On Error GoTo 0
            Exit Sub
        End If
    End If
    
    ' All files are clear.  Let's do it.
    Screen.MousePointer = 11
    Open Filenamstg$ For Output As #4
    Here's where I am trying to open the existing file, C:\ProgramData\PC-ControLAB 3.1\DecupFwd.stg.
    I used the word "apparently" because that is the argument that I passed. See below.
    Code:
    SaveStratRecheck:
    '
    Print #4, ControlStrategy
    Print #4, Path_plus_ModelName$
    '
    '   Tuning Options
    '
    Print #4, GainorPB      'Proportional Tuning. Gain or PB
    Print #4, MPRorRPM      'integral tuning Min/Rpt or Rpt/Min
    Print #4, IDTMS         'integral time units in mins or sec
    Print #4, Spareslot
    Print #4, Spareslot
    
    'Here is where I print these, and lot more parameters of this particular Control Strategy.  Then
    
    Close #4
    Screen.MousePointer = 0
    MsgBox "Strategy and tuning file " + Filenamstg$ + " successfully saved.", , "PC-ControLAB 3.1"
    WRONG! When I examine the file that I had hoped to save (actually, update), I find that neither the file date nor the data in the file has not been changed. Instead, if I do a Windows Explorer search, I find that there is a file

    C:\Users\MyName\AppData\Local\VirtualStore\ProgramData\PC-ControLAB 3.1\DecupFwd.stg

    that does have the correct file data and the file data that I intended to write to the other file.

    My question remains: Why, when I pass one valid argument, does the system ignore that argument and store the data in a location that I did not intend, nor specify? The problem may be in my computer configuration, but I don't believe it is within my code per se.
    Last edited by Hack; Jun 18th, 2013 at 08:05 AM. Reason: Added Code Tags

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,658

    Re: File Location

    I believe it's because saving to the folder requires admin permission, and when you try to save there without admin permission windows automatically saves in the VirtualStore folder instead.

  6. #6

  7. #7
    Lively Member
    Join Date
    May 2009
    Location
    UK
    Posts
    72

    Re: File Location

    use a different folder name eg C:\MyApp

    The folder you are currently using is riddled with many problems if not used correctly.

    It could be useful to look at the SHGetFolderPath API Function (depreciated). Now use SHGetKnownFolderPath api function

    SHGetKnownFolderPath

    SHGetFolderPath function (depreciated)
    Last edited by asymetrix; Jun 18th, 2013 at 11:01 AM.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File Location

    Why, when I pass one valid argument, does the system ignore that argument and store the data in a location that I did not intend, nor specify?
    why not just bow to windows7 and save your data elsewhere, programfiles being a protected folder, requiring elevated permissions, it will only be harder in windows 8 or later
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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