Thread

VB: Storing Values in INI Files (Sdk)

VB: Storing Values in INI Files // Sdk

1  |  

gamer

May 18, 2001, 3:12pm
Yeah ok, so this is a standard bit of VB coding...EVERYONE should know
it...well i leant my book to a friend and I'm looking for a really simple
way...

Just need to know the code to create a title (e.g. [score])

then create simple lines in the INI like 'gamer=10'

can anyone help out? i need to get that book back :o)

moria

May 18, 2001, 4:00pm
to do it properly you should really use the Win32 api for ini files.

the following need to be declared in your root module or wherever you do
declares...

The basics are below, you may need to play a bit to get exactly what you
want:)


Declare Function WritePrivateProfileSection Lib "kernel32" Alias
"WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As
String, ByVal lpFileName As String) As Long

Declare Function WritePrivateProfileString Lib "kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Declare Function GetPrivateProfileInt Lib "kernel32" Alias
"GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName
As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long

Declare Function GetPrivateProfileSection Lib "kernel32" Alias
"GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal
lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String)
As Long

Declare Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As
String, ByVal nSize As Long, ByVal lpFileName As String) As Long

then you need the following storage declares of..

SecName....
KeyName
KeyValue
PrvName

then to add the ini elements

WritePrivateProfileString SecName, KeyName, KeyValue, PrvName
KeyName = "xxxxxxxx"
KeyValue = "xxxxxxxx"

where x are your values

to read you need

World = Space(50)
KeyName = "World"
GetPrivateProfileString SecName, KeyName, "10", World, Len(World), PrvName


where "10" is a default value if no value found
and the entry is put into a 50 space field, in this case called World

Hope this rings some bells.

Moria



[View Quote]

m a k a v e l i

May 18, 2001, 6:12pm
The API is mostly for programmers who know a little more. Download a good
INI file creator (Ex: Kupex, Mabry, etc..) and learn to use them, they work
good and are easy.

[View Quote]

brant

May 18, 2001, 6:34pm
A good ini file editor is included with all of my programs (ini tools.ocx).
It's simple to use - just add it to your project. You can download any of
the programs at www.shoemakervillage.org/programs.html

m a k a v e l i

May 19, 2001, 1:18pm
(Kupex INI Tools)

[View Quote]

moria

May 19, 2001, 1:38pm
[View Quote] so is using the win32 api and much more powerful. Theres ocx's etc for
lots of functions, but every one bloats the final app size.

In addition, by using the API you'll learn a heck of a lot more than just
including an OCX.:)

I have nothing against OCX's etc, and brandts one is fine, but I still
believe its best to get to know what you can do without them:)

Moria

grimble

May 19, 2001, 1:47pm
Get/SetPrivateProfileString and Get/SetPrivateProfileInt aren't exactly
difficult to use.

Personally, I'd tend to go the direct route rather than add another layer
into the application which is only going to call these API functions anyway.
Reduces the number of components out of your control too.

Just a thought.

Grims

[View Quote]

kah

May 20, 2001, 11:47am
also possible to use registry entries (I'll get flammed if I don't tell that
it should be used for communication with other apps)

KAH

[View Quote]

grimble

May 20, 2001, 12:23pm
Get/SetPrivateProfileString and Get/SetPrivateProfileInt aren't for sharing
data in the registry. They're for private settings.

You should use Get/SetProfileString and Get/SetProfileInt for that. :o)

Grims




[View Quote]

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn