Liberty BASIC Community Forum
« Not working? »

Welcome Guest. Please Login or Register.
Nov 22nd, 2017, 01:32am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Not working?  (Read 556 times)
nooneyouknow
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 39
xx Not working?
« Thread started on: Nov 21st, 2015, 7:49pm »

The demo program here doesn't seem to write or read an INI file to save settings.



I was researching ways to build INI files, but I can't even find the INI file from this demo on my computer.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Not working?
« Reply #1 on: Nov 22nd, 2015, 02:29am »

Since the demo does not use a path name look at the contents of DefaulDir$, this will contain the working directory name. Tell us what it is. It may be permissions, Windows evolves, UAC use is mandatory now. The demos were written before that was the case.

So what was DefaultDir$, also we now know that Boolean is not a valid data type in Liberty so where you see that used swap it out for type long.
User IP Logged

Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14917
xx Re: Not working?
« Reply #2 on: Nov 22nd, 2015, 04:31am »

on Nov 21st, 2015, 7:49pm, nooneyouknow wrote:
The demo program here doesn't seem to write or read an INI file to save settings.



I was researching ways to build INI files, but I can't even find the INI file from this demo on my computer.


It's an old demo. Specify a full path. Change the two functions as follows, or use a path of your own choosing.

Code:
Sub WriteIniFile lpAppName$, lpKeyName$, lpString$, lpFileName$
    lpFileName$=DefaultDir$+"\"+lpFileName$
    CallDLL #kernel32, "WritePrivateProfileStringA", _
        lpAppName$ As ptr, _    'section name
        lpKeyName$ As ptr, _    'key name
        lpString$ As ptr, _     'key value
        lpFileName$ As ptr, _   'ini filename
        result As boolean       'nonzero = success
    end sub

Function GetIniFile$(lpAppName$, lpKeyName$,lpDefault$,lpFileName$)
    lpFileName$=DefaultDir$+"\"+lpFileName$
    nSize=100
    lpReturnedString$=Space$(nSize)+Chr$(0)
    CallDLL #kernel32, "GetPrivateProfileStringA", _
        lpAppName$ As ptr, _'section name
        lpKeyName$ As ptr, _'key name
        lpDefault$ As ptr, _'default string returned if there is no entry
        lpReturnedString$ As ptr, _ 'destination buffer
        nSize As long, _            'size of destination buffer
        lpFileName$ As ptr, _       'ini filename
        result As ulong     'number of characters copied to buffer

    GetIniFile$=Left$(lpReturnedString$,result)
    end function

 


A standalone test of the two functions follows:
Code:
call WriteIniFile "testapp","testkey","Test String","test.ini"
print GetIniFile$("testapp","testkey","Empty","test.ini")
wait

Sub WriteIniFile lpAppName$, lpKeyName$, lpString$, lpFileName$
    lpFileName$=DefaultDir$+"\"+lpFileName$
    CallDLL #kernel32, "WritePrivateProfileStringA", _
        lpAppName$ As ptr, _    'section name
        lpKeyName$ As ptr, _    'key name
        lpString$ As ptr, _     'key value
        lpFileName$ As ptr, _   'ini filename
        result As boolean       'nonzero = success
    end sub

Function GetIniFile$(lpAppName$, lpKeyName$,lpDefault$,lpFileName$)
    lpFileName$=DefaultDir$+"\"+lpFileName$
    nSize=100
    lpReturnedString$=Space$(nSize)+Chr$(0)
    CallDLL #kernel32, "GetPrivateProfileStringA", _
        lpAppName$ As ptr, _'section name
        lpKeyName$ As ptr, _'key name
        lpDefault$ As ptr, _'default string returned if there is no entry
        lpReturnedString$ As ptr, _ 'destination buffer
        nSize As long, _            'size of destination buffer
        lpFileName$ As ptr, _       'ini filename
        result As ulong     'number of characters copied to buffer

    GetIniFile$=Left$(lpReturnedString$,result)
    end function

 
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14917
xx Re: Not working?
« Reply #3 on: Nov 22nd, 2015, 04:58am »

on Nov 21st, 2015, 7:49pm, nooneyouknow wrote:
The demo program here doesn't seem to write or read an INI file to save settings.



I was researching ways to build INI files, but I can't even find the INI file from this demo on my computer.


As I said, it's an old demo. You posted a similar bit of code yesterday and added a path to it, so you already understand how to do this:

Your code:
Code:
if right$(DefaultDir$,1)<>"\" then
    DefaultDir$=DefaultDir$+"\"
end if
inifile$ = DefaultDir$ + "JunkINIstruct.ini"

print inifile$ 
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
nooneyouknow
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 39
xx Re: Not working?
« Reply #4 on: Nov 22nd, 2015, 06:54am »

Apparently, you think I'm being difficult. grin

So does having "boolean" in the spec cause it to not work? I'll try that, too.

I did try adding DefaultDir$ and didn't find the INI file there.

It didn't work, so I posted that result.
User IP Logged

Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14917
xx Re: Not working?
« Reply #5 on: Nov 22nd, 2015, 07:27am »

on Nov 22nd, 2015, 06:54am, nooneyouknow wrote:
Apparently, you think I'm being difficult. ;D

So does having "boolean" in the spec cause it to not work? I'll try that, too.

I did try adding DefaultDir$ and didn't find the INI file there.

It didn't work, so I posted that result.


I reread my messages and I do not see anything that implies that I think you are being difficult. I am trying to be helpful.

Did you try the standalone code in my first message? It includes only the ini file writing function and sub. On Windows 10, the ini file is exactly where it should be... in the default directory.

If you do not know where that is on your computer, you can discover the location like this:

Code:
print DefaultDir$ 


Run the standalone code from my first message and look in your DefaultDir$. If you do not find it there, then I have no other suggestions.
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
nooneyouknow
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 39
xx Re: Not working?
« Reply #6 on: Nov 22nd, 2015, 07:29am »

I changed "boolean" to "long" in 3 or 4 places. Now it works. I don't know why.

Thanks for the help.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls