Liberty BASIC Community Forum
« INI function question »

Welcome Guest. Please Login or Register.
Sep 19th, 2017, 1:49pm


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


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: INI function question  (Read 568 times)
nooneyouknow
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 39
xx INI function question
« Thread started on: Nov 25th, 2015, 06:20am »

In several places it is stated that either an "Entry" or a "Section" will be deleted if a corresponding value is "NULL". This deletion does not seem to be happening in my file today.

I can't find any way to delete a "Section" or an "Entry" other than to edit in a text editor.

I'm curious what has changed from then to now to make this no longer function, and is there a way to make that statement true?

LINK: http://lbpe.wikispaces.com/IniFiles

Quote:
Entry$
Points to a null-terminated string containing the entry associated with the value string. If the entry does not exist it will be created. If this is NULL (""), the entire section is deleted. If you were to read the file in a texteditor this entry would look like this -- the Entry$ followed by an = sign, followed by the String$

Entry=String
...
String$
Points to the null-terminated string value to be written to the file. If this is NULL, (""), the Entry$ entry is deleted from the file.

Entry=String
User IP Logged

Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14916
xx Re: INI function question
« Reply #1 on: Nov 25th, 2015, 07:56am »

Without seeing your code, we cannot guess. MSDN docs agree with the article and can be found here:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms725501(v=vs.85).aspx
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1681
xx Re: INI function question
« Reply #2 on: Nov 25th, 2015, 08:15am »

I think the problem is that NULL is not ""
NULL is the pointer with value of 0.
So.
For me,
Code:
Section$="sect1"
Entry$="user"
String$=""

calldll #kernel32, "WritePrivateProfileStringA", _
Section$ as ptr, _    'section name
Entry$ as ptr, _      'entry name
String$ as ptr, _     'actual entry
FileName$ as ptr, _   'name of ini file
result as long
 

produces
Code:
[sect1]
user=
 

but the
Code:
Section$="sect1"
Entry$="user"
null=0

calldll #kernel32, "WritePrivateProfileStringA", _
Section$ as ptr, _    'section name
Entry$ as ptr, _      'entry name
null as ulong, _     'actual entry
FileName$ as ptr, _   'name of ini file
result as long

 

results in
Code:
[sect1]
 

(it did actually erased "user" entry)
« Last Edit: Nov 25th, 2015, 08:17am by tsh73 » User IP Logged

damned Dog in the Manger
Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14916
xx Re: INI function question
« Reply #3 on: Nov 25th, 2015, 08:29am »

Thanks, Anatoly. The article is changed to correct that error.
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


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


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2278
xx Re: INI function question
« Reply #4 on: Nov 25th, 2015, 08:41am »

Oops!

Turns out the Wiki article is a bit misinformed.

While the information on the Wiki and MSDN agree, the actual implementation is different.

WritePrivateProfileString() is one of those functions that does not see NULL and "" as being equivalent.

When the MSDN doc specified NULL, it has to be NULL, not an empty string.

If an empty string is passed as a value, it uses that empty string as the value, which lets you create values that are blank(for now).


This:

Code:
Section$="sect1"
Entry$="user"
String$=""

calldll #kernel32, "WritePrivateProfileStringA", _
Section$ as ptr, _    'section name
Entry$ as ptr, _      'entry name
String$ as ptr, _     'actual entry
FileName$ as ptr, _   'name of ini file
result as long 


Will create this:

Code:
[sect1]
user= 



This:

Code:
Section$="sect1"
Entry$="user"
String$=""

calldll #kernel32, "WritePrivateProfileStringA", _
Section$ as ptr, _    'section name
Entry$ as ptr, _      'entry name
_NULL as ulong, _     'NULL entry
FileName$ as ptr, _   'name of ini file
result as long 


Will create this:

Code:
[sect1] 



Additionally, this:

Code:
Section$="sect1"
Entry$="user"
String$=""

calldll #kernel32, "WritePrivateProfileStringA", _
Section$ as ptr, _    'section name
_NULL as ulong, _      'entry name
_NULL as ulong, _     'actual entry
FileName$ as ptr, _   'name of ini file
result as long  



Will create an empty file.


EDIT: Hah! That's what I get for not refreshing. Ninja'd twice.
« Last Edit: Nov 25th, 2015, 08:46am by Chris Iverson » User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14916
xx Re: INI function question
« Reply #5 on: Nov 25th, 2015, 08:47am »

on Nov 25th, 2015, 08:41am, Chris Iverson wrote:
Oops!

Turns out the Wiki article is a bit misinformed.


EDIT: Hah! That's what I get for not refreshing. Ninja'd twice.


That's okay, Chris. I'd rather see multiple (if similar) correct responses than to see no correction at all. And I always want to read what you and Anatoly add to discussions. wink

When we moved from a published newsletter to a dynamic wiki implementation, some people complained. They like to print out the monthly newsletters. Unfortunately, having articles "set in stone" made it really difficult to correct or expand them. We've done both to the ini file article. In a newsletter format, we could publish a correction in a later article, but readers of the original article had no way of looking for a correction in a future issue.

We all make mistakes and omissions. The wiki format allows us to correct them. Wiki FTW!
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: 14916
xx Re: INI function question
« Reply #6 on: Nov 25th, 2015, 11:35am »

I edited the article in haste, and have now corrected the edits (I hope.) Chris will likely update it further.

Folks on this forum try to give quick, thorough answers, but we sometimes trip over ourselves. (At least I do...) We keep on trying, though.

« Last Edit: Nov 25th, 2015, 11:37am by Alyce Watson » User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
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