Problem with Preferences and Pathrequester

Windows specific forum
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Problem with Preferences and Pathrequester

Post by PB&J Lover »

There is a problem using the pathrequester before writingpreferences. It won't write the file.

Any ideas why?

When I use pathrequester just before writingpreferences, the file is not created.

Code: Select all

If CertDir$ = ""   
   CertDir$ = PathRequester("Select a Directory for IBCC Certificates:  ","C:\")
EndIf
   Gosub SavePrefs
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

Could you post the SavePrefs code? You just post the part with the PathRequester, I don't think I can help you just with it. :P

Maybe you are not doing something like that:

Code: Select all

If CertDir$ = ""    
   CertDir$ = PathRequester("Select a Directory for IBCC Certificates:  ","C:\") 
   CertDir$=CertDir$+"preferences.dat" ;add the file name after the path
EndIf 
   Gosub SavePrefs
It's just my opinion, but I think you should have post this on the Beginners forum. :wink:

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

pathrequester problem

Post by PB&J Lover »

Well, if I take the code I posted out the preferences file is created. The contents of the code that does that are not important (and large).

This is not a beginner's problem. There is obviously some kind of path interruption that doesn't allow the preferences file to be created. If anything this should be posted in the bug forum, but it may have a known solution.

I'm not a beginner and this is not a simple problem.

Thanks.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

There's nothing wrong in posting this in the beginner's forum. It won't turn you into a beginner. I just said that because this is not a windows specific problem.

If you don't post some code, how will someone help you? Take the unimportant parts off and post the rest here.

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: pathrequester problem

Post by PB »

Can you post some standalone code which demonstrates the problem? Your
little snippet does nothing to show the problem, so it may well be just a tiny
bug with your coding (no offence intended). We don't even know what your
SavePrefs routine looks like...
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

pathrequester problem

Post by PB&J Lover »

Ok here's some test code

Code: Select all

Xdir$ = PathRequester("Enter A File Path","C:\")

SavePrefs:
  spResult = CreatePreferences("Test.ini") : Debug spResult
               PreferenceGroup("TEST SECT")
         WritePreferenceString("Test","Test")
  ClosePreferences()
End
The problem only appears if I don't include a path in my "CreatePrefs" line. The Pathrequester line somehow screws that up. Normally it would put the file in the program's exe directory, but in this case it goes into some kind of Limbo.

This is not a Beginner's problem, it is a Windows, problem because it is happening on a Windows OS (Me).

Thanks for the help.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

No offences, but it isn't a windows problem just because you are using Windows ME. PathRequester() works on Windows, Linux, AmigaOS and probably on MacOS as well. This doesn't seem to be a bug either. So where sould it be? :wink:

Again, as I can see you are getting the path with PathRequester(), but you do not add the filename at the ending:

Code: Select all

MyPath$=PathRequester("Choose your Path","c:\")
MyFile$=Test.ini
CompletePath$=Mypath$+MyFile$
MyFileSaver(CompletePath$)
As I could see this was not on your code snippet. PathRequester() doesn't work for itself, it just returns the path as a string. If you don't add the filename after it, it won't save anything!

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

pathrequester problem

Post by PB&J Lover »

No, you misunderstand the problem. It is Windows (only) related.

When you use CreatePreferences("Myfile.ini") the file is normally stored in the program's exe directory (as I've said). That directory path is stored by the system.

If one does a PathRequester(Path$) for a completely different file operation (NOT the path for the ini file) the directory path for the Preferences is lost or the pointer is moved (this probably doesn't happen in other OS's).

I don't want to have to specify a path for the exe directory (and therefore the prefs directory) because I may not know it if the program is installed on another computer. I don't want to "hard-wire" it as your example shows.

I told you. This is not a beginner's problem, it does not have a beginners solution. It is a bug that displaces the pointer for the CreatePrefs command when the Pathrequester is used. If you don't understand what I'm saying by that then you don't know what is happening.

Use my code example:

Code: Select all

Xdir$ = PathRequester("Enter A File Path","C:\") 

SavePrefs: 
  spResult = CreatePreferences("Test.ini") : Debug spResult 
               PreferenceGroup("TEST SECT") 
         WritePreferenceString("Test","Test") 
  ClosePreferences() 
End
Comment out the pathrequest code. Where does the ini file appear? Now. Delete the ini file. Put the path requester back in. Where does the file appear? On WINDOWS, it goes into a sort of Limbo. This problem may happen on other OS's (I don't know) but it is caused by specific WINDOWS elements.

Thanks anyway.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

Have you ever read the post in Beginner's forum? there are some way harder than this one! I recommend you look at *this.

Your Problem:

Code: Select all

Xdir$ = PathRequester("Enter A File Path","C:\") 

SavePrefs: 
  spResult = CreatePreferences(Xdir$+"Test.ini") : Debug spResult 
               PreferenceGroup("TEST SECT") 
         WritePreferenceString("Test","Test") 
  ClosePreferences() 
End
Now it works. With the solution I gave you TWICE! It was a beginner's fault after all, and thus, with a beginner's solution. There's nothing wrong in being a beginner. If you don't know that, you are still a n00b.

:wink:

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

PathRequester / CreatePreferences conflict in Windows.

Post by PB&J Lover »

Sorry, but I don't know how to make is clearer. You just don't understand the problem so thanks anyway.

I've said the Xdir$ is NOT the preferences directory so your solution does NOT work. I've said it is for a different operation.

Perhaps someone else can give it a try. Thanks anyway.

Try the test that I spelled out in my last post. Or read it again and maybe you'll see what the problem really is. Thanks.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

I tryed your test, and as you said, it didn't save anything. Have you tryed my test? :)

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Post by PB&J Lover »

Your test is useless since you don't understand what I am saying. Read my post again.

What does this sentence mean to you?

"The Xdir$ is NOT the directory for the 'TEST.ini" file."

Where does your solution put the TEST.ini file? If the answer is: In the Xdir$ then you got it wrong. Now, thanks, but please let someone else take a crack at it. You're not understanding the problem.

(please delete your post in the bug topic so someone else will answer it)

Thanks.
Last edited by PB&J Lover on Sun Aug 07, 2005 7:04 pm, edited 1 time in total.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Post by PB&J Lover »

Fou-Lu wrote:I tryed your test, and as you said, it didn't save anything. Have you tryed my test? :)
A path is not required for it to save the ini file. So by saying it didn't save anything you are not being specific enough to be a good debugger. When didn't it save anthing? When did it? Why?

See, you don't get whats going on or how this function normally operates.

Run this:

Code: Select all

SavePrefs: 
  spResult = CreatePreferences(Xdir$+"Test.ini") : Debug spResult 
               PreferenceGroup("TEST SECT") 
         WritePreferenceString("Test","Test") 
  ClosePreferences() 
End
Now where is the Test.ini file located? Write that down. Now delete it. Now run this:

Code: Select all

Xdir$ = PathRequester("Enter A File Path","C:") 

SavePrefs: 
  spResult = CreatePreferences(Xdir$+"Test.ini") : Debug spResult 
               PreferenceGroup("TEST SECT") 
         WritePreferenceString("Test","Test") 
  ClosePreferences() 
End
Now, look for the TEXT.ini file again. Where is it now? Why?

Do you see what's happening? The PathRequester is affecting the location of the TEXT.ini file when the two operations are NOT related. That's a bug.
Get it?

I don't want to specify a directory for the TEST.ini and noramally I don't have to. Xdir$ is NOT the directory for the TEST.ini file. It is for some OTHER file.

Thanks anyway.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

PB&J Lover wrote:What does this sentence mean to you?

"The Xdir$ is NOT the directory for the 'TEST.ini" file."
I understood perfecly. You get a path but your file isn't saved there, and it is saved somewhere else just because you used the PathRequester() before, right? Sorry, I was just trying to help you. While there isn't anyone else trying to help, let's keep on trying to solve that? Don't get your hopes on Fred coming here himself to help you. This problem is also on Bugs forum so, you don't have to worry that nobody but me will help you.

I got you wrong because when I tested you code, it worked and the Test.ini is saved in the same directory as the code is saved. I'm not saying it's not a bug, but your piece of code doesn't show anything wrong.

You don't need to offend me just because your examples aren't speciffic enough. The only way to debug your code correctly is to see the whole code (by the way you can mail me it if you want).

Relax, I'm not your enemy! :wink:
Let eat some PB&J sandwiches after this is all over. :)

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

pathrequester problem

Post by PB&J Lover »

I didn't mean to offend you at all. The code I posted is enough to demonstrate the problem. It may be something specific to Windows ME.

It didn't look like you understood my problem since in your solution you simply put the Xdir$ into the CreatePreferences() function and that's not the problem.

This is a bug that took me a while to figure out so I don't blame you for not seeing it right away either. Fred is looking into it too.

Thanks, again, for the help.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
Post Reply