reading ini file, cannot be done ?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

The following does not work?

Writing goes well, reading is all messing up.
Can someone tell me what's the problem.
I can't figure it out.

INIFilename(".\sections.dat")
INISection("SECTIONS")
WriteINIString("test","cor") ; cor is written ok
ReadINIString("test",result1.s)
SetGadgetText(0,result1) ; no result even text gadget dissapears





Registered PB version : 2.82 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

If you look at the documentation, the format for ReadINIString would go like this...

Result$ = ReadINIString(Key$,Value$)
so
result1.s=ReadINIString("test","")

Value$ is a default value... what you would like the Result$ to be is it can't find the Key$.

Edited by - paul on 26 January 2002 01:41:52
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.
If you look at the documentation, the format for ReadINIString would go like this...

Result$ = ReadINIString(Key$,Value$)
so
result1.s=ReadINIString("test","")

Value$ is a default value... what you would like the Result$ to be is it can't find the Key$.

Edited by - paul on 26 January 2002 01:41:52
Too right!! I fell into that trap a few times too till I finally worked it out. But the relative path thing bothered me because it was a little unreliable. Someone posted a snippet of code in here somehwere that used an API call tod etermin a file's current path, very useful.

Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Two ways I know of to get your current path are:

curdir.s=Space(255)
GetCurrentDirectory_(255,@curdir)
MessageRequester("",curdir,0)

This makes use of Mr.Skunks ASM String2 Library. You could also use Wayne1's StringLibraryEx Library and change Space(255) to Space$(255).
The other method would be to allocate the memory yourself:

buffer = GlobalAlloc_(#GMEM_FIXED | #GMEM_ZEROINIT, 100)
GetCurrentDirectory_(100,buffer)
curdir.s=PeekS(buffer)
GlobalFree_(buffer)
MessageRequester("",curdir,0)

(A little more work if you ask me!)
They both seem to create the same size executable.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

Thanks,

but now I know what took me so long to find out, look at the sample below

; inifilename and inisection cannot be in the WaitWindowEvent section
; then things go wrong
; but I need to change the section at he WaitWindowEvent
; if it's before the WaitWindowEvent it's working
INIFilename(".\sections.dat")
INISection("SECTIONS")


; Wait for UserInput

Repeat

Select WaitWindowEvent()

Case #PB_EventMenu

Case #PB_EventGadget
Select EventGadgetID()
Case 1
; if you place inifilename and inisection below it's not working
INIFilename(".\sections.dat")
INISection("SECTIONS")
WriteINIString("test","cor")
result1.s=ReadINIString("test","")
MessageRequester("",result1,#PB_MessageRequester_Ok)

..........

Registered PB version : 2.82 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

WriteINIString("test","cor")

Doesn't work also in the WaitWindowEvent

only Reading seems to function

Registered PB version : 2.82 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Post Reply