How to read and write an ini file with Qbasic 4.5 
Author Message
 How to read and write an ini file with Qbasic 4.5

Hi everybody,
    I would like to know something very useful.  How can I read and write in
an initialisation file ( .INI file)?

    To be sure that we both talk about the same things, I would like to
write a file in this format:

[Section]
Key=Value

I want to be able to read and write this kind of file easily...

With QBasic 4.5

Thanks,

Fred



Mon, 27 Oct 2003 07:52:42 GMT  
 How to read and write an ini file with Qbasic 4.5
On Wed, 9 May 2001 19:52:42 -0400, "SgtPepper"

A Windows 3.x .INI file is just text.  Just specify .INI instead of
.TXT in the OPEN statement.

Quote:
>    I would like to know something very useful.  How can I read and write in
>an initialisation file ( .INI file)?

>    To be sure that we both talk about the same things, I would like to
>write a file in this format:

>[Section]
>Key=Value

>I want to be able to read and write this kind of file easily...

>With QBasic 4.5



Mon, 27 Oct 2003 12:14:42 GMT  
 How to read and write an ini file with Qbasic 4.5
Ok, i already knows that, what I need is do you have a fonction that write
and read ini easily like
filename$="something.ini"
section$="Test"
key$="writing"
Value$=Message$
Gosub Writeini

and

filename$="something.ini"
section$="Test"
Key$="Reading"
Gosub ReadIni

you see what I mean?

Fred



Quote:
> On Wed, 9 May 2001 19:52:42 -0400, "SgtPepper"

> A Windows 3.x .INI file is just text.  Just specify .INI instead of
> TXT in the OPEN statement.

> >    I would like to know something very useful.  How can I read and write
in
> >an initialisation file ( .INI file)?

> >    To be sure that we both talk about the same things, I would like to
> >write a file in this format:

> >[Section]
> >Key=Value

> >I want to be able to read and write this kind of file easily...

> >With QBasic 4.5



Mon, 27 Oct 2003 19:26:06 GMT  
 How to read and write an ini file with Qbasic 4.5

Quote:
> Hi everybody,
>     I would like to know something very useful.  How can I read and write
in
> an initialisation file ( .INI file)?

Since you can't use the Win32 API functions (well, you could.... but), your
only choice is to read each line of the file and parse out the strings
(input); or build the strings and write out the file (output).

There are no doubt dozens of techniques, but they all boil down to this.

MCM



Mon, 27 Oct 2003 19:51:00 GMT  
 How to read and write an ini file with Qbasic 4.5


Quote:
> Ok, i already knows that, what I need is do you have a fonction that write
> and read ini easily like
> filename$="something.ini"
> section$="Test"
> key$="writing"
> Value$=Message$
> Gosub Writeini

> and

> filename$="something.ini"
> section$="Test"
> Key$="Reading"
> Gosub ReadIni

> you see what I mean?

> Fred

Here is a simple demo for the ReadINI function. Add your own error checking
to the function as required. Now see if you can manage the WriteINI function
on your own. Hint; it's a bit more involved. The file has to be read until
either the section and key is found, or append a new section with the key.
The trick is, you have to write to a temporary file, then replace the
original with the temporary. I recommend you practice writing with a dummy
.ini file. Good luck with the exercise.

BTW, you can do all this work in memory with a string variable/array, but,
considering you should only need to read during program initialization,
write only when closing, and .ini files are small anyway, the gain is
minimal.

DECLARE FUNCTION ReadINI$ (FileName$, Section$, Key$)

CLS
FileName$ = "c:\windows\win.ini"
Section$ = "desktop"
Key$ = "wallpaper"

Value$ = ReadINI$(FileName$, Section$, Key$)

PRINT "Your wallpaper is ";
IF LEN(Value$) THEN
  PRINT Value$
ELSE
  PRINT "not set!"
END IF
SYSTEM

FUNCTION ReadINI$ (FileName$, Section$, Key$)

  FF = FREEFILE
  OPEN FileName$ FOR INPUT AS #FF
  INILOF = LOF(FF)

  IF INILOF THEN
    Section$ = UCASE$(Section$)
    Key$ = UCASE$(Key$)

    DO UNTIL EOF(FF)
      LINE INPUT #FF, in$
      in$ = LTRIM$(in$)

      IF SectionFound THEN
        'Search for the key within section
        IF LEFT$(UCASE$(in$), LEN(Key$) + 1) = Key$ + "=" THEN
          'Key found so set return string to the function
          ReadINI = MID$(in$, LEN(Key$) + 2)
          EXIT DO
        END IF
      END IF

      IF LEFT$(in$, 1) = "[" THEN
        'It's a section
        IF SectionFound THEN
          'Key was not found within the section
          EXIT DO
        ELSE
          'Check if it's the correct section
          SectionFound = INSTR(UCASE$(in$), "[" + Section$ + "]")
        END IF
      END IF
    LOOP
  END IF

  CLOSE #FF

END FUNCTION

--
Todd Vargo (body of message must contain my name to reply by email)



Mon, 27 Oct 2003 22:09:45 GMT  
 How to read and write an ini file with Qbasic 4.5


Quote:




BTW, please don't crosspost to groups of different languages. I received a
{*filter*} robot message (in French) telling me what amounts to, 'please read the
FAQ before posting'. It's a pretty dumb robot if it can't tell that I had
replied to a crosspost. Oh well, I'm not reposting just to complain about
the dumb robot, but this is the last crosspost you'll see from me in the
French group.

--
Todd Vargo (body of message must contain my name to reply by email)



Tue, 28 Oct 2003 20:22:09 GMT  
 How to read and write an ini file with Qbasic 4.5

Quote:

> BTW, please don't crosspost to groups of different languages. I received a
> {*filter*} robot message (in French).....

I got something in French, too. So is that what it was?

MCM
(who "carefully" edited the group to which this reply was sent).



Tue, 28 Oct 2003 23:57:50 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Qbasic: Pre-written INI read/write routines?

2. Read/Write INI Files w/Access 7.0

3. Ini-file, read write and empty lines.

4. Reading and writing from and to ini files

5. read/write an .ini file

6. Reading and writing to an INI file?

7. Reading and Writing to .ini files - help please.

8. Read and Write to INI files

9. Reading/writing to an INI file

10. Reading / Writing an INI file

11. Reading / Writing an INI file

12. Reading/Writing to the Registry and .INI file???

 

 
Powered by phpBB® Forum Software