Thread

A nice simple INI Module!!! (Sdk)

A nice simple INI Module!!! // Sdk

1  |  

gamer

Jul 8, 2001, 1:55pm
Ok, I'm posting way too much here but I just started work on the new RPG
bot...the thing is...the whoel thing is based on saving info ot INI
files...problem...the one i used with XedBot was buggy and required a lot of
code...

Does anyone have a nice SIMPLE Bas file and can list the commands read and
write. Ya know the stuff I need guys! Help! :o)

-Gamer

gamer

Jul 8, 2001, 1:56pm
In VB that is...

ananas

Jul 8, 2001, 4:01pm
The system commands are

WritePrivateProfileString
GetPrivateProfileString
GetPrivateProfileInt

and (newer commands) :

GetPrivateProfileSectionNames
GetPrivateProfileSection
WritePrivateProfileSection

GetPrivateProfileStruct
WritePrivateProfileStruct

and can be found in the kernel DLL

[View Quote] --
"_
|
/\
\ /
__/ /_

gamer

Jul 8, 2001, 6:19pm
Ahh I knew that...its just implementing them...

So what if I want to make a header like:

[settings]

and then a string in that called:

windows=yes

what would the code me to make those..and then put the "yes" into a value.

Also assuming the INI its reading from in in the same dir and called
settings.ini...

[View Quote]

ananas

Jul 8, 2001, 7:28pm
sorry, no VB here, but maybe the C version helps :

Write into the INI file :

WritePrivateProfileString ("settings", "windows", "yes",
"settings.ini")

read with :

anz=GetPrivateProfileString ("settings", "windows", "no", buffer,
buffersize, "settings.ini")

The "no" is the default value that is retrieved if no
entry can be found. The result in Anz contains the number
of characters read.

The location of the INI file :

It is searched in the currend directory, in windows
and windows system and on the path, so it would be
better to have a unique name.

I usually choose the name of my .exe file and replace the
extension by ".ini".

If you want to make sure that the file isn't taken from
a different location, specify it with the complete path.


[View Quote] --
"_
|
/\
\ /
__/ /_

andras

Jul 8, 2001, 9:10pm
Does that mean that stupid Micro$lop opens the ini file for EACH parameter access?? Yuck!!! At least in Borland you pass an open stream parameter to the retrieval/write function.

Andras

[View Quote]

trekkerx

Jul 9, 2001, 1:57am
--------------A5656D2318770E09C0169028
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Okay here is the code for VB


------------------------------------------------------------------------

Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any,
ByVal lplFilename As String) As Long
Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPriviteProfileIntA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal
lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As
String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

------------------------------------------------------------------------

now here is an example
------------------------------------------------------------------------

Dim lpAppName As String, lpFileName As String, lpKeyName As String, lpString As String, lppwname As String, lpPPW As String

'to write to a file
lpAppName = "Settings"
lpKeyName = "Windows"
lpString = "Test"
lpFileName = app.path & "\settings.ini"
ret = WritePrivateProfileString(lpAppName, lpKeyName, lpString, lpFileName)

'Now to load a setting
lpAppName = "Settings"
lpKeyName = "Windows"
lpFileName = app.path & "\settings.ini"
ret = GetPrivateProfileString(lpAppName, lpKeyName, "", Temp, Len(Temp), lpFileName)
If ret = 0 Then
text1.Text = ""
Else
text1.Text = Temp
End If
------------------------------------------------------------------------

that would make it look like this in text format
[Settings]
Windows=test

Get It? Very simple, I looked for it a long time, and when i found it it And figured it out it was simple

[View Quote] > Does that mean that stupid Micro$lop opens the ini file for EACH parameter access?? Yuck!!! At least in Borland you pass an open stream parameter to the retrieval/write function.
>
> Andras
>
[View Quote] --------------A5656D2318770E09C0169028
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Okay here is the code for VB
<br>&nbsp;
<p>
<hr WIDTH="100%">
<br>Public Declare Function WritePrivateProfileString Lib "kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal
lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As
Long
<br>Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPriviteProfileIntA"
(ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal nDefault
As Long, ByVal lpFileName As String) As Long
<br>Public Declare Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName
As String, ByVal lpDefault As String, ByVal lpReturnedString As String,
ByVal nSize As Long, ByVal lpFileName As String) As Long
<p>
<hr WIDTH="100%">
<p>now here is an example
<br>
<hr WIDTH="100%">
<br>Dim lpAppName As String, lpFileName As String, lpKeyName As String,
lpString As String, lppwname&nbsp; As String, lpPPW As String
<p>'to write to a file
<br>lpAppName = "Settings"
<br>lpKeyName = "Windows"
<br>lpString = "Test"
<br>lpFileName = app.path &amp; "\settings.ini"
<br>ret = WritePrivateProfileString(lpAppName, lpKeyName, lpString, lpFileName)
<p>'Now to load a setting
<br>lpAppName = "Settings"
<br>lpKeyName = "Windows"
<br>lpFileName = app.path &amp; "\settings.ini"
<br>ret = GetPrivateProfileString(lpAppName, lpKeyName, "", Temp, Len(Temp),
lpFileName)
<br>If ret = 0 Then
<br>&nbsp;text1.Text = ""
<br>Else
<br>&nbsp;&nbsp;&nbsp; text1.Text = Temp
<br>End If
<br>
<hr WIDTH="100%">
<br>that would make it look like this in text format
<br>[Settings]
<br>Windows=test
<p>Get It? Very simple, I looked for it a long time, and when i found it
it And figured it out it was simple
[View Quote] --------------A5656D2318770E09C0169028--

ananas

Jul 9, 2001, 3:47am
Windows caches the file and keeps track, at least as long
as no normal file functions are used on INI files.

[View Quote] --
"_
|
/\
\ /
__/ /_

gamer

Jul 9, 2001, 4:43am
thanks very much dude :o)


[View Quote]


Public Declare Function WritePrivateProfileString Lib "kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal
lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As
Long
Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias
"GetPriviteProfileIntA" (ByVal lpApplicationname As String, ByVal lpKeyName
As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As
String, ByVal nSize As Long, ByVal lpFileName As String) As Long



now here is an example




Dim lpAppName As String, lpFileName As String, lpKeyName As String, lpString
As String, lppwname As String, lpPPW As String
'to write to a file
lpAppName = "Settings"
lpKeyName = "Windows"
lpString = "Test"
lpFileName = app.path & "\settings.ini"
ret = WritePrivateProfileString(lpAppName, lpKeyName, lpString, lpFileName)
'Now to load a setting
lpAppName = "Settings"
lpKeyName = "Windows"
lpFileName = app.path & "\settings.ini"
ret = GetPrivateProfileString(lpAppName, lpKeyName, "", Temp, Len(Temp),
lpFileName)
If ret = 0 Then
text1.Text = ""
Else
text1.Text = Temp
End If




that would make it look like this in text format
[Settings]
Windows=test
Get It? Very simple, I looked for it a long time, and when i found it it And
figured it out it was simple
[View Quote]

andras

Jul 9, 2001, 10:52am
That is not an excuse to go through all the file locate/open/seek operation.
Andras

[View Quote]

gamer

Jul 9, 2001, 2:59pm
Hey I just got the the reading part in my code..it write the INI file
perfectly with no problems...however if I go to start the program again and
laod from the INI it dosent load all the values from the INI, heres my
code...whats wrong???

_________________________________

Private Sub Form_Load()
'Declarations
Dim QuestName As String, BotName As String, RaceName As String, PlayerName
As String, WorldName As String, CurrencyName As String, ModeratorName As
String
Dim OpEasy As String, OpMed As String, OpDif As String, OverLord As String
Dim Money As String, Item As String, Kill As String, Stat As String
Dim StartHealth As String, CurrencyStart As String, MagicStart As String,
HealthLimit As String, ItemLimit As String, MagicLimit As String, CurLimit
As String, IncreaseHealthLimitBy As String, IncreaseItemLimitBy As String,
IncreaseMagicLimitBy As String
Dim FilePath As String
Dim iKill As String
FilePath = App.Path & "\Settings.ini"
'Speech
QuestName = GetPrivateProfileString("Speech", "QuestName", "", Temp,
Len(Temp), FilePath)
BotName = GetPrivateProfileString("Speech", "BotName", "", Temp, Len(Temp),
FilePath)
RaceName = GetPrivateProfileString("Speech", "RaceName", "", Temp,
Len(Temp), FilePath)
PlayerName = GetPrivateProfileString("Speech", "PlayerName", "", Temp,
Len(Temp), FilePath)
WorldName = GetPrivateProfileString("Speech", "WorldName", "", Temp,
Len(Temp), FilePath)
CurrencyName = GetPrivateProfileString("Speech", "CurrencyName", "", Temp,
Len(Temp), FilePath)
ModeratorName = GetPrivateProfileString("Speech", "ModeratorName", "", Temp,
Len(Temp), FilePath)
'Enemies
OpEasy = GetPrivateProfileString("Enemies", "OpEasy", "", Temp, Len(Temp),
FilePath)
OpMed = GetPrivateProfileString("Enemies", "OpMed", "", Temp, Len(Temp),
FilePath)
OpDif = GetPrivateProfileString("Enemies", "OpDif", "", Temp, Len(Temp),
FilePath)
OverLord = GetPrivateProfileString("Enemies", "OverLord", "", Temp,
Len(Temp), FilePath)
'Rules
Money = GetPrivateProfileString("Rules", "Money", "", Temp, Len(Temp),
FilePath)
Item = GetPrivateProfileString("Rules", "Item", "", Temp, Len(Temp),
FilePath)
iKill = GetPrivateProfileString("Rules", "Kill", "", Temp, Len(Temp),
FilePath)
Stat = GetPrivateProfileString("Rules", "Stat", "", Temp, Len(Temp),
FilePath)
'Stats
StartHealth = GetPrivateProfileString("Stats", "StartHealth", "", Temp,
Len(Temp), FilePath)
CurrencyStart = GetPrivateProfileString("Stats", "CurrencyStart", "", Temp,
Len(Temp), FilePath)
MagicStart = GetPrivateProfileString("Stats", "MagicStart", "", Temp,
Len(Temp), FilePath)
HealthLimit = GetPrivateProfileString("Stats", "HealthLimit", "", Temp,
Len(Temp), FilePath)
CurLimit = GetPrivateProfileString("Stats", "CurrencyLimit", "", Temp,
Len(Temp), FilePath)
ItemLimit = GetPrivateProfileString("Stats", "ItemLimit", "", Temp,
Len(Temp), FilePath)
MagicLimit = GetPrivateProfileString("Stats", "MagicLimit", "", Temp,
Len(Temp), FilePath)
IncreaseHealthLimitBy = GetPrivateProfileString("Stats",
"IncreaseHealthLimitBy", "", Temp, Len(Temp), FilePath)
IncreaseItemLimitBy = GetPrivateProfileString("Stats",
"IncreaseItemLimitBy", "", Temp, Len(Temp), FilePath)
IncreaseMagicLimitBy = GetPrivateProfileString("Stats",
"IncreaseMagicLimitBy", "", Temp, Len(Temp), FilePath)
tbQuestName.Text = QuestName
tbBotName.Text = BotName
tbRaceName.Text = RaceName
tbPlayerName.Text = PlayerName
tbWorldName.Text = WorldName
tbCurrencyName.Text = CurrencyName
tbModeratorName.Text = ModeratorName
tbOpEasy.Text = OpEasy
tbOpMed.Text = OpMed
tbOpDif.Text = OpDif
tbOverlord.Text = OverLord
ckMoney.Value = Money
ckItem.Value = Item
ckKill.Value = iKill
ckStat.Value = Stat
tbHealthStart.Text = StartHealth
tbCurStart.Text = CurrencyStart
tbMagicStart.Text = MagicStart
tbHealthLimit.Text = HealthLimit
tbCurLimit.Text = CurLimit
tbLevelupHealth.Text = IncreaseHealthLimitBy
tbLevelupItem.Text = IncreaseItemLimitBy
tbLevelupMagic.Text = IncreaseMagicLimitBy
End Sub

gamer

Jul 9, 2001, 3:00pm
please excuse typos...typed it in a rush...

[View Quote]

trekkerx

Jul 9, 2001, 7:58pm
Ive notesed sometimes the Temp in reading the ini has to be dimed like this...
Dim Temp as String * 50

Also try and make a sub just to read and write the Ini, it makes it cleaner and
easer to deal with.

[View Quote] > please excuse typos...typed it in a rush...
>
[View Quote]

grimble

Jul 9, 2001, 11:21pm
You MUST preallocate space to the string as the API is simply copying over
memory it assumes to exist - as in C. The * 50 or whatever if defining a
pre-allocated fixed length string. Win2000 will blow VB to bits if you try
making the call without preallocating the space in the string.

The number after the "*" is the length of the string (50 characters in this
case). The buffer size is therfore the size of this string. If you DON'T
preallocated the string, then its length will be left over from the last
time you used it.

http://support.microsoft.com/support/kb/articles/Q75/6/39.asp explains it
but they prefill the string with spaces instead.

Grims


[View Quote]

kah

Jul 14, 2001, 11:13am
forget about INIs in VB, use the registry instead... even if it SHOULDN'T be
that way, it is: MS have done editing registry entries for your app
supereasy, use the SaveSetting, GetSetting and DeleteSetting statements to
use it (alltought the entries are layed in HKEY_CURRENT_USER\Software\VB and
VBA Program Settings\[AppName param]\[Categoryorwhateveritis param])

KAH

ananas

Jul 14, 2001, 3:45pm
Good programs don't use this piece of M$ shit (sorry)

[View Quote] --
"_
|
/\
\ /
__/ /_

agent1

Jul 14, 2001, 8:19pm
oh my :)
Visual Basic or the Registry?

-Agent1

[View Quote]

ananas

Jul 14, 2001, 9:13pm
I ment the registry, VB seems to be good for people who
don't need to go deeper into programming.

But the registry is a central ressource that should not be
used by individual standalone programs. Overuse of the
registry slows down the system and makes it harder to move
the program. Stuff that only this one program needs belongs
into a local config file, especially if there is no uninstall
program for the application.

After some months the registry usually contains more junk
than stuff that is needed, actually it does that already
after installing windows.

[View Quote] --
"_
|
/\
\ /
__/ /_

lanezeri

Jul 19, 2001, 9:45pm
The Reg sucks.. trust me.. use an INI file.. you can even use my INI file
creator.. I'd put it for download.. (my latest one) but I dont know which
files you need..

I have four.. I dont distribute my OCX's so that's why I dont know:

..exp
..lib
..oca
..ocx


[View Quote]

trekkerx

Jul 20, 2001, 1:08am
lanezeri, you only need the ocx file. And... why use a ocx file, and not a
moduel?
A ocx file is bigger, then a moduel would do to add to your bot?

[View Quote] > The Reg sucks.. trust me.. use an INI file.. you can even use my INI file
> creator.. I'd put it for download.. (my latest one) but I dont know which
> files you need..
>
> I have four.. I dont distribute my OCX's so that's why I dont know:
>
> .exp
> .lib
> .oca
> .ocx
>
[View Quote]

lanezeri

Jul 23, 2001, 1:52am
Bite my head off for trying to help.. damn.. and the last time I sent
someone just the ocx it said it wasn't registered.. so u need more than the
OCX..

[View Quote]

the derek

Jul 23, 2001, 3:14am
the ini file is for initialzation data. the rekgistry is to store things like
file type registration and icons etc... i didnt see the origonal post so i dont
know which is needed

[View Quote] > The Reg sucks.. trust me.. use an INI file.. you can even use my INI file
> creator.. I'd put it for download.. (my latest one) but I dont know which
> files you need..
>
> I have four.. I dont distribute my OCX's so that's why I dont know:
>
> .exp
> .lib
> .oca
> .ocx
>
[View Quote]

lanezeri

Jul 23, 2001, 7:15pm
Your wrong.. an INI can be used for anything.. for example.. listing citizen
names and numbers..

[Citizen Information]
1=AWLD

They aren't restricted to just initialization data only..

[View Quote]

the derek

Jul 23, 2001, 7:33pm
i never said it CANT be used for that i jts was saying what each was designed to
do.
yeah you can use it for anything, for example i have been wokring on a bot that
uses ini files asascript so its easier for the scripterto understand

[View Quote] > Your wrong.. an INI can be used for anything.. for example.. listing citizen
> names and numbers..
>
> [Citizen Information]
> 1=AWLD
>
> They aren't restricted to just initialization data only..
>
[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