Archived

This topic is now archived and is closed to further replies.

Saandman

INI File I/O

Recommended Posts

[VISUAL BASIC] I have my little setup app that configures my game''s resolution and so on. I write this info to an INI file, successfully, with the API call WritePrivateProfileSection(). But when I''m to read these values into variables after restarting the app, I get crap data instead of the section data. I then use GetPrivateProfileString() and GetPrivateProfileInt(). For example, I read in the screen width. It gives me something like 83413250813205987132507 which is false It doesn''t even return the default return value I specify...
FileName = "data/config.ini"
sSTRING = "Screen Width=" & CStr(Width) & Chr(0) & Chr(0)
lRESULT = WritePrivateProfileSection("Display", sSTRING, FileName)

Width = GetPrivateProfileInt("Display", "Screen Width", 0, sFILE) '' crappy things happen here
 
Where am I going wrong? /Sandman

Share this post


Link to post
Share on other sites
In no particular order some things of the top of my head:

When you say wrote successfully, do you mean the result code was successful, or did you actually check the ini file was written correctly?
Are you sure you''re opening the same file you wrote to?
Did you try WritePrivateProfileString() instead of WritePrivateProfileSection() ?
Did you try replacing your key name with one without spaces?

Share this post


Link to post
Share on other sites
Hey I tried all your ideas now..

It doesn't work. It works in C++ though! The exact same calls. Very weird. What should one do different in VB?

Take the following simple example (nice last two words


WritePrivateProfileString "Display", "Width", "640", "data/conf.ini");

cout << GetPrivateProfileInt("Display", "Width", 0, "data/conf.ini") << endl;


AND IN VB:

WritePrivateProfileString("Display", "Width", "640", "data/conf.ini")

MsgBox(GetPrivateProfileInt("Display", "Width", 0, "data/conf.ini"))


The C++ version prints 640 which is correct. The VB snippet messages 84783082476 something. Very wrong.

Clueless!!?!++"`%?%"???!?!

/Sandman

[edited by - Saandman on November 9, 2002 5:32:57 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by elis-cool
VB == crap.. you shouldnt be using it at all! There, your problem is fixed!

What a thoroughly idiotic thing to say. Kudos!



God puts an apple tree in the middle of the Garden of Eden and says, do what you like guys, oh, but don''t eat the apple. Surprise surprise, they eat it and he leaps out from behind a bush shouting "Gotcha." It wouldn''t have made any difference if they hadn''t eaten it... because if you''re dealing with somebody who has the sort of mentality which likes leaving hats on the pavement with bricks under them you know perfectly well they won''t give up. They''ll get you in the end. -- Douglas Adams

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
displayWidth = GetPrivateProfileInt("Display", "Width", "0", "conf.ini"
MsgBox (displayWidth)

Worked for me, first time I''ve used vb for a while and haven''t touched api stuff before today. Wouldn''t write to a folder called data for some reason (as you do)

Share this post


Link to post
Share on other sites
Windows will look in the WINDOWS folder if I don''t specify a full search path to the ini file.

const File as string = "conf.ini"
API->"[root]/WINDOWS/conf.ini"

const File as string = "data/conf.ini"
API->"[currdir]/data/conf.ini"

THIS SHIT IS STILL BUGGING ME!!! WHY DO I GET CRAPDATA INSTEAD OF PERFECTLY RETURNED KEY VALUE!??!!

/Sandman

Share this post


Link to post
Share on other sites